diff --git a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee index 1f6a9b48a4..55fca1c3e6 100644 --- a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee +++ b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee @@ -2,6 +2,7 @@ logger = require('logger-sharelatex') ReferencesSearchHandler = require('./ReferencesSearchHandler') ProjectLocator = require("../Project/ProjectLocator") settings = require('settings-sharelatex') +EditorRealTimeController = require("../Editor/EditorRealTimeController") module.exports = ReferencesSearchController = @@ -49,5 +50,7 @@ module.exports = ReferencesSearchController = if err logger.err {err, projectId}, "error indexing references" 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 diff --git a/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee b/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee index 4639b23509..eacd5df266 100644 --- a/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee +++ b/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee @@ -3,6 +3,7 @@ define [ class ReferencesSearchManager constructor: (@ide, @$scope) -> + console.log @ide @$scope.$root._references = @state = keys: [] @$scope.$on 'document:closed', (e, doc) => @@ -15,6 +16,17 @@ define [ @$scope.$on 'project:joined', (e) => @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 indexReferences: (docIds, shouldBroadcast) -> if window._ENABLE_REFERENCES_AUTOCOMPLETE != true @@ -23,13 +35,12 @@ define [ docIds: docIds shouldBroadcast: shouldBroadcast _csrf: window.csrfToken - console.log ">>", opts $.post( "/project/#{@$scope.project_id}/references/index", opts, (data) => console.log ">> done ", data - @$scope.$root._references.keys = data.keys + @_storeReferencesKeys(data.keys) ) getReferenceKeys: (callback=(keys)->) -> @@ -41,7 +52,7 @@ define [ _csrf: window.csrfToken }, (data) => - @$scope.$root._references.keys = data.keys + @_storeReferencesKeys(data.keys) if callback callback(data.keys) )