2017-06-02 10:12:59 -04:00
|
|
|
EditorRealTimeController = require "../Editor/EditorRealTimeController"
|
|
|
|
LabelsHandler = require './LabelsHandler'
|
|
|
|
logger = require 'logger-sharelatex'
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = LabelsController =
|
|
|
|
|
|
|
|
getAllLabels: (req, res, next) ->
|
2017-06-12 06:37:05 -04:00
|
|
|
project_id = req.params.project_id
|
2017-06-02 10:12:59 -04:00
|
|
|
LabelsHandler.getAllLabelsForProject project_id, (err, projectLabels) ->
|
|
|
|
if err?
|
|
|
|
logger.err {project_id, err}, "[LabelsController] error getting all labels from project"
|
|
|
|
return next(err)
|
2017-06-05 09:48:50 -04:00
|
|
|
res.json {projectId: project_id, projectLabels: projectLabels}
|
2017-06-05 04:26:13 -04:00
|
|
|
|
|
|
|
getLabelsForDoc: (req, res, next) ->
|
2017-06-12 06:37:05 -04:00
|
|
|
project_id = req.params.project_id
|
2017-06-05 04:26:13 -04:00
|
|
|
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)
|
2017-06-08 10:12:18 -04:00
|
|
|
EditorRealTimeController.emitToRoom project_id, 'docLabelsUpdated', {
|
2017-06-05 09:48:50 -04:00
|
|
|
docId: doc_id, labels: docLabels
|
|
|
|
}
|
2017-06-05 04:26:13 -04:00
|
|
|
res.json {projectId: project_id, docId: doc_id, labels: docLabels}
|