mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
WIP: initial work on server-side labels
This commit is contained in:
parent
0e498d5e65
commit
4cb41a988a
4 changed files with 61 additions and 1 deletions
|
@ -0,0 +1,14 @@
|
|||
EditorRealTimeController = require "../Editor/EditorRealTimeController"
|
||||
LabelsHandler = require './LabelsHandler'
|
||||
logger = require 'logger-sharelatex'
|
||||
|
||||
|
||||
module.exports = LabelsController =
|
||||
|
||||
getAllLabels: (req, res, next) ->
|
||||
project_id = req.params.Project_id
|
||||
LabelsHandler.getAllLabelsForProject project_id, (err, projectLabels) ->
|
||||
if err?
|
||||
logger.err {project_id, err}, "[LabelsController] error getting all labels from project"
|
||||
return next(err)
|
||||
res.json {projectId: project_id, labels: projectLabels}
|
28
services/web/app/coffee/Features/Labels/LabelsHandler.coffee
Normal file
28
services/web/app/coffee/Features/Labels/LabelsHandler.coffee
Normal file
|
@ -0,0 +1,28 @@
|
|||
ProjectEntityHandler = require "../Project/ProjectEntityHandler"
|
||||
|
||||
|
||||
module.exports = LabelsHandler =
|
||||
|
||||
labelCaptureRegex: () ->
|
||||
/\\label\{([^\}\n\\]{0,80})\}/g
|
||||
|
||||
getAllLabelsForProject: (projectId, callback=(err, projectLabels)->) ->
|
||||
ProjectEntityHandler.getAllDocs projectId, (err, docs) ->
|
||||
if err?
|
||||
return callback(err)
|
||||
LabelsHandler.extractLabelsFromDocs docs, (err, projectLabels) ->
|
||||
if err?
|
||||
return callback(err)
|
||||
callback(null, projectLabels)
|
||||
|
||||
extractLabelsFromDocs: (docs, callback=(err, projectLabels)->) ->
|
||||
projectLabels = {} # docId => List[Label]
|
||||
for docPath, doc of docs
|
||||
docLabels = []
|
||||
for line in doc.lines
|
||||
re = LabelsHandler.labelCaptureRegex()
|
||||
while (labelMatch = re.exec(line))
|
||||
if labelMatch[1]
|
||||
docLabels.push(labelMatch[1])
|
||||
projectLabels[doc._id] = docLabels
|
||||
callback(null, projectLabels)
|
|
@ -43,6 +43,7 @@ SudoModeController = require('./Features/SudoMode/SudoModeController')
|
|||
SudoModeMiddlewear = require('./Features/SudoMode/SudoModeMiddlewear')
|
||||
AnalyticsRouter = require('./Features/Analytics/AnalyticsRouter')
|
||||
AnnouncementsController = require("./Features/Announcements/AnnouncementsController")
|
||||
LabelsController = require('./Features/Labels/LabelsController')
|
||||
|
||||
logger = require("logger-sharelatex")
|
||||
_ = require("underscore")
|
||||
|
@ -193,6 +194,8 @@ module.exports = class Router
|
|||
webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject
|
||||
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
||||
|
||||
webRouter.get '/project/:Project_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.getAllLabels
|
||||
|
||||
webRouter.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags
|
||||
webRouter.post '/tag', AuthenticationController.requireLogin(), TagsController.createTag
|
||||
webRouter.post '/tag/:tag_id/rename', AuthenticationController.requireLogin(), TagsController.renameTag
|
||||
|
|
|
@ -12,6 +12,9 @@ define [
|
|||
class LabelsManager
|
||||
constructor: (@$scope, @editor, @element) ->
|
||||
|
||||
window.GET_LABELS = () =>
|
||||
@loadProjectLabelsFromServer()
|
||||
|
||||
@state =
|
||||
documents: {} # map of DocId => List[Label]
|
||||
|
||||
|
@ -35,10 +38,22 @@ define [
|
|||
e.session.on "change", onChange
|
||||
setTimeout(
|
||||
() =>
|
||||
@scheduleLoadLabelsFromOpenDoc()
|
||||
# @scheduleLoadLabelsFromOpenDoc()
|
||||
@loadProjectLabelsFromServer()
|
||||
, 0
|
||||
)
|
||||
|
||||
loadProjectLabelsFromServer: () ->
|
||||
$.get(
|
||||
"/project/#{window.project_id}/labels"
|
||||
, (data) =>
|
||||
console.log ">>", data
|
||||
if data.labels
|
||||
for docId, docLabels of data.labels
|
||||
@state.documents[docId] = docLabels
|
||||
console.log @state.documents
|
||||
)
|
||||
|
||||
loadLabelsFromOpenDoc: () ->
|
||||
docId = @$scope.docId
|
||||
docText = @editor.getValue()
|
||||
|
|
Loading…
Reference in a new issue