diff --git a/services/web/app/coffee/Features/Labels/LabelsController.coffee b/services/web/app/coffee/Features/Labels/LabelsController.coffee deleted file mode 100644 index 7608a40021..0000000000 --- a/services/web/app/coffee/Features/Labels/LabelsController.coffee +++ /dev/null @@ -1,28 +0,0 @@ -EditorRealTimeController = require "../Editor/EditorRealTimeController" -LabelsHandler = require './LabelsHandler' -logger = require 'logger-sharelatex' - - -module.exports = LabelsController = - - getAllLabels: (req, res, next) -> - project_id = req.params.project_id - logger.log {project_id}, "getting all labels for project" - LabelsHandler.getAllLabelsForProject project_id, (err, projectLabels) -> - if err? - logger.err {project_id, err}, "[LabelsController] error getting all labels from project" - return next(err) - res.json {projectId: project_id, projectLabels: projectLabels} - - broadcastLabelsForDoc: (req, res, next) -> - project_id = req.params.project_id - doc_id = req.params.doc_id - logger.log {project_id, doc_id}, "getting labels for doc" - LabelsHandler.getLabelsForDoc project_id, doc_id, (err, docLabels) -> - if err? - logger.err {project_id, doc_id, err}, "[LabelsController] error getting labels from doc" - return next(err) - EditorRealTimeController.emitToRoom project_id, 'broadcastDocLabels', { - docId: doc_id, labels: docLabels - } - res.sendStatus(200) diff --git a/services/web/app/coffee/Features/Labels/LabelsHandler.coffee b/services/web/app/coffee/Features/Labels/LabelsHandler.coffee deleted file mode 100644 index 1d4cc013d5..0000000000 --- a/services/web/app/coffee/Features/Labels/LabelsHandler.coffee +++ /dev/null @@ -1,43 +0,0 @@ -ProjectEntityHandler = require "../Project/ProjectEntityHandler" -DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler') - - -module.exports = LabelsHandler = - - labelCaptureRegex: () -> - /\\label\{([^\}\n\\]{0,80})\}/g - - getAllLabelsForProject: (projectId, callback=(err, projectLabels)->) -> - DocumentUpdaterHandler.flushProjectToMongo projectId, (err) -> - if err? - return callback(err) - ProjectEntityHandler.getAllDocs projectId, (err, docs) -> - if err? - return callback(err) - projectLabels = LabelsHandler.extractLabelsFromProjectDocs docs - callback(null, projectLabels) - - getLabelsForDoc: (projectId, docId, callback=(err, docLabels)->) -> - DocumentUpdaterHandler.flushDocToMongo projectId, docId, (err) -> - if err? - return callback(err) - ProjectEntityHandler.getDoc projectId, docId, (err, lines) -> - if err? - return callback(err) - docLabels = LabelsHandler.extractLabelsFromDoc lines - callback(null, docLabels) - - extractLabelsFromDoc: (lines) -> - docLabels = [] - for line in lines - re = LabelsHandler.labelCaptureRegex() - while (labelMatch = re.exec(line)) - if labelMatch[1] - docLabels.push(labelMatch[1]) - return docLabels - - extractLabelsFromProjectDocs: (projectDocs) -> - projectLabels = {} # docId => List[Label] - for _path, doc of projectDocs - projectLabels[doc._id] = LabelsHandler.extractLabelsFromDoc(doc.lines) - return projectLabels diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 3e3aa1af7a..f8ec65ac53 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -44,7 +44,6 @@ SudoModeMiddlewear = require('./Features/SudoMode/SudoModeMiddlewear') AnalyticsRouter = require('./Features/Analytics/AnalyticsRouter') AnnouncementsController = require("./Features/Announcements/AnnouncementsController") MetaController = require('./Features/Metadata/MetaController') -LabelsController = require('./Features/Labels/LabelsController') TokenAccessController = require('./Features/TokenAccess/TokenAccessController') Features = require('./infrastructure/Features') @@ -206,8 +205,6 @@ module.exports = class Router webRouter.get '/project/:project_id/metadata', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), MetaController.getMetadata webRouter.post '/project/:project_id/doc/:doc_id/metadata', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), MetaController.broadcastMetadataForDoc - webRouter.get '/project/:project_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.getAllLabels - webRouter.post '/project/:project_id/doc/:doc_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.broadcastLabelsForDoc webRouter.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags webRouter.post '/tag', AuthenticationController.requireLogin(), TagsController.createTag @@ -360,4 +357,3 @@ module.exports = class Router TokenAccessController.readAndWriteToken webRouter.get '*', ErrorController.notFound - diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 55eb2cb179..6908b25bce 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -10,13 +10,11 @@ define [ "ide/editor/directives/aceEditor/cursor-position/CursorPositionManager" "ide/editor/directives/aceEditor/track-changes/TrackChangesManager" "ide/editor/directives/aceEditor/metadata/MetadataManager" - "ide/editor/directives/aceEditor/labels/LabelsManager" - "ide/labels/services/labels" "ide/metadata/services/metadata" "ide/graphics/services/graphics" "ide/preamble/services/preamble" "ide/files/services/files" -], (App, Ace, SearchBox, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager, MetadataManager, LabelsManager) -> +], (App, Ace, SearchBox, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager, MetadataManager) -> EditSession = ace.require('ace/edit_session').EditSession ModeList = ace.require('ace/ext/modelist') @@ -38,7 +36,7 @@ define [ url = ace.config._moduleUrl(args...) + "?fingerprint=#{window.aceFingerprint}" return url - App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, labels, metadata, graphics, preamble, files, $http, $q) -> + App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, metadata, graphics, preamble, files, $http, $q) -> monkeyPatchSearch($rootScope, $compile) return { @@ -105,9 +103,8 @@ define [ highlightsManager = new HighlightsManager(scope, editor, element) cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage) 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, metadataManager, labelsManager, graphics, preamble, files) + autoCompleteManager = new AutoCompleteManager(scope, editor, element, metadataManager, graphics, preamble, files) # Prevert Ctrl|Cmd-S from triggering save dialog diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index 542b8ae69f..15a8b51b82 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -10,7 +10,7 @@ define [ aceSnippetManager = ace.require('ace/snippets').snippetManager class AutoCompleteManager - constructor: (@$scope, @editor, @element, @metadataManager, @labelsManager, @graphics, @preamble, @files) -> + constructor: (@$scope, @editor, @element, @metadataManager, @graphics, @preamble, @files) -> @monkeyPatchAutocomplete() diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/labels/LabelsManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/labels/LabelsManager.coffee deleted file mode 100644 index a5d2c10625..0000000000 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/labels/LabelsManager.coffee +++ /dev/null @@ -1,58 +0,0 @@ -define [ - "ace/ace" -], () -> - Range = ace.require("ace/range").Range - - getLastCommandFragment = (lineUpToCursor) -> - if m = lineUpToCursor.match(/(\\[^\\]+)$/) - return m[1] - else - return null - - class LabelsManager - constructor: (@$scope, @editor, @element, @Labels) -> - @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}\}/)) - lastCommandFragmentIsLabel = commandFragment?.slice(0,7) == '\\label{' - if linesContainLabel or lastCommandFragmentIsLabel - @scheduleLoadCurrentDocLabelsFromServer() - - @editor.on "changeSession", (e) => - e.oldSession.off "change", onChange - e.session.on "change", onChange - - loadCurrentDocLabelsFromServer: () -> - currentDocId = @$scope.docId - @Labels.loadDocLabelsFromServer(currentDocId) - - loadDocLabelsFromServer: (docId) -> - @Labels.loadDocLabelsFromServer(docId) - - scheduleLoadCurrentDocLabelsFromServer: () -> - # De-bounce loading labels with a timeout - currentDocId = @$scope.docId - existingTimeout = @debouncer[currentDocId] - if existingTimeout? - clearTimeout(existingTimeout) - delete @debouncer[currentDocId] - @debouncer[currentDocId] = setTimeout( - () => - @loadDocLabelsFromServer(currentDocId) - delete @debouncer[currentDocId] - , 1000 - , this - ) - - getAllLabels: () -> - @Labels.getAllLabels() diff --git a/services/web/public/coffee/ide/labels/LabelsManager.coffee b/services/web/public/coffee/ide/labels/LabelsManager.coffee deleted file mode 100644 index d5e7e2892e..0000000000 --- a/services/web/public/coffee/ide/labels/LabelsManager.coffee +++ /dev/null @@ -1,13 +0,0 @@ -define [], () -> - - class LabelsManager - - constructor: (@ide, @$scope, @labels) -> - - @ide.socket.on 'broadcastDocLabels', (data) => - @labels.onBroadcastDocLabels(data) - @$scope.$on 'entity:deleted', @labels.onEntityDeleted - @$scope.$on 'file:upload:complete', @labels.fileUploadComplete - - loadProjectLabelsFromServer: () -> - @labels.loadProjectLabelsFromServer() diff --git a/services/web/public/coffee/ide/labels/services/labels.coffee b/services/web/public/coffee/ide/labels/services/labels.coffee deleted file mode 100644 index 313d48175f..0000000000 --- a/services/web/public/coffee/ide/labels/services/labels.coffee +++ /dev/null @@ -1,44 +0,0 @@ -define [ - "base" -], (App) -> - - App.factory 'labels', ($http, ide) -> - - state = {documents: {}} - - labels = { - state: state - } - - labels.onBroadcastDocLabels = (data) -> - if data.docId and data.labels - state.documents[data.docId] = data.labels - - labels.onEntityDeleted = (e, entity) -> - if entity.type == 'doc' - delete state.documents[entity.id] - - labels.onFileUploadComplete = (e, upload) -> - if upload.entity_type == 'doc' - labels.loadDocLabelsFromServer(upload.entity_id) - - labels.getAllLabels = () -> - _.flatten(labels for docId, labels of state.documents) - - labels.loadProjectLabelsFromServer = () -> - $http - .get("/project/#{window.project_id}/labels") - .then (response) -> - { data } = response - if data.projectLabels - for docId, docLabels of data.projectLabels - state.documents[docId] = docLabels - - labels.loadDocLabelsFromServer = (docId) -> - $http - .post( - "/project/#{window.project_id}/doc/#{docId}/labels", - {_csrf: window.csrfToken} - ) - - return labels