|
@@ -15,63 +15,92 @@ define [
|
|
|
window.GET_LABELS = () =>
|
|
window.GET_LABELS = () =>
|
|
|
@loadProjectLabelsFromServer()
|
|
@loadProjectLabelsFromServer()
|
|
|
|
|
|
|
|
|
|
+ window.GET_DOC_LABELS = () =>
|
|
|
|
|
+ @loadCurrentDocLabelsFromServer()
|
|
|
|
|
+
|
|
|
@state =
|
|
@state =
|
|
|
documents: {} # map of DocId => List[Label]
|
|
documents: {} # map of DocId => List[Label]
|
|
|
|
|
|
|
|
@loadLabelsTimeout = null
|
|
@loadLabelsTimeout = null
|
|
|
|
|
|
|
|
|
|
+ @$scope.$on 'doc:labels:updated', (e, data) =>
|
|
|
|
|
+ if data.docId and data.labels
|
|
|
|
|
+ @state.documents[data.docId] = data.labels
|
|
|
|
|
+
|
|
|
onChange = (change) =>
|
|
onChange = (change) =>
|
|
|
|
|
+ if change.remote
|
|
|
|
|
+ return
|
|
|
cursorPosition = @editor.getCursorPosition()
|
|
cursorPosition = @editor.getCursorPosition()
|
|
|
end = change.end
|
|
end = change.end
|
|
|
range = new Range(end.row, 0, end.row, end.column)
|
|
range = new Range(end.row, 0, end.row, end.column)
|
|
|
lineUpToCursor = @editor.getSession().getTextRange(range)
|
|
lineUpToCursor = @editor.getSession().getTextRange(range)
|
|
|
commandFragment = getLastCommandFragment(lineUpToCursor)
|
|
commandFragment = getLastCommandFragment(lineUpToCursor)
|
|
|
if (
|
|
if (
|
|
|
- !change.remote and
|
|
|
|
|
change.action in ['remove', 'insert'] and
|
|
change.action in ['remove', 'insert'] and
|
|
|
((_.any(change.lines, (line) -> line.match(/\\label\{[^\}\n\\]{0,80}\}/))) or
|
|
((_.any(change.lines, (line) -> line.match(/\\label\{[^\}\n\\]{0,80}\}/))) or
|
|
|
(commandFragment?.length > 2 and commandFragment.slice(0,7) == '\\label{'))
|
|
(commandFragment?.length > 2 and commandFragment.slice(0,7) == '\\label{'))
|
|
|
)
|
|
)
|
|
|
- @scheduleLoadLabelsFromOpenDoc()
|
|
|
|
|
|
|
+ @scheduleLoadCurrentDocLabelsFromServer()
|
|
|
|
|
+ # @scheduleLoadLabelsFromOpenDoc()
|
|
|
|
|
|
|
|
@editor.on "changeSession", (e) =>
|
|
@editor.on "changeSession", (e) =>
|
|
|
e.oldSession.off "change", onChange
|
|
e.oldSession.off "change", onChange
|
|
|
e.session.on "change", onChange
|
|
e.session.on "change", onChange
|
|
|
- setTimeout(
|
|
|
|
|
- () =>
|
|
|
|
|
- # @scheduleLoadLabelsFromOpenDoc()
|
|
|
|
|
- @loadProjectLabelsFromServer()
|
|
|
|
|
- , 0
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ # setTimeout(
|
|
|
|
|
+ # () =>
|
|
|
|
|
+ # # @scheduleLoadLabelsFromOpenDoc()
|
|
|
|
|
+ # @loadProjectLabelsFromServer()
|
|
|
|
|
+ # , 0
|
|
|
|
|
+ # )
|
|
|
|
|
+
|
|
|
|
|
+ # Load now
|
|
|
|
|
+ @loadProjectLabelsFromServer()
|
|
|
|
|
|
|
|
loadProjectLabelsFromServer: () ->
|
|
loadProjectLabelsFromServer: () ->
|
|
|
$.get(
|
|
$.get(
|
|
|
"/project/#{window.project_id}/labels"
|
|
"/project/#{window.project_id}/labels"
|
|
|
, (data) =>
|
|
, (data) =>
|
|
|
- console.log ">>", data
|
|
|
|
|
- if data.labels
|
|
|
|
|
- for docId, docLabels of data.labels
|
|
|
|
|
|
|
+ if data.projectLabels
|
|
|
|
|
+ for docId, docLabels of data.projectLabels
|
|
|
@state.documents[docId] = docLabels
|
|
@state.documents[docId] = docLabels
|
|
|
- console.log @state.documents
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- loadLabelsFromOpenDoc: () ->
|
|
|
|
|
- docId = @$scope.docId
|
|
|
|
|
- docText = @editor.getValue()
|
|
|
|
|
- labels = []
|
|
|
|
|
- re = /\\label\{([^\}\n\\]{0,80})\}/g
|
|
|
|
|
- while (labelMatch = re.exec(docText)) and labels.length < 1000
|
|
|
|
|
- if labelMatch[1]
|
|
|
|
|
- labels.push(labelMatch[1])
|
|
|
|
|
- @state.documents[docId] = labels
|
|
|
|
|
-
|
|
|
|
|
- scheduleLoadLabelsFromOpenDoc: () ->
|
|
|
|
|
|
|
+ loadCurrentDocLabelsFromServer: () ->
|
|
|
|
|
+ $.get(
|
|
|
|
|
+ "/project/#{window.project_id}/#{@$scope.docId}/labels"
|
|
|
|
|
+ , (data) =>
|
|
|
|
|
+ if data.docId and data.labels
|
|
|
|
|
+ @state.documents[data.docId] = data.labels
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # loadLabelsFromOpenDoc: () ->
|
|
|
|
|
+ # docId = @$scope.docId
|
|
|
|
|
+ # docText = @editor.getValue()
|
|
|
|
|
+ # labels = []
|
|
|
|
|
+ # re = /\\label\{([^\}\n\\]{0,80})\}/g
|
|
|
|
|
+ # while (labelMatch = re.exec(docText)) and labels.length < 1000
|
|
|
|
|
+ # if labelMatch[1]
|
|
|
|
|
+ # labels.push(labelMatch[1])
|
|
|
|
|
+ # @state.documents[docId] = labels
|
|
|
|
|
+
|
|
|
|
|
+ # scheduleLoadLabelsFromOpenDoc: () ->
|
|
|
|
|
+ # # De-bounce loading labels with a timeout
|
|
|
|
|
+ # if @loadLabelsTimeout
|
|
|
|
|
+ # clearTimeout(@loadLabelsTimeout)
|
|
|
|
|
+ # @loadLabelsTimeout = setTimeout(
|
|
|
|
|
+ # () =>
|
|
|
|
|
+ # @loadLabelsFromOpenDoc()
|
|
|
|
|
+ # , 1000
|
|
|
|
|
+ # , this
|
|
|
|
|
+ # )
|
|
|
|
|
+
|
|
|
|
|
+ scheduleLoadCurrentDocLabelsFromServer: () ->
|
|
|
# De-bounce loading labels with a timeout
|
|
# De-bounce loading labels with a timeout
|
|
|
if @loadLabelsTimeout
|
|
if @loadLabelsTimeout
|
|
|
clearTimeout(@loadLabelsTimeout)
|
|
clearTimeout(@loadLabelsTimeout)
|
|
|
@loadLabelsTimeout = setTimeout(
|
|
@loadLabelsTimeout = setTimeout(
|
|
|
() =>
|
|
() =>
|
|
|
- @loadLabelsFromOpenDoc()
|
|
|
|
|
|
|
+ @loadCurrentDocLabelsFromServer()
|
|
|
, 1000
|
|
, 1000
|
|
|
, this
|
|
, this
|
|
|
)
|
|
)
|