mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
WIP: send multiple bib files and get back keys
This commit is contained in:
parent
d5d5ba9066
commit
307f78b831
4 changed files with 58 additions and 8 deletions
|
@ -219,7 +219,7 @@ module.exports = ProjectController =
|
||||||
allowedFreeTrial = !!subscription.freeTrial.allowed || true
|
allowedFreeTrial = !!subscription.freeTrial.allowed || true
|
||||||
|
|
||||||
# HACK: don't do it for now
|
# 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"
|
logger.log project_id:project_id, "rendering editor page"
|
||||||
res.render 'project/editor',
|
res.render 'project/editor',
|
||||||
|
|
|
@ -36,3 +36,14 @@ module.exports = ReferencesSearchController =
|
||||||
logger.err {err, project_id}, "error getting references keys"
|
logger.err {err, project_id}, "error getting references keys"
|
||||||
return res.send 500
|
return res.send 500
|
||||||
return res.json data
|
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
|
||||||
|
|
|
@ -28,13 +28,40 @@ module.exports = ReferencesSearchHandler =
|
||||||
|
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
_isFullIndex: (projectId, callback = (err, result) ->) ->
|
_isFullIndex: (project, callback = (err, result) ->) ->
|
||||||
Project.findById projectId, {owner_ref: 1}, (err, project) ->
|
|
||||||
return callback(err) if err
|
|
||||||
UserGetter.getUser project.owner_ref, {features: 1}, (err, owner) ->
|
UserGetter.getUser project.owner_ref, {features: 1}, (err, owner) ->
|
||||||
return callback(err) if err
|
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) ->) ->
|
indexProjectReferences: (project, callback = (err) ->) ->
|
||||||
logger.log {projectId: project._id}, "try indexing references from project"
|
logger.log {projectId: project._id}, "try indexing references from project"
|
||||||
ids = ReferencesSearchHandler._findBibDocIds(project)
|
ids = ReferencesSearchHandler._findBibDocIds(project)
|
||||||
|
@ -62,7 +89,6 @@ module.exports = ReferencesSearchHandler =
|
||||||
url: target_url
|
url: target_url
|
||||||
json:
|
json:
|
||||||
referencesUrl: fileUrl
|
referencesUrl: fileUrl
|
||||||
fullIndex: isFullIndex == true
|
|
||||||
}, (err, res, result) ->
|
}, (err, res, result) ->
|
||||||
if err
|
if err
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
|
|
@ -13,7 +13,20 @@ define [
|
||||||
@indexReferences doc.doc_id
|
@indexReferences doc.doc_id
|
||||||
|
|
||||||
@$scope.$on 'project:joined', (e) =>
|
@$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) ->
|
indexReferences: (doc_id) ->
|
||||||
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
||||||
|
|
Loading…
Reference in a new issue