labels -> metadata
This commit is contained in:
@@ -5,6 +5,30 @@ logger = require 'logger-sharelatex'
|
|||||||
|
|
||||||
module.exports = MetadataController =
|
module.exports = MetadataController =
|
||||||
|
|
||||||
|
getAllLabels: (req, res, next) ->
|
||||||
|
project_id = req.params.project_id
|
||||||
|
logger.log {project_id}, "getting labels for project"
|
||||||
|
MetadataHandler.getMetadataForProject project_id, (err, projectMetadata) ->
|
||||||
|
if err?
|
||||||
|
logger.err {project_id, err}, "[MetadataController] error getting labels from project"
|
||||||
|
return next err
|
||||||
|
res.json {
|
||||||
|
projectId: project_id
|
||||||
|
projectLabels: projectMetadata["labels"]
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllPackages: (req, res, next) ->
|
||||||
|
project_id = req.params.project_id
|
||||||
|
logger.log {project_id}, "getting labels for project"
|
||||||
|
MetadataHandler.getMetadataForProject project_id, (err, projectMetadata) ->
|
||||||
|
if err?
|
||||||
|
logger.err {project_id, err}, "[MetadataController] error getting labels from project"
|
||||||
|
return next err
|
||||||
|
res.json {
|
||||||
|
projectId: project_id
|
||||||
|
projectPackages: projectMetadata["packages"]
|
||||||
|
}
|
||||||
|
|
||||||
getAllMetadata: (req, res, next) ->
|
getAllMetadata: (req, res, next) ->
|
||||||
project_id = req.params.project_id
|
project_id = req.params.project_id
|
||||||
logger.log {project_id}, "getting metadata for project"
|
logger.log {project_id}, "getting metadata for project"
|
||||||
@@ -33,4 +57,4 @@ module.exports = MetadataController =
|
|||||||
packages: docMetadata["packages"]
|
packages: docMetadata["packages"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.sendStatus(200)
|
res.sendStatus 200
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ define [
|
|||||||
"ide/editor/directives/aceEditor/highlights/HighlightsManager"
|
"ide/editor/directives/aceEditor/highlights/HighlightsManager"
|
||||||
"ide/editor/directives/aceEditor/cursor-position/CursorPositionManager"
|
"ide/editor/directives/aceEditor/cursor-position/CursorPositionManager"
|
||||||
"ide/editor/directives/aceEditor/track-changes/TrackChangesManager"
|
"ide/editor/directives/aceEditor/track-changes/TrackChangesManager"
|
||||||
"ide/editor/directives/aceEditor/labels/LabelsManager"
|
# "ide/editor/directives/aceEditor/labels/LabelsManager"
|
||||||
"ide/labels/services/labels"
|
"ide/editor/directives/aceEditor/metadata/MetadataManager"
|
||||||
|
# "ide/labels/services/labels"
|
||||||
|
"ide/metadata/services/metadata"
|
||||||
"ide/graphics/services/graphics"
|
"ide/graphics/services/graphics"
|
||||||
"ide/preamble/services/preamble"
|
"ide/preamble/services/preamble"
|
||||||
], (App, Ace, SearchBox, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager, LabelsManager) ->
|
], (App, Ace, SearchBox, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager, MetadataManager) ->
|
||||||
EditSession = ace.require('ace/edit_session').EditSession
|
EditSession = ace.require('ace/edit_session').EditSession
|
||||||
ModeList = ace.require('ace/ext/modelist')
|
ModeList = ace.require('ace/ext/modelist')
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ define [
|
|||||||
url = ace.config._moduleUrl(args...) + "?fingerprint=#{window.aceFingerprint}"
|
url = ace.config._moduleUrl(args...) + "?fingerprint=#{window.aceFingerprint}"
|
||||||
return url
|
return url
|
||||||
|
|
||||||
App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, labels, graphics, preamble) ->
|
App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, metadata, graphics, preamble) ->
|
||||||
monkeyPatchSearch($rootScope, $compile)
|
monkeyPatchSearch($rootScope, $compile)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -102,8 +104,9 @@ define [
|
|||||||
highlightsManager = new HighlightsManager(scope, editor, element)
|
highlightsManager = new HighlightsManager(scope, editor, element)
|
||||||
cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage)
|
cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage)
|
||||||
trackChangesManager = new TrackChangesManager(scope, editor, element)
|
trackChangesManager = new TrackChangesManager(scope, editor, element)
|
||||||
labelsManager = new LabelsManager(scope, editor, element, labels)
|
metadataManager = new metadataManager(scope, editor, element, metadata)
|
||||||
autoCompleteManager = new AutoCompleteManager(scope, editor, element, labelsManager, graphics, preamble)
|
# labelsManager = new LabelsManager(scope, editor, element, labels)
|
||||||
|
autoCompleteManager = new AutoCompleteManager(scope, editor, element, metadataManager, graphics, preamble)
|
||||||
|
|
||||||
|
|
||||||
# Prevert Ctrl|Cmd-S from triggering save dialog
|
# Prevert Ctrl|Cmd-S from triggering save dialog
|
||||||
@@ -115,16 +118,16 @@ define [
|
|||||||
editor.commands.removeCommand "transposeletters"
|
editor.commands.removeCommand "transposeletters"
|
||||||
editor.commands.removeCommand "showSettingsMenu"
|
editor.commands.removeCommand "showSettingsMenu"
|
||||||
editor.commands.removeCommand "foldall"
|
editor.commands.removeCommand "foldall"
|
||||||
|
|
||||||
# For European keyboards, the / is above 7 so needs Shift pressing.
|
# For European keyboards, the / is above 7 so needs Shift pressing.
|
||||||
# This comes through as Command-Shift-/ on OS X, which is mapped to
|
# This comes through as Command-Shift-/ on OS X, which is mapped to
|
||||||
# toggleBlockComment.
|
# toggleBlockComment.
|
||||||
# This doesn't do anything for LaTeX, so remap this to togglecomment to
|
# This doesn't do anything for LaTeX, so remap this to togglecomment to
|
||||||
# work for European keyboards as normal.
|
# work for European keyboards as normal.
|
||||||
# On Windows, the key combo comes as Ctrl-Shift-7.
|
# On Windows, the key combo comes as Ctrl-Shift-7.
|
||||||
editor.commands.removeCommand "toggleBlockComment"
|
editor.commands.removeCommand "toggleBlockComment"
|
||||||
editor.commands.removeCommand "togglecomment"
|
editor.commands.removeCommand "togglecomment"
|
||||||
|
|
||||||
editor.commands.addCommand {
|
editor.commands.addCommand {
|
||||||
name: "togglecomment",
|
name: "togglecomment",
|
||||||
bindKey: { win: "Ctrl-/|Ctrl-Shift-7", mac: "Command-/|Command-Shift-/" },
|
bindKey: { win: "Ctrl-/|Ctrl-Shift-7", mac: "Command-/|Command-Shift-/" },
|
||||||
@@ -140,7 +143,7 @@ define [
|
|||||||
exec: (editor) ->
|
exec: (editor) ->
|
||||||
ace.require("ace/ext/searchbox").Search(editor, true)
|
ace.require("ace/ext/searchbox").Search(editor, true)
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
|
||||||
# Bold text on CMD+B
|
# Bold text on CMD+B
|
||||||
editor.commands.addCommand
|
editor.commands.addCommand
|
||||||
name: "bold",
|
name: "bold",
|
||||||
@@ -154,7 +157,7 @@ define [
|
|||||||
text = editor.getCopyText()
|
text = editor.getCopyText()
|
||||||
editor.insert("\\textbf{" + text + "}")
|
editor.insert("\\textbf{" + text + "}")
|
||||||
readOnly: false
|
readOnly: false
|
||||||
|
|
||||||
# Italicise text on CMD+I
|
# Italicise text on CMD+I
|
||||||
editor.commands.addCommand
|
editor.commands.addCommand
|
||||||
name: "italics",
|
name: "italics",
|
||||||
@@ -171,7 +174,7 @@ define [
|
|||||||
|
|
||||||
scope.$watch "onCtrlEnter", (callback) ->
|
scope.$watch "onCtrlEnter", (callback) ->
|
||||||
if callback?
|
if callback?
|
||||||
editor.commands.addCommand
|
editor.commands.addCommand
|
||||||
name: "compile",
|
name: "compile",
|
||||||
bindKey: win: "Ctrl-Enter", mac: "Command-Enter"
|
bindKey: win: "Ctrl-Enter", mac: "Command-Enter"
|
||||||
exec: (editor) =>
|
exec: (editor) =>
|
||||||
@@ -180,7 +183,7 @@ define [
|
|||||||
|
|
||||||
scope.$watch "onCtrlJ", (callback) ->
|
scope.$watch "onCtrlJ", (callback) ->
|
||||||
if callback?
|
if callback?
|
||||||
editor.commands.addCommand
|
editor.commands.addCommand
|
||||||
name: "toggle-review-panel",
|
name: "toggle-review-panel",
|
||||||
bindKey: win: "Ctrl-J", mac: "Command-J"
|
bindKey: win: "Ctrl-J", mac: "Command-J"
|
||||||
exec: (editor) =>
|
exec: (editor) =>
|
||||||
@@ -189,7 +192,7 @@ define [
|
|||||||
|
|
||||||
scope.$watch "onCtrlShiftC", (callback) ->
|
scope.$watch "onCtrlShiftC", (callback) ->
|
||||||
if callback?
|
if callback?
|
||||||
editor.commands.addCommand
|
editor.commands.addCommand
|
||||||
name: "add-new-comment",
|
name: "add-new-comment",
|
||||||
bindKey: win: "Ctrl-Shift-C", mac: "Command-Shift-C"
|
bindKey: win: "Ctrl-Shift-C", mac: "Command-Shift-C"
|
||||||
exec: (editor) =>
|
exec: (editor) =>
|
||||||
@@ -198,7 +201,7 @@ define [
|
|||||||
|
|
||||||
scope.$watch "onCtrlShiftA", (callback) ->
|
scope.$watch "onCtrlShiftA", (callback) ->
|
||||||
if callback?
|
if callback?
|
||||||
editor.commands.addCommand
|
editor.commands.addCommand
|
||||||
name: "toggle-track-changes",
|
name: "toggle-track-changes",
|
||||||
bindKey: win: "Ctrl-Shift-A", mac: "Command-Shift-A"
|
bindKey: win: "Ctrl-Shift-A", mac: "Command-Shift-A"
|
||||||
exec: (editor) =>
|
exec: (editor) =>
|
||||||
@@ -302,7 +305,7 @@ define [
|
|||||||
if updateCount == 100
|
if updateCount == 100
|
||||||
event_tracking.send 'editor-interaction', 'multi-doc-update'
|
event_tracking.send 'editor-interaction', 'multi-doc-update'
|
||||||
scope.$emit "#{scope.name}:change"
|
scope.$emit "#{scope.name}:change"
|
||||||
|
|
||||||
onScroll = (scrollTop) ->
|
onScroll = (scrollTop) ->
|
||||||
return if !scope.eventsBridge?
|
return if !scope.eventsBridge?
|
||||||
height = editor.renderer.layerConfig.maxHeight
|
height = editor.renderer.layerConfig.maxHeight
|
||||||
@@ -311,7 +314,7 @@ define [
|
|||||||
onScrollbarVisibilityChanged = (event, vRenderer) ->
|
onScrollbarVisibilityChanged = (event, vRenderer) ->
|
||||||
return if !scope.eventsBridge?
|
return if !scope.eventsBridge?
|
||||||
scope.eventsBridge.emit "aceScrollbarVisibilityChanged", vRenderer.scrollBarV.isVisible, vRenderer.scrollBarV.width
|
scope.eventsBridge.emit "aceScrollbarVisibilityChanged", vRenderer.scrollBarV.isVisible, vRenderer.scrollBarV.width
|
||||||
|
|
||||||
if scope.eventsBridge?
|
if scope.eventsBridge?
|
||||||
editor.renderer.on "scrollbarVisibilityChanged", onScrollbarVisibilityChanged
|
editor.renderer.on "scrollbarVisibilityChanged", onScrollbarVisibilityChanged
|
||||||
|
|
||||||
@@ -401,14 +404,14 @@ define [
|
|||||||
|
|
||||||
session = editor.getSession()
|
session = editor.getSession()
|
||||||
session.off "changeScrollTop"
|
session.off "changeScrollTop"
|
||||||
|
|
||||||
doc = session.getDocument()
|
doc = session.getDocument()
|
||||||
doc.off "change", onChange
|
doc.off "change", onChange
|
||||||
|
|
||||||
editor.renderer.on "changeCharacterSize", () ->
|
editor.renderer.on "changeCharacterSize", () ->
|
||||||
scope.$apply () ->
|
scope.$apply () ->
|
||||||
scope.rendererData.lineHeight = editor.renderer.lineHeight
|
scope.rendererData.lineHeight = editor.renderer.lineHeight
|
||||||
|
|
||||||
scope.$watch "rendererData", (rendererData) ->
|
scope.$watch "rendererData", (rendererData) ->
|
||||||
if rendererData?
|
if rendererData?
|
||||||
rendererData.lineHeight = editor.renderer.lineHeight
|
rendererData.lineHeight = editor.renderer.lineHeight
|
||||||
|
|||||||
+5
-3
@@ -9,7 +9,7 @@ define [
|
|||||||
aceSnippetManager = ace.require('ace/snippets').snippetManager
|
aceSnippetManager = ace.require('ace/snippets').snippetManager
|
||||||
|
|
||||||
class AutoCompleteManager
|
class AutoCompleteManager
|
||||||
constructor: (@$scope, @editor, @element, @labelsManager, @graphics, @preamble) ->
|
constructor: (@$scope, @editor, @element, @metadataManager, @graphics, @preamble) ->
|
||||||
@suggestionManager = new CommandManager()
|
@suggestionManager = new CommandManager()
|
||||||
|
|
||||||
@monkeyPatchAutocomplete()
|
@monkeyPatchAutocomplete()
|
||||||
@@ -34,6 +34,8 @@ define [
|
|||||||
enableLiveAutocompletion: false
|
enableLiveAutocompletion: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# metadataManager = @metadataManager
|
||||||
|
|
||||||
SnippetCompleter = new EnvironmentManager()
|
SnippetCompleter = new EnvironmentManager()
|
||||||
|
|
||||||
Graphics = @graphics
|
Graphics = @graphics
|
||||||
@@ -63,7 +65,7 @@ define [
|
|||||||
}
|
}
|
||||||
callback null, result
|
callback null, result
|
||||||
|
|
||||||
labelsManager = @labelsManager
|
metadataManager = @metadataManager
|
||||||
LabelsCompleter =
|
LabelsCompleter =
|
||||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||||
context = Helpers.getContext(editor, pos)
|
context = Helpers.getContext(editor, pos)
|
||||||
@@ -80,7 +82,7 @@ define [
|
|||||||
meta: "cross-reference",
|
meta: "cross-reference",
|
||||||
score: 60
|
score: 60
|
||||||
}
|
}
|
||||||
for label in labelsManager.getAllLabels()
|
for label in metadataManager.getAllLabels()
|
||||||
result.push {
|
result.push {
|
||||||
caption: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
|
caption: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
|
||||||
value: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
|
value: "\\#{commandName}{#{label}#{if needsClosingBrace then '}' else ''}",
|
||||||
|
|||||||
+77
@@ -0,0 +1,77 @@
|
|||||||
|
define [
|
||||||
|
"ace/ace"
|
||||||
|
], () ->
|
||||||
|
Range = ace.require("ace/range").Range
|
||||||
|
|
||||||
|
getLastCommandFragment = (lineUpToCursor) ->
|
||||||
|
if m = lineUpToCursor.match(/(\\[^\\]+)$/)
|
||||||
|
return m[1]
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
|
||||||
|
class MetadataManager
|
||||||
|
constructor: (@$scope, @editor, @element, @Metadata) ->
|
||||||
|
@debouncer = {} # DocId => Timeout
|
||||||
|
|
||||||
|
onChange = (change) =>
|
||||||
|
if change.remote
|
||||||
|
return
|
||||||
|
if change.action not in ['remove', 'insert']
|
||||||
|
return
|
||||||
|
cursorPosition = @editor.getCursorPosition()
|
||||||
|
end = change.end
|
||||||
|
range = new Range(end.row, 0, end.row, end.column)
|
||||||
|
lineUpToCursor = @editor.getSession().getTextRange(range)
|
||||||
|
commandFragment = getLastCommandFragment(lineUpToCursor)
|
||||||
|
|
||||||
|
linesContainLabel = _.any(
|
||||||
|
change.lines,
|
||||||
|
(line) -> line.match(/\\label\{[^\}\n\\]{0,80}\}/)
|
||||||
|
)
|
||||||
|
linesContainPackage = _.any(
|
||||||
|
change.lines,
|
||||||
|
(line) -> line.match(/\\usepackage(?:\[.*?])?\s*{.*?}/)
|
||||||
|
)
|
||||||
|
linesContainMeta = linesContainPackage or linesContainLabel
|
||||||
|
|
||||||
|
lastCommandFragmentIsLabel = commandFragment?.startsWith '\\label{'
|
||||||
|
lastCommandFragmentIsPackage = commandFragment?.startsWith '\\usepackage'
|
||||||
|
lastCommandFragmentIsMeta = lastCommandFragmentIsPackage or lastCommandFragmentIsLabel
|
||||||
|
|
||||||
|
if linesContainMeta or lastCommandFragmentIsMeta
|
||||||
|
@scheduleLoadCurrentDocMetadataFromServer()
|
||||||
|
|
||||||
|
@editor.on 'changeSession', (e) =>
|
||||||
|
e.oldSession.off 'change', onChange
|
||||||
|
e.session.on 'change', onChange
|
||||||
|
|
||||||
|
loadCurrentDocMetadataFromServer: () ->
|
||||||
|
currentDocId = @$scope.docId
|
||||||
|
@Metadata.loadDocMetadataFromServer currentDocId
|
||||||
|
|
||||||
|
loadDocMetadataFromServer: (docId) ->
|
||||||
|
@Metadata.loadDocMetadataFromServer docId
|
||||||
|
|
||||||
|
scheduleLoadCurrentDocMetadataFromServer: () ->
|
||||||
|
# De-bounce loading labels with a timeout
|
||||||
|
currentDocId = @$scope.docId
|
||||||
|
existingTimeout = @debouncer[currentDocId]
|
||||||
|
if existingTimeout?
|
||||||
|
clearTimeout(existingTimeout)
|
||||||
|
delete @debouncer[currentDocId]
|
||||||
|
@debouncer[currentDocId] = setTimeout(
|
||||||
|
() =>
|
||||||
|
@loadDocMetadataFromServer(currentDocId)
|
||||||
|
delete @debouncer[currentDocId]
|
||||||
|
, 1000
|
||||||
|
, this
|
||||||
|
)
|
||||||
|
|
||||||
|
getAllLabels: () ->
|
||||||
|
@Metadata.getAllLabels()
|
||||||
|
|
||||||
|
getAllPackages: () ->
|
||||||
|
@Metadata.getAllPackages()
|
||||||
|
|
||||||
|
getAllMetadata: () ->
|
||||||
|
@Metadata.getAllMetadata()
|
||||||
Reference in New Issue
Block a user