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-15 03:56:48 -04:00
|
|
|
logger.log {project_id}, "getting all labels for project"
|
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
|
|
|
|
2017-06-13 06:38:15 -04:00
|
|
|
broadcastLabelsForDoc: (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
|
2017-06-15 03:56:48 -04:00
|
|
|
logger.log {project_id, doc_id}, "getting labels for doc"
|
2017-06-05 04:26:13 -04:00
|
|
|
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-12 08:06:56 -04:00
|
|
|
EditorRealTimeController.emitToRoom project_id, 'broadcastDocLabels', {
|
2017-06-05 09:48:50 -04:00
|
|
|
docId: doc_id, labels: docLabels
|
|
|
|
}
|
2017-06-13 06:38:15 -04:00
|
|
|
res.sendStatus(200)
|