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