2015-12-17 11:51:14 +00:00
|
|
|
logger = require('logger-sharelatex')
|
2016-02-08 17:04:27 +00:00
|
|
|
ReferencesHandler = require('./ReferencesHandler')
|
2015-12-17 11:51:14 +00:00
|
|
|
settings = require('settings-sharelatex')
|
2016-01-22 15:59:43 +00:00
|
|
|
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
2015-12-17 11:51:14 +00:00
|
|
|
|
2016-02-08 17:04:27 +00:00
|
|
|
module.exports = ReferencesController =
|
2015-12-17 11:51:14 +00:00
|
|
|
|
2016-01-27 16:00:53 +00:00
|
|
|
|
2016-01-22 14:23:59 +00:00
|
|
|
index: (req, res) ->
|
|
|
|
projectId = req.params.Project_id
|
2016-01-21 17:01:24 +00:00
|
|
|
shouldBroadcast = req.body.shouldBroadcast
|
2016-01-22 14:23:59 +00:00
|
|
|
docIds = req.body.docIds
|
2016-01-27 16:00:53 +00:00
|
|
|
if (!docIds or !(docIds instanceof Array))
|
2016-01-22 14:23:59 +00:00
|
|
|
logger.err {projectId, docIds}, "docIds is not valid, should be either Array or String 'ALL'"
|
2016-02-16 12:28:02 +00:00
|
|
|
return res.sendStatus 400
|
2016-01-27 13:33:42 +00:00
|
|
|
logger.log {projectId, docIds: docIds}, "index references for project"
|
2016-02-08 17:04:27 +00:00
|
|
|
ReferencesHandler.index projectId, docIds, (err, data) ->
|
2016-06-24 14:46:37 +00:00
|
|
|
if err?
|
2016-01-27 16:00:53 +00:00
|
|
|
logger.err {err, projectId}, "error indexing all references"
|
2016-02-16 12:28:02 +00:00
|
|
|
return res.sendStatus 500
|
2016-02-08 17:04:27 +00:00
|
|
|
ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
|
2016-01-27 16:00:53 +00:00
|
|
|
|
|
|
|
indexAll: (req, res) ->
|
|
|
|
projectId = req.params.Project_id
|
|
|
|
shouldBroadcast = req.body.shouldBroadcast
|
|
|
|
logger.log {projectId}, "index all references for project"
|
2016-02-08 17:04:27 +00:00
|
|
|
ReferencesHandler.indexAll projectId, (err, data) ->
|
2016-06-24 14:46:37 +00:00
|
|
|
if err?
|
2016-01-27 16:00:53 +00:00
|
|
|
logger.err {err, projectId}, "error indexing all references"
|
2016-02-16 12:28:02 +00:00
|
|
|
return res.sendStatus 500
|
2016-02-08 17:04:27 +00:00
|
|
|
ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
|
2016-01-27 16:00:53 +00:00
|
|
|
|
|
|
|
_handleIndexResponse: (req, res, projectId, shouldBroadcast, data) ->
|
2016-06-24 14:46:37 +00:00
|
|
|
if !data? or !data.keys?
|
2016-07-26 13:23:00 +00:00
|
|
|
return res.json({projectId, keys: []})
|
|
|
|
if shouldBroadcast
|
2016-01-27 16:00:53 +00:00
|
|
|
logger.log {projectId}, "emitting new references keys to connected clients"
|
|
|
|
EditorRealTimeController.emitToRoom projectId, 'references:keys:updated', data.keys
|
|
|
|
return res.json data
|