mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Broadcast references-key changes back to connected clients.
This commit is contained in:
parent
af75bb8a60
commit
c911b7d6a3
2 changed files with 18 additions and 4 deletions
|
@ -2,6 +2,7 @@ logger = require('logger-sharelatex')
|
||||||
ReferencesSearchHandler = require('./ReferencesSearchHandler')
|
ReferencesSearchHandler = require('./ReferencesSearchHandler')
|
||||||
ProjectLocator = require("../Project/ProjectLocator")
|
ProjectLocator = require("../Project/ProjectLocator")
|
||||||
settings = require('settings-sharelatex')
|
settings = require('settings-sharelatex')
|
||||||
|
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
||||||
|
|
||||||
module.exports = ReferencesSearchController =
|
module.exports = ReferencesSearchController =
|
||||||
|
|
||||||
|
@ -49,5 +50,7 @@ module.exports = ReferencesSearchController =
|
||||||
if err
|
if err
|
||||||
logger.err {err, projectId}, "error indexing references"
|
logger.err {err, projectId}, "error indexing references"
|
||||||
return res.send 500
|
return res.send 500
|
||||||
# TODO: optionally broadcast to all connected clients
|
if shouldBroadcast
|
||||||
|
logger.log {projectId}, "emitting new references keys to connected clients"
|
||||||
|
EditorRealTimeController.emitToRoom projectId, 'references:keys:updated', data.keys
|
||||||
return res.json data
|
return res.json data
|
||||||
|
|
|
@ -3,6 +3,7 @@ define [
|
||||||
class ReferencesSearchManager
|
class ReferencesSearchManager
|
||||||
constructor: (@ide, @$scope) ->
|
constructor: (@ide, @$scope) ->
|
||||||
|
|
||||||
|
console.log @ide
|
||||||
@$scope.$root._references = @state = keys: []
|
@$scope.$root._references = @state = keys: []
|
||||||
|
|
||||||
@$scope.$on 'document:closed', (e, doc) =>
|
@$scope.$on 'document:closed', (e, doc) =>
|
||||||
|
@ -15,6 +16,17 @@ define [
|
||||||
@$scope.$on 'project:joined', (e) =>
|
@$scope.$on 'project:joined', (e) =>
|
||||||
@indexReferences("ALL", false)
|
@indexReferences("ALL", false)
|
||||||
|
|
||||||
|
setTimeout(
|
||||||
|
(self) ->
|
||||||
|
self.ide.socket.on 'references:keys:updated', (keys) ->
|
||||||
|
self._storeReferencesKeys(keys)
|
||||||
|
, 100
|
||||||
|
, this
|
||||||
|
)
|
||||||
|
|
||||||
|
_storeReferencesKeys: (newKeys) ->
|
||||||
|
@$scope.$root._references.keys = newKeys
|
||||||
|
|
||||||
# docIds: List[String]|String('ALL'), shouldBroadcast: Bool
|
# docIds: List[String]|String('ALL'), shouldBroadcast: Bool
|
||||||
indexReferences: (docIds, shouldBroadcast) ->
|
indexReferences: (docIds, shouldBroadcast) ->
|
||||||
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
||||||
|
@ -23,13 +35,12 @@ define [
|
||||||
docIds: docIds
|
docIds: docIds
|
||||||
shouldBroadcast: shouldBroadcast
|
shouldBroadcast: shouldBroadcast
|
||||||
_csrf: window.csrfToken
|
_csrf: window.csrfToken
|
||||||
console.log ">>", opts
|
|
||||||
$.post(
|
$.post(
|
||||||
"/project/#{@$scope.project_id}/references/index",
|
"/project/#{@$scope.project_id}/references/index",
|
||||||
opts,
|
opts,
|
||||||
(data) =>
|
(data) =>
|
||||||
console.log ">> done ", data
|
console.log ">> done ", data
|
||||||
@$scope.$root._references.keys = data.keys
|
@_storeReferencesKeys(data.keys)
|
||||||
)
|
)
|
||||||
|
|
||||||
getReferenceKeys: (callback=(keys)->) ->
|
getReferenceKeys: (callback=(keys)->) ->
|
||||||
|
@ -41,7 +52,7 @@ define [
|
||||||
_csrf: window.csrfToken
|
_csrf: window.csrfToken
|
||||||
},
|
},
|
||||||
(data) =>
|
(data) =>
|
||||||
@$scope.$root._references.keys = data.keys
|
@_storeReferencesKeys(data.keys)
|
||||||
if callback
|
if callback
|
||||||
callback(data.keys)
|
callback(data.keys)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue