2015-12-17 10:13:02 -05:00
|
|
|
define [
|
|
|
|
], () ->
|
|
|
|
class ReferencesSearchManager
|
|
|
|
constructor: (@ide, @$scope) ->
|
|
|
|
|
2015-12-29 06:02:59 -05:00
|
|
|
@$scope.$root._references = @state = keys: []
|
2015-12-18 11:20:58 -05:00
|
|
|
|
2015-12-17 10:13:02 -05:00
|
|
|
@$scope.$on 'document:closed', (e, doc) =>
|
|
|
|
if doc.doc_id
|
|
|
|
entity = @ide.fileTreeManager.findEntityById doc.doc_id
|
|
|
|
if entity?.name?.match /.*\.bib$/
|
|
|
|
@$scope.$emit 'references:changed', entity
|
2016-01-22 09:23:59 -05:00
|
|
|
@indexReferences([doc.doc_id], true)
|
2015-12-17 10:13:02 -05:00
|
|
|
|
2015-12-29 08:30:57 -05:00
|
|
|
@$scope.$on 'project:joined', (e) =>
|
2016-01-22 09:23:59 -05:00
|
|
|
@indexReferences("ALL", false)
|
2016-01-21 12:01:24 -05:00
|
|
|
|
2016-01-22 09:23:59 -05:00
|
|
|
# docIds: List[String]|String('ALL'), shouldBroadcast: Bool
|
|
|
|
indexReferences: (docIds, shouldBroadcast) ->
|
2016-01-21 12:01:24 -05:00
|
|
|
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
|
|
|
return
|
2016-01-22 09:23:59 -05:00
|
|
|
opts =
|
|
|
|
docIds: docIds
|
|
|
|
shouldBroadcast: shouldBroadcast
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
console.log ">>", opts
|
2016-01-21 12:01:24 -05:00
|
|
|
$.post(
|
2016-01-22 09:23:59 -05:00
|
|
|
"/project/#{@$scope.project_id}/references/index",
|
|
|
|
opts,
|
2016-01-21 12:01:24 -05:00
|
|
|
(data) =>
|
2016-01-22 09:23:59 -05:00
|
|
|
console.log ">> done ", data
|
|
|
|
@$scope.$root._references.keys = data.keys
|
2015-12-18 11:00:24 -05:00
|
|
|
)
|
|
|
|
|
2016-01-22 09:23:59 -05:00
|
|
|
getReferenceKeys: (callback=(keys)->) ->
|
2016-01-13 09:42:35 -05:00
|
|
|
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
|
|
|
return
|
2015-12-18 11:00:24 -05:00
|
|
|
$.get(
|
|
|
|
"/project/#{@$scope.project_id}/references/keys",
|
|
|
|
{
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
},
|
|
|
|
(data) =>
|
2015-12-29 06:02:59 -05:00
|
|
|
@$scope.$root._references.keys = data.keys
|
2016-01-18 05:29:13 -05:00
|
|
|
if callback
|
|
|
|
callback(data.keys)
|
2015-12-18 11:00:24 -05:00
|
|
|
)
|