WIP: send multiple bib files and get back keys

This commit is contained in:
Shane Kilkelly 2016-01-21 17:01:24 +00:00
parent d5d5ba9066
commit 307f78b831
4 changed files with 58 additions and 8 deletions

View file

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

View file

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

View file

@ -28,13 +28,40 @@ module.exports = ReferencesSearchHandler =
return ids
_isFullIndex: (projectId, callback = (err, result) ->) ->
Project.findById projectId, {owner_ref: 1}, (err, project) ->
return callback(err) if err
_isFullIndex: (project, callback = (err, result) ->) ->
UserGetter.getUser project.owner_ref, {features: 1}, (err, owner) ->
return callback(err) if err
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"
ids = ReferencesSearchHandler._findBibDocIds(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)

View file

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