2015-12-17 06:51:14 -05:00
|
|
|
logger = require('logger-sharelatex')
|
|
|
|
ReferencesSearchHandler = require('./ReferencesSearchHandler')
|
|
|
|
settings = require('settings-sharelatex')
|
2016-01-22 10:59:43 -05:00
|
|
|
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
2015-12-17 06:51:14 -05:00
|
|
|
|
|
|
|
module.exports = ReferencesSearchController =
|
|
|
|
|
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-26 09:29:23 -05:00
|
|
|
if (!docIds or (!(docIds instanceof Array) and (docIds != 'ALL')))
|
2016-01-22 09:23:59 -05:00
|
|
|
logger.err {projectId, docIds}, "docIds is not valid, should be either Array or String 'ALL'"
|
|
|
|
return res.send 400
|
|
|
|
logger.log {projectId, docIds}, "index references for project"
|
|
|
|
ReferencesSearchHandler.index projectId, docIds, (err, data) ->
|
2016-01-21 12:01:24 -05:00
|
|
|
if err
|
2016-01-22 09:23:59 -05:00
|
|
|
logger.err {err, projectId}, "error indexing references"
|
2016-01-21 12:01:24 -05:00
|
|
|
return res.send 500
|
2016-01-22 10:59:43 -05:00
|
|
|
if shouldBroadcast
|
|
|
|
logger.log {projectId}, "emitting new references keys to connected clients"
|
|
|
|
EditorRealTimeController.emitToRoom projectId, 'references:keys:updated', data.keys
|
2016-01-21 12:01:24 -05:00
|
|
|
return res.json data
|