overleaf/services/web/app/coffee/Features/Labels/LabelsController.coffee

27 lines
1,015 B
CoffeeScript
Raw Normal View History

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
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, projectLabels: projectLabels}
getLabelsForDoc: (req, res, next) ->
2017-06-12 06:37:05 -04:00
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)
EditorRealTimeController.emitToRoom project_id, 'docLabelsUpdated', {
docId: doc_id, labels: docLabels
}
res.json {projectId: project_id, docId: doc_id, labels: docLabels}