Merge pull request #506 from sharelatex/pr-prepare-bulk-actions-events

Prepare bulk actions events
This commit is contained in:
Paulo Jorge Reis 2017-05-16 15:51:19 +01:00 committed by GitHub
commit 9e4869ee3d
3 changed files with 72 additions and 25 deletions

View file

@ -27,10 +27,16 @@ define [
@selectLineIfNoSelection() @selectLineIfNoSelection()
@$scope.$on "change:accept", (e, change_id) => @$scope.$on "change:accept", (e, change_id) =>
@acceptChangeId(change_id) @acceptChangeIds([ change_id ])
@$scope.$on "change:reject", (e, change_id) => @$scope.$on "change:reject", (e, change_id) =>
@rejectChangeId(change_id) @rejectChangeIds([ change_id ])
@$scope.$on "change:bulk-accept", (e, change_ids) =>
@acceptChangeIds(change_ids)
@$scope.$on "change:bulk-reject", (e, change_ids) =>
@rejectChangeIds(change_ids)
@$scope.$on "comment:remove", (e, comment_id) => @$scope.$on "comment:remove", (e, comment_id) =>
@removeCommentId(comment_id) @removeCommentId(comment_id)
@ -207,31 +213,32 @@ define [
if @editor.selection.isEmpty() if @editor.selection.isEmpty()
@editor.selection.selectLine() @editor.selection.selectLine()
acceptChangeId: (change_id) -> acceptChangeIds: (change_ids) ->
@rangesTracker.removeChangeId(change_id) @rangesTracker.removeChangeIds(change_ids)
@updateAnnotations() @updateAnnotations()
rejectChangeId: (change_id) -> rejectChangeIds: (change_ids) ->
change = @rangesTracker.getChange(change_id) changes = @rangesTracker.getChanges(change_ids)
return if !change? return if changes.length == 0
session = @editor.getSession() session = @editor.getSession()
if change.op.d? for change in changes
content = change.op.d if change.op.d?
position = @_shareJsOffsetToAcePosition(change.op.p) content = change.op.d
session.$fromReject = true # Tell track changes to cancel out delete position = @_shareJsOffsetToAcePosition(change.op.p)
session.insert(position, content) session.$fromReject = true # Tell track changes to cancel out delete
session.$fromReject = false session.insert(position, content)
else if change.op.i? session.$fromReject = false
start = @_shareJsOffsetToAcePosition(change.op.p) else if change.op.i?
end = @_shareJsOffsetToAcePosition(change.op.p + change.op.i.length) start = @_shareJsOffsetToAcePosition(change.op.p)
editor_text = session.getDocument().getTextRange({start, end}) end = @_shareJsOffsetToAcePosition(change.op.p + change.op.i.length)
if editor_text != change.op.i editor_text = session.getDocument().getTextRange({start, end})
throw new Error("Op to be removed (#{JSON.stringify(change.op)}), does not match editor text, '#{editor_text}'") if editor_text != change.op.i
session.$fromReject = true throw new Error("Op to be removed (#{JSON.stringify(change.op)}), does not match editor text, '#{editor_text}'")
session.remove({start, end}) session.$fromReject = true
session.$fromReject = false session.remove({start, end})
else session.$fromReject = false
throw new Error("unknown change: #{JSON.stringify(change)}") else
throw new Error("unknown change: #{JSON.stringify(change)}")
removeCommentId: (comment_id) -> removeCommentId: (comment_id) ->
@rangesTracker.removeCommentId(comment_id) @rangesTracker.removeCommentId(comment_id)

View file

@ -96,10 +96,42 @@ load = () ->
break break
return change return change
getChanges: (change_ids) ->
changes_response = []
ids_map = {}
for change_id in change_ids
ids_map[change_id] = true
for change in @changes
if ids_map[change.id]
delete ids_map[change.id]
changes_response.push change
return changes_response
removeChangeId: (change_id) -> removeChangeId: (change_id) ->
change = @getChange(change_id) change = @getChange(change_id)
return if !change? return if !change?
@_removeChange(change) @_removeChange(change)
removeChangeIds: (change_to_remove_ids) ->
return if !change_to_remove_ids?.length > 0
i = @changes.length
remove_change_id = {}
for change_id in change_to_remove_ids
remove_change_id[change_id] = true
remaining_changes = []
for change in @changes
if remove_change_id[change.id]
delete remove_change_id[change.id]
@_markAsDirty change, "change", "removed"
else
remaining_changes.push change
@changes = remaining_changes
validate: (text) -> validate: (text) ->
for change in @changes for change in @changes

View file

@ -76,6 +76,14 @@ define [
$scope.$broadcast "change:accept", change_id $scope.$broadcast "change:accept", change_id
updateEntries(doc_id) updateEntries(doc_id)
$scope.$apply () -> $scope.$apply () ->
ide.socket.on "accept-changes", (doc_id, change_ids) ->
if doc_id != $scope.editor.open_doc_id
getChangeTracker(doc_id).removeChangeIds(change_ids)
else
$scope.$broadcast "change:bulk-accept", change_ids
updateEntries(doc_id)
$scope.$apply () ->
ide.socket.on "resolve-thread", (thread_id, user) -> ide.socket.on "resolve-thread", (thread_id, user) ->
_onCommentResolved(thread_id, user) _onCommentResolved(thread_id, user)