mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-09 02:20:45 +00:00
Add ability to load labels from single document
This commit is contained in:
parent
4cb41a988a
commit
f29320dd93
3 changed files with 31 additions and 3 deletions
|
@ -12,3 +12,12 @@ module.exports = LabelsController =
|
|||
logger.err {project_id, err}, "[LabelsController] error getting all labels from project"
|
||||
return next(err)
|
||||
res.json {projectId: project_id, labels: projectLabels}
|
||||
|
||||
getLabelsForDoc: (req, res, next) ->
|
||||
project_id = req.params.Project_id
|
||||
doc_id = req.params.doc_id
|
||||
LabelsHandler.getLabelsForDoc project_id, doc_id, (err, docLabels) ->
|
||||
if err?
|
||||
logger.err {project_id, doc_id, err}, "[LabelsController] error getting labels from doc"
|
||||
return next(err)
|
||||
res.json {projectId: project_id, docId: doc_id, labels: docLabels}
|
||||
|
|
|
@ -10,14 +10,32 @@ module.exports = LabelsHandler =
|
|||
ProjectEntityHandler.getAllDocs projectId, (err, docs) ->
|
||||
if err?
|
||||
return callback(err)
|
||||
LabelsHandler.extractLabelsFromDocs docs, (err, projectLabels) ->
|
||||
LabelsHandler.extractLabelsFromProjectDocs docs, (err, projectLabels) ->
|
||||
if err?
|
||||
return callback(err)
|
||||
callback(null, projectLabels)
|
||||
|
||||
extractLabelsFromDocs: (docs, callback=(err, projectLabels)->) ->
|
||||
getLabelsForDoc: (projectId, docId, callback=(err, docLabels)->) ->
|
||||
ProjectEntityHandler.getDoc projectId, docId, (err, lines, rev) ->
|
||||
if err?
|
||||
return callback(err)
|
||||
LabelsHandler.extractLabelsFromDoc lines, (err, docLabels) ->
|
||||
if err?
|
||||
return callback(err)
|
||||
callback(null, docLabels)
|
||||
|
||||
extractLabelsFromDoc: (lines, callback=(err, docLabels)->) ->
|
||||
docLabels = []
|
||||
for line in lines
|
||||
re = LabelsHandler.labelCaptureRegex()
|
||||
while (labelMatch = re.exec(line))
|
||||
if labelMatch[1]
|
||||
docLabels.push(labelMatch[1])
|
||||
callback(null, docLabels)
|
||||
|
||||
extractLabelsFromProjectDocs: (docs, callback=(err, projectLabels)->) ->
|
||||
projectLabels = {} # docId => List[Label]
|
||||
for docPath, doc of docs
|
||||
for _docPath, doc of docs
|
||||
docLabels = []
|
||||
for line in doc.lines
|
||||
re = LabelsHandler.labelCaptureRegex()
|
||||
|
|
|
@ -195,6 +195,7 @@ module.exports = class Router
|
|||
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
||||
|
||||
webRouter.get '/project/:Project_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.getAllLabels
|
||||
webRouter.get '/project/:Project_id/:doc_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.getLabelsForDoc
|
||||
|
||||
webRouter.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags
|
||||
webRouter.post '/tag', AuthenticationController.requireLogin(), TagsController.createTag
|
||||
|
|
Loading…
Add table
Reference in a new issue