Fetch the list of keys from references index.

This commit is contained in:
Shane Kilkelly 2015-12-18 16:00:24 +00:00
parent c9db11edbe
commit 8c9c476dd7
4 changed files with 50 additions and 4 deletions

View file

@ -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}"

View file

@ -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)

View file

@ -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

View file

@ -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)
)