Sync track changes state between sessions and client

This commit is contained in:
James Allen 2017-01-10 16:11:12 +01:00
parent 85c613e161
commit f31fa98679
10 changed files with 42 additions and 7 deletions

View file

@ -201,7 +201,7 @@ module.exports = ProjectController =
async.parallel { async.parallel {
project: (cb)-> 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)-> user: (cb)->
if !user_id? if !user_id?
cb null, defaultSettingsForAnonymousUser(user_id) cb null, defaultSettingsForAnonymousUser(user_id)
@ -267,6 +267,7 @@ module.exports = ProjectController =
pdfViewer : user.ace.pdfViewer pdfViewer : user.ace.pdfViewer
syntaxValidation: user.ace.syntaxValidation syntaxValidation: user.ace.syntaxValidation
} }
trackChangesEnabled: !!project.track_changes
privilegeLevel: privilegeLevel privilegeLevel: privilegeLevel
chatUrl: Settings.apis.chat.url chatUrl: Settings.apis.chat.url
anonymous: anonymous anonymous: anonymous

View file

@ -3,6 +3,7 @@ logger = require "logger-sharelatex"
UserInfoController = require "../User/UserInfoController" UserInfoController = require "../User/UserInfoController"
DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler" DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler"
EditorRealTimeController = require("../Editor/EditorRealTimeController") EditorRealTimeController = require("../Editor/EditorRealTimeController")
TrackChangesManager = require "./TrackChangesManager"
module.exports = TrackChangesController = module.exports = TrackChangesController =
getAllRanges: (req, res, next) -> getAllRanges: (req, res, next) ->
@ -29,3 +30,11 @@ module.exports = TrackChangesController =
EditorRealTimeController.emitToRoom project_id, "accept-change", doc_id, change_id, (err)-> EditorRealTimeController.emitToRoom project_id, "accept-change", doc_id, change_id, (err)->
res.send 204 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

View file

@ -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

View file

@ -32,6 +32,7 @@ ProjectSchema = new Schema
archived : { type: Boolean } archived : { type: Boolean }
deletedDocs : [DeletedDocSchema] deletedDocs : [DeletedDocSchema]
imageName : { type: String } imageName : { type: String }
track_changes : { type: Boolean }
ProjectSchema.statics.getProject = (project_or_id, fields, callback)-> ProjectSchema.statics.getProject = (project_or_id, fields, callback)->
if project_or_id._id? if project_or_id._id?

View file

@ -180,6 +180,7 @@ module.exports = class Router
webRouter.get "/project/:project_id/ranges", AuthorizationMiddlewear.ensureUserCanReadProject, TrackChangesController.getAllRanges webRouter.get "/project/:project_id/ranges", AuthorizationMiddlewear.ensureUserCanReadProject, TrackChangesController.getAllRanges
webRouter.get "/project/:project_id/changes/users", AuthorizationMiddlewear.ensureUserCanReadProject, TrackChangesController.getAllChangesUsers 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/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/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects

View file

@ -107,6 +107,7 @@ block requirejs
window.csrfToken = "!{csrfToken}"; window.csrfToken = "!{csrfToken}";
window.anonymous = #{anonymous}; window.anonymous = #{anonymous};
window.maxDocLength = #{maxDocLength}; window.maxDocLength = #{maxDocLength};
window.trackChangesEnabled = #{trackChangesEnabled};
window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)};
window.requirejs = { window.requirejs = {
"paths" : { "paths" : {

View file

@ -9,11 +9,11 @@
on-delete="deleteComment(entryId, threadId);" on-delete="deleteComment(entryId, threadId);"
is-loading="reviewPanel.dropdown.loading" 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 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 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") span.review-panel-toolbar-spinner(ng-if="editor.wantTrackChanges != editor.trackChanges")
i.fa.fa-spin.fa-spinner i.fa.fa-spin.fa-spinner

View file

@ -11,7 +11,7 @@ define [
open_doc_name: null open_doc_name: null
opening: true opening: true
trackChanges: false trackChanges: false
wantTrackChanges: false wantTrackChanges: window.trackChangesEnabled
} }
@$scope.$on "entity:selected", (event, entity) => @$scope.$on "entity:selected", (event, entity) =>

View file

@ -309,6 +309,15 @@ define [
$scope.gotoEntry = (doc_id, entry) -> $scope.gotoEntry = (doc_id, entry) ->
ide.editorManager.openDocId(doc_id, { gotoOffset: entry.offset }) 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 _refreshingRangeUsers = false
_refreshedForUserIds = {} _refreshedForUserIds = {}
refreshChangeUsers = (refresh_for_user_id) -> refreshChangeUsers = (refresh_for_user_id) ->

View file

@ -4,10 +4,18 @@ define [
App.directive "reviewPanelToggle", () -> App.directive "reviewPanelToggle", () ->
restrict: "E" restrict: "E"
scope: 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: """ template: """
<div class="rp-toggle"> <div class="rp-toggle">
<input id="rp-toggle-{{$id}}" type="checkbox" class="rp-toggle-hidden-input" ng-model="innerModel" /> <input id="rp-toggle-{{$id}}" type="checkbox" class="rp-toggle-hidden-input" ng-model="localModel" ng-change="onChange()" />
<label for="rp-toggle-{{$id}}" class="rp-toggle-btn"></label> <label for="rp-toggle-{{$id}}" class="rp-toggle-btn"></label>
</div> </div>
""" """