Very crude adding of comments

This commit is contained in:
James Allen 2016-11-09 14:50:58 +00:00
parent 446ca7212a
commit 707ed43a7d
3 changed files with 47 additions and 3 deletions

View file

@ -51,8 +51,15 @@ div.full-size(
.review-panel-scroller
.review-entry-list(review-panel-sorted)
.review-entry(ng-repeat="(entry_id, entry) in reviewPanel.entries", ng-style="{'top': top}")
div.small {{ entry.metadata.ts }}
{{ entry.content }}
div(ng-if="entry.type != 'focus-position'")
div.small {{ entry.metadata.ts }}
{{ entry.content }}
div(ng-if="entry.type == 'focus-position'")
a.btn.btn-sm(href, ng-if="!commentState.adding", ng-click="startAddingComment()") Add comment
div(ng-if="commentState.adding")
textarea(ng-model="commentState.content")
a.btn.btn-sm.btm-primary(href, ng-click="submitComment()") Submit
.ui-layout-east
div(ng-if="ui.pdfLayout == 'sideBySide'")

View file

@ -34,6 +34,16 @@ define [
@changesTracker.on "comment:moved", (comment) =>
sl_console.log "[comment:moved]", comment
@_onCommentMoved(comment)
@editor.on "changeSelection", (e) =>
# TODO: Make this only update focus when we get a more optimised updating system
@updateReviewEntriesScope()
@$scope.$on "comment:add", (e, comment) =>
@addCommentToSelection(comment)
@$scope.$on "comment:select_line", (e) =>
@selectLineIfNoSelection()
onChange = (e) =>
if !@editor.initing and @enabled
@ -91,6 +101,10 @@ define [
end = @_aceRangeToShareJs(range.end)
length = end - offset
@addComment(offset, length, comment)
selectLineIfNoSelection: () ->
if @editor.selection.isEmpty()
@editor.selection.selectLine()
checkMapping: () ->
session = @editor.getSession()
@ -141,16 +155,25 @@ define [
@$scope.reviewPanel.entries = {}
for change in @changesTracker.changes
@$scope.reviewPanel.entries[change.id] = {
type: "change"
content: change.op.i or change.op.d
offset: change.op.p
metadata: change.metadata
}
for comment in @changesTracker.comments
@$scope.reviewPanel.entries[comment.id] = {
type: "comment"
content: comment.metadata.comment
offset: comment.offset
}
@updateFocus()
@recalculateReviewEntriesScreenPositions()
updateFocus: () ->
@$scope.reviewPanel.entries["focus-position"] = {
type: "focus-position"
offset: @_aceRangeToShareJs(@editor.getSelectionRange().start)
}
@recalculateReviewEntriesScreenPositions()
recalculateReviewEntriesScreenPositions: () ->
@ -161,6 +184,7 @@ define [
screen_position = session.documentToScreenPosition(doc_position.row, doc_position.column)
y = screen_position.row * renderer.lineHeight
entry.screenPos = { y }
@$scope.$apply()
_makeZeroWidthRange: (position) ->

View file

@ -6,6 +6,10 @@ define [
$scope.reviewPanel =
entries: {}
trackNewChanges: false
$scope.commentState =
adding: false
content: ""
scroller = $element.find(".review-panel-scroller")
list = $element.find(".review-entry-list")
@ -55,3 +59,12 @@ define [
# console.log "mousewheel", deltaY
scroller.scrollTop(scroller.scrollTop() + deltaY * 4)
e.preventDefault()
$scope.startAddingComment = () ->
$scope.commentState.adding = true
$scope.$broadcast "comment:select_line"
$scope.submitComment = () ->
$scope.commentState.adding = false
console.log "ADDING COMMENT", $scope.commentState.content
$scope.$broadcast "comment:add", $scope.commentState.content