diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 1d975ea5b3..9713a1b1e2 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -201,7 +201,7 @@ module.exports = ProjectController = async.parallel { project: (cb)-> - ProjectGetter.getProject project_id, { name: 1, lastUpdated: 1}, cb + ProjectGetter.getProject project_id, { name: 1, lastUpdated: 1, track_changes: 1 }, cb user: (cb)-> if !user_id? cb null, defaultSettingsForAnonymousUser(user_id) @@ -267,6 +267,7 @@ module.exports = ProjectController = pdfViewer : user.ace.pdfViewer syntaxValidation: user.ace.syntaxValidation } + trackChangesEnabled: !!project.track_changes privilegeLevel: privilegeLevel chatUrl: Settings.apis.chat.url anonymous: anonymous diff --git a/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee b/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee index 7fb873a209..71adadb213 100644 --- a/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee +++ b/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee @@ -3,6 +3,7 @@ logger = require "logger-sharelatex" UserInfoController = require "../User/UserInfoController" DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler" EditorRealTimeController = require("../Editor/EditorRealTimeController") +TrackChangesManager = require "./TrackChangesManager" module.exports = TrackChangesController = getAllRanges: (req, res, next) -> @@ -29,3 +30,11 @@ module.exports = TrackChangesController = EditorRealTimeController.emitToRoom project_id, "accept-change", doc_id, change_id, (err)-> res.send 204 + toggleTrackChanges: (req, res, next) -> + {project_id} = req.params + track_changes_on = !!req.body.on + logger.log {project_id, track_changes_on}, "request to toggle track changes" + TrackChangesManager.toggleTrackChanges project_id, track_changes_on, (error) -> + return next(error) if error? + EditorRealTimeController.emitToRoom project_id, "toggle-track-changes", track_changes_on, (err)-> + res.send 204 diff --git a/services/web/app/coffee/Features/TrackChanges/TrackChangesManager.coffee b/services/web/app/coffee/Features/TrackChanges/TrackChangesManager.coffee new file mode 100644 index 0000000000..8eb7c10c29 --- /dev/null +++ b/services/web/app/coffee/Features/TrackChanges/TrackChangesManager.coffee @@ -0,0 +1,5 @@ +Project = require("../../models/Project").Project + +module.exports = TrackChangesManager = + toggleTrackChanges: (project_id, track_changes_on, callback = (error) ->) -> + Project.update {_id: project_id}, {track_changes: track_changes_on}, callback diff --git a/services/web/app/coffee/models/Project.coffee b/services/web/app/coffee/models/Project.coffee index 1d53999bd9..18387bdc0b 100644 --- a/services/web/app/coffee/models/Project.coffee +++ b/services/web/app/coffee/models/Project.coffee @@ -32,6 +32,7 @@ ProjectSchema = new Schema archived : { type: Boolean } deletedDocs : [DeletedDocSchema] imageName : { type: String } + track_changes : { type: Boolean } ProjectSchema.statics.getProject = (project_or_id, fields, callback)-> if project_or_id._id? diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 05c6c7194b..d98f9579e1 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -180,6 +180,7 @@ module.exports = class Router webRouter.get "/project/:project_id/ranges", AuthorizationMiddlewear.ensureUserCanReadProject, TrackChangesController.getAllRanges webRouter.get "/project/:project_id/changes/users", AuthorizationMiddlewear.ensureUserCanReadProject, TrackChangesController.getAllChangesUsers webRouter.post "/project/:project_id/doc/:doc_id/changes/:change_id/accept", AuthorizationMiddlewear.ensureUserCanWriteProjectContent, TrackChangesController.acceptChange + webRouter.post "/project/:project_id/track_changes", AuthorizationMiddlewear.ensureUserCanWriteProjectContent, TrackChangesController.toggleTrackChanges webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index 01e1a8b88f..54c742fd15 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -107,6 +107,7 @@ block requirejs window.csrfToken = "!{csrfToken}"; window.anonymous = #{anonymous}; window.maxDocLength = #{maxDocLength}; + window.trackChangesEnabled = #{trackChangesEnabled}; window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.requirejs = { "paths" : { diff --git a/services/web/app/views/project/editor/review-panel.jade b/services/web/app/views/project/editor/review-panel.jade index 4ec1d24f6e..34e49f03f0 100644 --- a/services/web/app/views/project/editor/review-panel.jade +++ b/services/web/app/views/project/editor/review-panel.jade @@ -9,11 +9,11 @@ on-delete="deleteComment(entryId, threadId);" is-loading="reviewPanel.dropdown.loading" ) - span.review-panel-toolbar-label(ng-click="editor.wantTrackChanges = true;", ng-if="editor.wantTrackChanges === false") Track Changes is + span.review-panel-toolbar-label(ng-click="toggleTrackChanges(true)", ng-if="editor.wantTrackChanges === false") Track Changes is strong off - span.review-panel-toolbar-label(ng-click="editor.wantTrackChanges = false;", ng-if="editor.wantTrackChanges === true") Track Changes is + span.review-panel-toolbar-label(ng-click="toggleTrackChanges(false)", ng-if="editor.wantTrackChanges === true") Track Changes is strong on - review-panel-toggle(ng-if="editor.wantTrackChanges == editor.trackChanges", ng-model="editor.wantTrackChanges") + review-panel-toggle(ng-if="editor.wantTrackChanges == editor.trackChanges", ng-model="editor.wantTrackChanges", on-toggle="toggleTrackChanges") span.review-panel-toolbar-spinner(ng-if="editor.wantTrackChanges != editor.trackChanges") i.fa.fa-spin.fa-spinner diff --git a/services/web/public/coffee/ide/editor/EditorManager.coffee b/services/web/public/coffee/ide/editor/EditorManager.coffee index 629e1a4cb3..22fcef1a69 100644 --- a/services/web/public/coffee/ide/editor/EditorManager.coffee +++ b/services/web/public/coffee/ide/editor/EditorManager.coffee @@ -11,7 +11,7 @@ define [ open_doc_name: null opening: true trackChanges: false - wantTrackChanges: false + wantTrackChanges: window.trackChangesEnabled } @$scope.$on "entity:selected", (event, entity) => diff --git a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee index 96cc0fc86f..9a28c4995e 100644 --- a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee +++ b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee @@ -308,6 +308,15 @@ define [ $scope.gotoEntry = (doc_id, entry) -> ide.editorManager.openDocId(doc_id, { gotoOffset: entry.offset }) + + $scope.toggleTrackChanges = (value) -> + console.log "Toggling track changes", value + $scope.editor.wantTrackChanges = value + $http.post "/project/#{$scope.project_id}/track_changes", {_csrf: window.csrfToken, on: value} + + ide.socket.on "toggle-track-changes", (value) -> + $scope.$apply () -> + $scope.editor.wantTrackChanges = value _refreshingRangeUsers = false _refreshedForUserIds = {} diff --git a/services/web/public/coffee/ide/review-panel/directives/reviewPanelToggle.coffee b/services/web/public/coffee/ide/review-panel/directives/reviewPanelToggle.coffee index e3844d1b12..24b7070d07 100644 --- a/services/web/public/coffee/ide/review-panel/directives/reviewPanelToggle.coffee +++ b/services/web/public/coffee/ide/review-panel/directives/reviewPanelToggle.coffee @@ -4,10 +4,18 @@ define [ App.directive "reviewPanelToggle", () -> restrict: "E" scope: - innerModel: '=ngModel' + onToggle: '=' + ngModel: '=' + link: (scope) -> + scope.onChange = (args...) -> + scope.onToggle(scope.localModel) + scope.localModel = scope.ngModel + scope.$watch "ngModel", (value) -> + scope.localModel = value + template: """