From 34b2b665a30e91b68c2aad5a4876fe1fe2f80268 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 10 Nov 2016 10:52:09 +0000 Subject: [PATCH] Accept and reject changes --- .../web/app/views/project/editor/editor.jade | 2 ++ .../track-changes/ChangesTracker.coffee | 15 +++++++- .../track-changes/TrackChangesManager.coffee | 34 +++++++++++++++++++ .../controllers/ReviewPanelController.coffee | 6 ++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/services/web/app/views/project/editor/editor.jade b/services/web/app/views/project/editor/editor.jade index 176b1518d0..182058f51b 100644 --- a/services/web/app/views/project/editor/editor.jade +++ b/services/web/app/views/project/editor/editor.jade @@ -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") diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/ChangesTracker.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/ChangesTracker.coffee index 82fb72bda7..bfb03baac7 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/ChangesTracker.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/ChangesTracker.coffee @@ -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 = { diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee index b82aaad553..d869158e8a 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee @@ -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 + 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 d94fe057cd..b45dd7262d 100644 --- a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee +++ b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee @@ -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"