diff --git a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee index 5f4fadde4e..ee9320c604 100644 --- a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee +++ b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchController.coffee @@ -27,5 +27,14 @@ module.exports = ReferencesSearchController = res.send 200 + getKeys: (req, res) -> + project_id = req.params.Project_id + logger.log {project_id}, "getting project references keys" + ReferencesSearchHandler.getKeys project_id, (err, data) -> + if err + logger.err {err, project_id}, "error getting references keys" + return res.send 500 + return res.json data + _buildDocUrl: (project_id, doc_id) -> "#{settings.apis.web.url}/project/#{project_id}/doc/#{doc_id}" diff --git a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee index 262c99226e..a01b6893a2 100644 --- a/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee +++ b/services/web/app/coffee/Features/ReferencesSearch/ReferencesSearchHandler.coffee @@ -24,3 +24,19 @@ module.exports = ReferencesSearchHandler = err = new Error("references api responded with non-success code: #{res.statusCode}") logger.log {err, project_id, file_url}, "error updating references" return callback(err) + + getKeys: (project_id, callback = (err, result)->) -> + logger.log {project_id}, "getting keys from remote references api" + url = "#{settings.apis.references.url}/project/#{project_id}/keys" + request.get { + url: url + json: true + }, (err, res, result) -> + if err + return callback(err) + if 200 <= res.statusCode < 300 + return callback(null, result) + else + err = new Error("references api responded with non-success code: #{res.statusCode}") + logger.log {err, project_id, file_url}, "error getting references keys" + return callback(err) diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index ae9f4db508..c3eec34c6a 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -172,6 +172,7 @@ module.exports = class Router webRouter.get /learn(\/.*)?/, WikiController.getPage webRouter.post "/project/:Project_id/references", SecurityManager.requestCanAccessProject, ReferencesSearchController.indexFile + webRouter.get "/project/:Project_id/references/keys", SecurityManager.requestCanAccessProject, ReferencesSearchController.getKeys #Admin Stuff webRouter.get '/admin', SecurityManager.requestIsAdmin, AdminController.index diff --git a/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee b/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee index 6c8fa56992..7eabbef337 100644 --- a/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee +++ b/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee @@ -14,7 +14,27 @@ define [ indexReferences: (doc_id) -> console.log ">> doc id #{doc_id}" - $.post("/project/#{@$scope.project_id}/references", { - docId: doc_id, - _csrf: window.csrfToken - }, (data) => console.log(data)) + $.post( + "/project/#{@$scope.project_id}/references", + { + docId: doc_id, + _csrf: window.csrfToken + }, + (data) => + console.log(data) + setTimeout( + ( () -> @getReferenceKeys() ).bind(this), + 100 + ) + ) + + getReferenceKeys: () -> + $.get( + "/project/#{@$scope.project_id}/references/keys", + { + _csrf: window.csrfToken + }, + (data) => + console.log ">> got keys" + console.log(data) + )