2016-10-12 12:27:20 -04:00
|
|
|
define [
|
|
|
|
"base",
|
|
|
|
"utils/EventEmitter"
|
|
|
|
], (App, EventEmitter) ->
|
2016-10-13 09:22:23 -04:00
|
|
|
App.controller "ReviewPanelController", ($scope, $element, ide) ->
|
2016-10-12 12:27:20 -04:00
|
|
|
$scope.reviewPanel =
|
|
|
|
entries: {}
|
2016-11-08 11:43:01 -05:00
|
|
|
trackNewChanges: false
|
2016-11-09 09:50:58 -05:00
|
|
|
|
|
|
|
$scope.commentState =
|
|
|
|
adding: false
|
|
|
|
content: ""
|
2016-10-12 12:27:20 -04:00
|
|
|
|
|
|
|
scroller = $element.find(".review-panel-scroller")
|
|
|
|
list = $element.find(".review-entry-list")
|
|
|
|
|
2016-10-13 05:09:59 -04:00
|
|
|
# Use these to avoid unnecessary updates. Scrolling one
|
|
|
|
# panel causes us to scroll the other panel, but there's no
|
|
|
|
# need to trigger the event back to the original panel.
|
2016-10-12 12:27:20 -04:00
|
|
|
ignoreNextPanelEvent = false
|
|
|
|
ignoreNextAceEvent = false
|
|
|
|
|
2016-10-13 05:09:59 -04:00
|
|
|
$scope.scrollEvents = new EventEmitter()
|
|
|
|
|
|
|
|
scrollPanel = (scrollTop, height) ->
|
2016-10-12 12:27:20 -04:00
|
|
|
if ignoreNextAceEvent
|
|
|
|
ignoreNextAceEvent = false
|
|
|
|
else
|
|
|
|
ignoreNextPanelEvent = true
|
|
|
|
list.height(height)
|
|
|
|
scroller.scrollTop(scrollTop)
|
|
|
|
|
|
|
|
scrollAce = (e) ->
|
|
|
|
if ignoreNextPanelEvent
|
|
|
|
ignoreNextPanelEvent = false
|
|
|
|
else
|
|
|
|
ignoreNextAceEvent = true
|
|
|
|
$scope.scrollEvents.emit "scroll", e.target.scrollTop
|
2016-10-13 09:22:23 -04:00
|
|
|
|
|
|
|
$scope.$watch "ui.reviewPanelOpen", (reviewPanelOpen) ->
|
|
|
|
return if !reviewPanelOpen?
|
|
|
|
setTimeout () ->
|
|
|
|
$scope.$broadcast "reviewPanel:toggle"
|
|
|
|
if reviewPanelOpen
|
|
|
|
scroller.on "scroll", scrollAce
|
|
|
|
$scope.onScroll = scrollPanel # Passed into the editor directive for it to call
|
|
|
|
else
|
|
|
|
scroller.off "scroll"
|
|
|
|
$scope.onScroll = null
|
2016-10-13 05:09:59 -04:00
|
|
|
|
|
|
|
# If we listen for scroll events in the review panel natively, then with a Mac trackpad
|
|
|
|
# the scroll is very smooth (natively done I'd guess), but we don't get polled regularly
|
|
|
|
# enough to keep Ace in step, and it noticeably lags. If instead, we borrow the manual
|
|
|
|
# mousewheel/trackpad scrolling behaviour from Ace, and turn mousewheel events into
|
|
|
|
# scroll events ourselves, then it makes the review panel slightly less smooth (barely)
|
|
|
|
# noticeable, but keeps it perfectly in step with Ace.
|
2016-10-12 12:27:20 -04:00
|
|
|
ace.require("ace/lib/event").addMouseWheelListener scroller[0], (e) ->
|
|
|
|
deltaY = e.wheelY
|
|
|
|
# console.log "mousewheel", deltaY
|
|
|
|
scroller.scrollTop(scroller.scrollTop() + deltaY * 4)
|
2016-10-13 07:21:49 -04:00
|
|
|
e.preventDefault()
|
2016-11-09 09:50:58 -05:00
|
|
|
|
2016-11-09 10:25:41 -05:00
|
|
|
$scope.startNewComment = () ->
|
2016-11-09 09:50:58 -05:00
|
|
|
$scope.commentState.adding = true
|
|
|
|
$scope.$broadcast "comment:select_line"
|
|
|
|
|
2016-11-09 10:25:41 -05:00
|
|
|
$scope.submitNewComment = () ->
|
2016-11-09 09:50:58 -05:00
|
|
|
$scope.commentState.adding = false
|
2016-11-09 10:25:41 -05:00
|
|
|
$scope.$broadcast "comment:add", $scope.commentState.content
|
|
|
|
$scope.commentState.content = ""
|
|
|
|
|
|
|
|
$scope.startReply = (entry) ->
|
|
|
|
console.log "Start new reply"
|
|
|
|
entry.replying = true
|
|
|
|
|
|
|
|
$scope.submitReply = (entry) ->
|
|
|
|
entry.thread.push {
|
|
|
|
content: entry.replyContent
|
|
|
|
ts: new Date()
|
|
|
|
user_id: window.user_id
|
|
|
|
}
|
|
|
|
entry.replyContent = ""
|
|
|
|
entry.replying = false
|