From 81fcafb4761988e6460e230bbe2f47e7e2e4a735 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 13 Mar 2014 13:58:57 +0000 Subject: [PATCH 1/2] Make track changes a feature flag --- services/web/app/coffee/controllers/ProjectController.coffee | 4 ++-- services/web/app/coffee/models/User.coffee | 2 +- services/web/public/coffee/ide.coffee | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/services/web/app/coffee/controllers/ProjectController.coffee b/services/web/app/coffee/controllers/ProjectController.coffee index 1aefeabd0a..1c4b9a3349 100755 --- a/services/web/app/coffee/controllers/ProjectController.coffee +++ b/services/web/app/coffee/controllers/ProjectController.coffee @@ -120,7 +120,7 @@ module.exports = class ProjectController allowed: true featureSwitches: dropbox: false - longPolling: false + trackChanges: false else anonymous = false SubscriptionLocator.getUsersSubscription user._id, (err, subscription)-> @@ -154,7 +154,7 @@ module.exports = class ProjectController spellCheckLanguage: user.ace.spellCheckLanguage pdfViewer : user.ace.pdfViewer docPositions: {} - longPolling: user.featureSwitches.longPolling + trackChanges: user.featureSwitches.trackChanges }) sharelatexObject : JSON.stringify({ siteUrl: Settings.siteUrl, diff --git a/services/web/app/coffee/models/User.coffee b/services/web/app/coffee/models/User.coffee index a4141880a0..e71182ec2b 100644 --- a/services/web/app/coffee/models/User.coffee +++ b/services/web/app/coffee/models/User.coffee @@ -32,7 +32,7 @@ UserSchema = new Schema } featureSwitches : { dropbox: {type:Boolean, default:true}, - longPolling: {type:Boolean, default:false} + trackChanges: {type:Boolean, default:false} } referal_id : {type:String, default:() -> uuid.v4().split("-")[0]} refered_users: [ type:ObjectId, ref:'User' ] diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 871ac98d1e..e98163f87d 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -97,8 +97,6 @@ define [ ioOptions = reconnect: false "force new connection": true - if @userSettings.longPolling - ioOptions.transports = ["xhr-polling"] @socket = socket = io.connect null, ioOptions @messageManager = new MessageManager(@) @@ -119,7 +117,8 @@ define [ @cursorManager = new CursorManager(@) @fileViewManager = new FileViewManager(@) @analyticsManager = new AnalyticsManager(@) - @trackChangesManager = new TrackChangesManager(@) + if @userSettings.trackChanges + @trackChangesManager = new TrackChangesManager(@) @setLoadingMessage("Connecting") firstConnect = true From df706da7e0d85a0fb59da7d07e4fd2ec113130c7 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 13 Mar 2014 14:32:30 +0000 Subject: [PATCH 2/2] Add history entry into context menu for docs --- .../public/coffee/file-tree/EntityView.coffee | 2 ++ .../coffee/track-changes/DiffView.coffee | 9 +++-- .../track-changes/TrackChangesManager.coffee | 36 +++++++++++++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/services/web/public/coffee/file-tree/EntityView.coffee b/services/web/public/coffee/file-tree/EntityView.coffee index eab47883bb..84bf1cf023 100644 --- a/services/web/public/coffee/file-tree/EntityView.coffee +++ b/services/web/public/coffee/file-tree/EntityView.coffee @@ -100,6 +100,8 @@ define [ showContextMenu: (position) -> entries = @getContextMenuEntries() + @manager.trigger "contextmenu:beforeshow", @model, entries + @contextMenu = new ContextMenu(position, entries) @contextMenu.on "destroy", () => delete @contextMenu diff --git a/services/web/public/coffee/track-changes/DiffView.coffee b/services/web/public/coffee/track-changes/DiffView.coffee index 396de3de67..73006e2f3d 100644 --- a/services/web/public/coffee/track-changes/DiffView.coffee +++ b/services/web/public/coffee/track-changes/DiffView.coffee @@ -23,11 +23,14 @@ define [ @insertNameTag() return @ + destroy: () -> + @$editor?.remove() + createAceEditor: () -> @$el.empty() - $editor = $("
") - @$el.append($editor) - @aceEditor = Ace.edit($editor[0]) + @$editor = $("
") + @$el.append(@$editor) + @aceEditor = Ace.edit(@$editor[0]) @aceEditor.setTheme("ace/theme/#{window.userSettings.theme}") @aceEditor.setReadOnly true @aceEditor.setShowPrintMargin(false) diff --git a/services/web/public/coffee/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/track-changes/TrackChangesManager.coffee index 62a7aaf524..4e35ebe45f 100644 --- a/services/web/public/coffee/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/track-changes/TrackChangesManager.coffee @@ -4,26 +4,38 @@ define [ "track-changes/ChangeListView" "track-changes/DiffView" "utils/Modal" + "models/Doc" "moment" -], (ChangeList, Diff, ChangeListView, DiffView, Modal, moment) -> +], (ChangeList, Diff, ChangeListView, DiffView, Modal, Doc, moment) -> class TrackChangesManager template: $("#trackChangesPanelTemplate").html() constructor: (@ide) -> + @project_id = window.userSettings.project_id @$el = $(@template) $("#editorWrapper").append(@$el) - @hide() + @hideEl() @ide.editor.on "change:doc", () => - @hide() + @hideEl() @$el.find(".track-changes-close").on "click", (e) => e.preventDefault @hide() - show: () -> - @project_id = window.userSettings.project_id - @doc_id = @ide.editor.current_doc_id + @ide.fileTreeManager.on "contextmenu:beforeshow", (entity, entries) => + if entity instanceof Doc + entries.push { + divider: true + }, { + text: "History" + onClick: () => + @show(entity.id) + } + + show: (@doc_id) -> + @ide.fileTreeManager.selectEntity(@doc_id) + @changes = new ChangeList([], doc_id: @doc_id, project_id: @project_id) @changeListView = new ChangeListView( @@ -40,8 +52,15 @@ define [ @changeListView.on "restore", (change) => @restore(change) + if @diffView? + @diffView.destroy() + @showEl() + hide: () -> + @hideEl() + @ide.fileTreeManager.openDoc(@doc_id) + autoSelectDiff: () -> if @changes.models.length == 0 return @@ -69,6 +88,9 @@ define [ from: fromModel.get("fromVersion") to: toModel.get("toVersion") }) + + if @diffView? + @diffView.destroy() @diffView = new DiffView( model: @diff el: @$el.find(".track-changes-diff") @@ -79,7 +101,7 @@ define [ @ide.editor.hide() @$el.show() - hide: () -> + hideEl: () -> @ide.editor.show() @$el.hide()