diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 1d0a70642a..540e460953 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -219,7 +219,7 @@ module.exports = ProjectController = allowedFreeTrial = !!subscription.freeTrial.allowed || true # HACK: don't do it for now - ReferencesSearchHandler.indexProjectReferences project, -> # don't need to wait on this + # ReferencesSearchHandler.indexProjectReferences project, -> # don't need to wait on this logger.log project_id:project_id, "rendering editor page" res.render 'project/editor', diff --git a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee index 5926041ef9..e2208aeffa 100644 --- a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee +++ b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee @@ -36,3 +36,14 @@ module.exports = ReferencesSearchController = logger.err {err, project_id}, "error getting references keys" return res.send 500 return res.json data + + loadReferencesKeys: (req, res) -> + project_id = req.params.Project_id + shouldBroadcast = req.body.shouldBroadcast + logger.log {project_id}, "loading project references keys" + ReferencesSearchHandler.loadReferencesKeys project_id, (err, data) -> + if err + logger.err {err, project_id}, "error getting references keys" + return res.send 500 + # TODO: optionally broadcast to all connected clients + return res.json data diff --git a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee index 13bdad9927..dd2990c3f4 100644 --- a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee +++ b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee @@ -28,12 +28,39 @@ module.exports = ReferencesSearchHandler = return ids - _isFullIndex: (projectId, callback = (err, result) ->) -> - Project.findById projectId, {owner_ref: 1}, (err, project) -> + _isFullIndex: (project, callback = (err, result) ->) -> + UserGetter.getUser project.owner_ref, {features: 1}, (err, owner) -> return callback(err) if err - UserGetter.getUser project.owner_ref, {features: 1}, (err, owner) -> - return callback(err) if err - callback(null, owner.features.references == true) + callback(null, owner.features.references == true) + + loadReferencesKeys: (projectId, callback=(err, data)->) -> + logger.log {projectId}, "load references keys for project" + Project.findPopulatedById projectId, (err, project) -> + if err + return callback(err) + ReferencesSearchHandler._isFullIndex project, (err, isFullIndex) -> + if err + return callback(err) + bibDocIds = ReferencesSearchHandler._findBibDocIds(project) + bibDocUrls = bibDocIds.map (docId) -> + ReferencesSearchHandler._buildDocUrl projectId, docId + logger.log {projectId, isFullIndex, bibDocIds}, "sending request to references service" + request.post { + url: "#{settings.apis.references.url}/project/#{projectId}/loadreferenceskeys" + json: + docUrls: bibDocUrls + fullIndex: isFullIndex + }, (err, res, result) -> + if err + return callback(err) + if 200 <= res.statusCode < 300 + return callback(null) + else + err = new Error("references api responded with non-success code: #{res.statusCode}") + logger.log {err, projectId, fileUrl}, "error updating references" + return callback(err) + + ## ## ## ## indexProjectReferences: (project, callback = (err) ->) -> logger.log {projectId: project._id}, "try indexing references from project" @@ -62,7 +89,6 @@ module.exports = ReferencesSearchHandler = url: target_url json: referencesUrl: fileUrl - fullIndex: isFullIndex == true }, (err, res, result) -> if err return callback(err) diff --git a/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee b/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee index 6b80dcbc4d..47e310e1ed 100644 --- a/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee +++ b/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee @@ -13,7 +13,20 @@ define [ @indexReferences doc.doc_id @$scope.$on 'project:joined', (e) => - @getReferenceKeys() + @loadReferencesKeys() + + loadReferencesKeys: () -> + if window._ENABLE_REFERENCES_AUTOCOMPLETE != true + return + $.post( + "/project/#{@$scope.project_id}/referenceskeys", + { + shouldBroadcast: false + _csrf: window.csrfToken + }, + (data) => + console.log ">> ", data + ) indexReferences: (doc_id) -> if window._ENABLE_REFERENCES_AUTOCOMPLETE != true