mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Control sync state with server.
This commit is contained in:
parent
0ac52e7f19
commit
f4bdd5eb2b
2 changed files with 29 additions and 18 deletions
|
@ -69,7 +69,7 @@
|
||||||
//- Missing on-toggle attribute because we also need to pass user_id to the toggleTrackChangesForUser
|
//- Missing on-toggle attribute because we also need to pass user_id to the toggleTrackChangesForUser
|
||||||
//- method, and it's not clear how.
|
//- method, and it's not clear how.
|
||||||
review-panel-toggle(
|
review-panel-toggle(
|
||||||
ng-model="reviewPanel.trackChangesOnForEveryone || reviewPanel.trackChangesState[user.id]"
|
ng-model="reviewPanel.trackChangesState[user.id].value"
|
||||||
on-toggle="toggleTrackChangesForUser(isOn, user.id);"
|
on-toggle="toggleTrackChangesForUser(isOn, user.id);"
|
||||||
disabled="reviewPanel.trackChangesOnForEveryone"
|
disabled="reviewPanel.trackChangesOnForEveryone"
|
||||||
)
|
)
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
) {{ users[member._id].name }}
|
) {{ users[member._id].name }}
|
||||||
//- {{member._id}}
|
//- {{member._id}}
|
||||||
review-panel-toggle(
|
review-panel-toggle(
|
||||||
ng-model="reviewPanel.trackChangesOnForEveryone || reviewPanel.trackChangesState[member._id]"
|
ng-model="reviewPanel.trackChangesState[member._id].value"
|
||||||
on-toggle="toggleTrackChangesForUser(isOn, member._id);"
|
on-toggle="toggleTrackChangesForUser(isOn, member._id);"
|
||||||
disabled="reviewPanel.trackChangesOnForEveryone"
|
disabled="reviewPanel.trackChangesOnForEveryone"
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,6 +11,11 @@ define [
|
||||||
CUR_FILE : "cur_file"
|
CUR_FILE : "cur_file"
|
||||||
OVERVIEW : "overview"
|
OVERVIEW : "overview"
|
||||||
|
|
||||||
|
$scope.UserTCSyncState = UserTCSyncState =
|
||||||
|
SYNCED : "synced"
|
||||||
|
PENDING : "pending"
|
||||||
|
|
||||||
|
|
||||||
window.reviewPanel = # DEBUG LINE
|
window.reviewPanel = # DEBUG LINE
|
||||||
$scope.reviewPanel =
|
$scope.reviewPanel =
|
||||||
trackChangesState: {}
|
trackChangesState: {}
|
||||||
|
@ -571,34 +576,45 @@ define [
|
||||||
ide.editorManager.openDocId(doc_id, { gotoOffset: entry.offset })
|
ide.editorManager.openDocId(doc_id, { gotoOffset: entry.offset })
|
||||||
|
|
||||||
applyTrackChangesStateToClient = (state) ->
|
applyTrackChangesStateToClient = (state) ->
|
||||||
console.log "[applyTrackChangesStateToClient]", state
|
|
||||||
if typeof state is "boolean"
|
if typeof state is "boolean"
|
||||||
console.log "[applyTrackChangesStateToClient]", "BOOLEAN"
|
|
||||||
$scope.reviewPanel.trackChangesOnForEveryone = state
|
$scope.reviewPanel.trackChangesOnForEveryone = state
|
||||||
$scope.reviewPanel.trackChangesState = {}
|
$scope.reviewPanel.trackChangesState = {}
|
||||||
$scope.editor.wantTrackChanges = state
|
$scope.editor.wantTrackChanges = state
|
||||||
else
|
else
|
||||||
$scope.reviewPanel.trackChangesOnForEveryone = false
|
$scope.reviewPanel.trackChangesOnForEveryone = false
|
||||||
$scope.reviewPanel.trackChangesState = state
|
for member in $scope.project.members
|
||||||
|
_setUserState(member._id, state[member._id] ? false)
|
||||||
|
_setUserState(ide.$scope.user.id, state[ide.$scope.user.id] ? false)
|
||||||
|
|
||||||
|
for id, state of $scope.reviewPanel.trackChangesState
|
||||||
|
console.log id, state.value, state.syncState
|
||||||
# State is an object with user_ids as keys
|
# State is an object with user_ids as keys
|
||||||
if state[ide.$scope.user.id]
|
if state[ide.$scope.user.id]
|
||||||
$scope.editor.wantTrackChanges = true
|
$scope.editor.wantTrackChanges = true
|
||||||
else
|
else
|
||||||
$scope.editor.wantTrackChanges = false
|
$scope.editor.wantTrackChanges = false
|
||||||
|
|
||||||
|
_setUserState = (userId, newValue) ->
|
||||||
|
$scope.reviewPanel.trackChangesState[userId] ?= {}
|
||||||
|
state = $scope.reviewPanel.trackChangesState[userId]
|
||||||
|
if !state.syncState? or state.syncState == UserTCSyncState.SYNCED
|
||||||
|
state.value = newValue
|
||||||
|
state.syncState = UserTCSyncState.SYNCED
|
||||||
|
if state.syncState == UserTCSyncState.PENDING and state.value == newValue
|
||||||
|
state.syncState = UserTCSyncState.SYNCED
|
||||||
|
|
||||||
applyClientTrackChangesStateToServer = () ->
|
applyClientTrackChangesStateToServer = () ->
|
||||||
if $scope.reviewPanel.trackChangesOnForEveryone
|
if $scope.reviewPanel.trackChangesOnForEveryone
|
||||||
data = {on : true}
|
data = {on : true}
|
||||||
else
|
else
|
||||||
data = {on_for: $scope.reviewPanel.trackChangesState}
|
data = {on_for: {}}
|
||||||
console.log "[applyClientTrackChangesStateToServer]", data
|
for userId, userState of $scope.reviewPanel.trackChangesState
|
||||||
|
data.on_for[userId] = true if userState.value
|
||||||
data._csrf = window.csrfToken
|
data._csrf = window.csrfToken
|
||||||
$http.post "/project/#{$scope.project_id}/track_changes", data
|
$http.post "/project/#{$scope.project_id}/track_changes", data
|
||||||
|
|
||||||
setTrackChangesState = (state) ->
|
setTrackChangesState = (state) ->
|
||||||
console.log "[setTrackChangesState]", state
|
|
||||||
if $scope.project.features.trackChanges
|
if $scope.project.features.trackChanges
|
||||||
applyTrackChangesStateToClient(state)
|
|
||||||
applyClientTrackChangesStateToServer()
|
applyClientTrackChangesStateToServer()
|
||||||
event_tracking.sendMB "rp-trackchanges-toggle", { state }
|
event_tracking.sendMB "rp-trackchanges-toggle", { state }
|
||||||
else
|
else
|
||||||
|
@ -608,21 +624,17 @@ define [
|
||||||
reviewPanel.fullTCStateCollapsed = !reviewPanel.fullTCStateCollapsed
|
reviewPanel.fullTCStateCollapsed = !reviewPanel.fullTCStateCollapsed
|
||||||
|
|
||||||
$scope.toggleTrackChangesForEveryone = (onForEveryone) ->
|
$scope.toggleTrackChangesForEveryone = (onForEveryone) ->
|
||||||
console.log "[toggleTrackChangesForEveryone]", onForEveryone
|
|
||||||
setTrackChangesState(onForEveryone)
|
setTrackChangesState(onForEveryone)
|
||||||
|
|
||||||
|
|
||||||
window.toggleTrackChangesForUser = # DEBUG LINE
|
window.toggleTrackChangesForUser = # DEBUG LINE
|
||||||
$scope.toggleTrackChangesForUser = (onForUser, userId) ->
|
$scope.toggleTrackChangesForUser = (onForUser, userId) ->
|
||||||
console.log "[toggleTrackChangesForUser]", onForUser, userId
|
|
||||||
state = $scope.reviewPanel.trackChangesState
|
state = $scope.reviewPanel.trackChangesState
|
||||||
state[userId] = onForUser
|
state[userId] =
|
||||||
if state[user_id] == false
|
value : onForUser
|
||||||
delete state[userId]
|
syncState : UserTCSyncState.PENDING
|
||||||
setTrackChangesState(state)
|
setTrackChangesState(state)
|
||||||
|
|
||||||
ide.socket.on "toggle-track-changes", (state) ->
|
ide.socket.on "toggle-track-changes", (state) ->
|
||||||
console.log "[ide toggle-track-changes]", state
|
|
||||||
$scope.$apply () ->
|
$scope.$apply () ->
|
||||||
applyTrackChangesStateToClient(state)
|
applyTrackChangesStateToClient(state)
|
||||||
|
|
||||||
|
@ -649,7 +661,6 @@ define [
|
||||||
|
|
||||||
_inited = false
|
_inited = false
|
||||||
ide.$scope.$on "project:joined", () ->
|
ide.$scope.$on "project:joined", () ->
|
||||||
console.log "project joined, setting track changes state from window"
|
|
||||||
return if _inited
|
return if _inited
|
||||||
project = ide.$scope.project
|
project = ide.$scope.project
|
||||||
if project.features.trackChanges
|
if project.features.trackChanges
|
||||||
|
|
Loading…
Reference in a new issue