Accept and reject changes

This commit is contained in:
James Allen 2016-11-10 10:52:09 +00:00
parent ca178c1a85
commit 34b2b665a3
4 changed files with 56 additions and 1 deletions

View file

@ -71,6 +71,8 @@ div.full-size(
.review-entry-body
{{ entry.content }}
.review-entry-actions
a(href, ng-click="acceptChange(entry_id)") Accept
a(href, ng-click="rejectChange(entry_id)") Reject
div(ng-if="entry.type == 'comment'")
div(ng-repeat="comment in entry.thread", class="comment-thread__comment")

View file

@ -61,6 +61,19 @@ define [
@emit "comment:added", comment
return comment
getChange: (change_id) ->
change = null
for c in @changes
if c.id == change_id
change = c
break
return change
removeChangeId: (change_id) ->
change = @getChange(change_id)
return if !change?
@_removeChange(change)
applyOp: (op, metadata) ->
metadata.ts ?= new Date()
# Apply an op that has been applied to the document to our changes to keep them up to date
@ -305,7 +318,7 @@ define [
@emit "changes:moved", moved_changes
_newId: () ->
@id++
(@id++).toString()
_addOp: (op, metadata) ->
change = {

View file

@ -44,6 +44,12 @@ define [
@$scope.$on "comment:select_line", (e) =>
@selectLineIfNoSelection()
@$scope.$on "change:accept", (e, change_id) =>
@acceptChangeId(change_id)
@$scope.$on "change:reject", (e, change_id) =>
@rejectChangeId(change_id)
onChange = (e) =>
if !@editor.initing and @enabled
@ -108,6 +114,33 @@ define [
selectLineIfNoSelection: () ->
if @editor.selection.isEmpty()
@editor.selection.selectLine()
acceptChangeId: (change_id) ->
@changesTracker.removeChangeId(change_id)
rejectChangeId: (change_id) ->
change = @changesTracker.getChange(change_id)
return if !change?
@changesTracker.removeChangeId(change_id)
is_tracking = @changesTracker.track_changes
@changesTracker.track_changes = false
session = @editor.getSession()
if change.op.d?
content = change.op.d
position = @_shareJsOffsetToAcePosition(change.op.p)
session.insert(position, content)
else if change.op.i?
start = @_shareJsOffsetToAcePosition(change.op.p)
end = @_shareJsOffsetToAcePosition(change.op.p + change.op.i.length)
editor_text = session.getDocument().getTextRange({start, end})
if editor_text != change.op.i
throw new Error("Op to be removed (#{JSON.stringify(change.op)}), does not match editor text, '#{editor_text}'")
session.remove({start, end})
else
throw new Error("unknown change: #{JSON.stringify(change)}")
setTimeout () =>
@changesTracker.track_changes = is_tracking
, 0
checkMapping: () ->
session = @editor.getSession()
@ -322,3 +355,4 @@ define [
callout_marker = markers[callout_marker_id]
callout_marker.range.start = start
callout_marker.range.end = start

View file

@ -60,6 +60,12 @@ define [
scroller.scrollTop(scroller.scrollTop() + deltaY * 4)
e.preventDefault()
$scope.acceptChange = (entry_id) ->
$scope.$broadcast "change:accept", entry_id
$scope.rejectChange = (entry_id) ->
$scope.$broadcast "change:reject", entry_id
$scope.startNewComment = () ->
$scope.commentState.adding = true
$scope.$broadcast "comment:select_line"