2016-10-12 12:27:20 -04:00
|
|
|
define [
|
|
|
|
"base",
|
|
|
|
"utils/EventEmitter"
|
2016-11-09 11:23:08 -05:00
|
|
|
"ide/colors/ColorManager"
|
2016-11-15 10:48:12 -05:00
|
|
|
"ide/review-panel/ChangesTracker"
|
|
|
|
], (App, EventEmitter, ColorManager, ChangesTracker) ->
|
2016-11-14 06:47:36 -05:00
|
|
|
App.controller "ReviewPanelController", ($scope, $element, ide, $timeout) ->
|
2016-11-17 07:02:45 -05:00
|
|
|
$reviewPanelEl = $element.find "#review-panel"
|
|
|
|
|
2016-11-16 07:31:47 -05:00
|
|
|
$scope.SubViews =
|
|
|
|
CUR_FILE : "cur_file"
|
|
|
|
OVERVIEW : "overview"
|
|
|
|
|
2016-10-12 12:27:20 -04:00
|
|
|
$scope.reviewPanel =
|
|
|
|
entries: {}
|
2016-11-08 11:43:01 -05:00
|
|
|
trackNewChanges: false
|
2016-11-15 10:04:29 -05:00
|
|
|
hasEntries: false
|
2016-11-16 07:31:47 -05:00
|
|
|
subView: $scope.SubViews.CUR_FILE
|
2016-11-17 09:57:11 -05:00
|
|
|
openSubView: $scope.SubViews.CUR_FILE
|
2016-11-15 10:04:29 -05:00
|
|
|
|
2016-11-09 09:50:58 -05:00
|
|
|
$scope.commentState =
|
|
|
|
adding: false
|
|
|
|
content: ""
|
2016-11-15 10:48:12 -05:00
|
|
|
|
2016-11-17 05:40:08 -05:00
|
|
|
$scope.reviewPanelEventsBridge = new EventEmitter()
|
|
|
|
|
2016-11-17 09:29:35 -05:00
|
|
|
scrollbar = {}
|
2016-11-17 07:02:45 -05:00
|
|
|
$scope.reviewPanelEventsBridge.on "aceScrollbarVisibilityChanged", (isVisible, scrollbarWidth) ->
|
2016-11-17 09:29:35 -05:00
|
|
|
scrollbar = {isVisible, scrollbarWidth}
|
|
|
|
updateScrollbar()
|
|
|
|
|
|
|
|
updateScrollbar = () ->
|
|
|
|
if scrollbar.isVisible and $scope.reviewPanel.subView == $scope.SubViews.CUR_FILE
|
|
|
|
$reviewPanelEl.css "right", "#{ scrollbar.scrollbarWidth }px"
|
2016-11-17 07:02:45 -05:00
|
|
|
else
|
|
|
|
$reviewPanelEl.css "right", "0"
|
2016-11-17 09:29:35 -05:00
|
|
|
|
|
|
|
$scope.$watch "reviewPanel.subView", (subView) ->
|
|
|
|
return if !subView?
|
|
|
|
updateScrollbar()
|
|
|
|
if subView == $scope.SubViews.CUR_FILE
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-17 09:57:11 -05:00
|
|
|
|
|
|
|
$scope.$watch "ui.reviewPanelOpen", (open) ->
|
|
|
|
console.log "ui.reviewPanelOpen", open
|
|
|
|
return if !open?
|
|
|
|
if !open
|
|
|
|
# Always show current file when not open, but save current state
|
|
|
|
$scope.reviewPanel.openSubView = $scope.reviewPanel.subView
|
|
|
|
$scope.reviewPanel.subView = $scope.SubViews.CUR_FILE
|
|
|
|
else
|
|
|
|
# Reset back to what we had when previously open
|
|
|
|
$scope.reviewPanel.subView = $scope.reviewPanel.openSubView
|
|
|
|
|
2016-11-17 07:02:45 -05:00
|
|
|
|
2016-11-15 10:48:12 -05:00
|
|
|
changesTrackers = {}
|
|
|
|
|
|
|
|
$scope.$watch "editor.open_doc_id", (open_doc_id) ->
|
|
|
|
return if !open_doc_id?
|
|
|
|
changesTrackers[open_doc_id] ?= new ChangesTracker()
|
|
|
|
$scope.reviewPanel.changesTracker = changesTrackers[open_doc_id]
|
|
|
|
|
2016-11-11 11:10:26 -05:00
|
|
|
# TODO Just for prototyping purposes; remove afterwards.
|
|
|
|
mockedUserId = '12345abc'
|
|
|
|
|
2016-11-16 12:17:50 -05:00
|
|
|
$scope.$watch (() ->
|
|
|
|
entries = $scope.reviewPanel.entries[$scope.editor.open_doc_id] or {}
|
|
|
|
Object.keys(entries).length
|
|
|
|
), (nEntries) ->
|
|
|
|
$scope.reviewPanel.hasEntries = nEntries > 0 and $scope.trackChangesFeatureFlag
|
2016-11-16 11:28:01 -05:00
|
|
|
|
|
|
|
$scope.$watch "ui.reviewPanelOpen", (reviewPanelOpen) ->
|
|
|
|
return if !reviewPanelOpen?
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "review-panel:toggle"
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-09 09:50:58 -05:00
|
|
|
|
2016-11-10 05:52:09 -05:00
|
|
|
$scope.acceptChange = (entry_id) ->
|
|
|
|
$scope.$broadcast "change:accept", entry_id
|
|
|
|
|
|
|
|
$scope.rejectChange = (entry_id) ->
|
|
|
|
$scope.$broadcast "change:reject", entry_id
|
|
|
|
|
2016-11-09 10:25:41 -05:00
|
|
|
$scope.startNewComment = () ->
|
2016-11-16 10:47:05 -05:00
|
|
|
# $scope.commentState.adding = true
|
2016-11-09 09:50:58 -05:00
|
|
|
$scope.$broadcast "comment:select_line"
|
2016-11-16 11:03:06 -05:00
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-09 09:50:58 -05:00
|
|
|
|
2016-11-16 10:47:05 -05:00
|
|
|
$scope.submitNewComment = (content) ->
|
|
|
|
console.log(content)
|
|
|
|
# $scope.commentState.adding = false
|
|
|
|
$scope.$broadcast "comment:add", content
|
|
|
|
# $scope.commentState.content = ""
|
2016-11-16 11:03:06 -05:00
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-09 10:25:41 -05:00
|
|
|
|
2016-11-09 10:51:40 -05:00
|
|
|
$scope.cancelNewComment = (entry) ->
|
2016-11-16 10:47:05 -05:00
|
|
|
# $scope.commentState.adding = false
|
|
|
|
# $scope.commentState.content = ""
|
2016-11-16 11:03:06 -05:00
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-09 10:51:40 -05:00
|
|
|
|
2016-11-09 10:25:41 -05:00
|
|
|
$scope.startReply = (entry) ->
|
|
|
|
entry.replying = true
|
2016-11-16 11:03:06 -05:00
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-11 05:51:32 -05:00
|
|
|
|
2016-11-16 10:12:58 -05:00
|
|
|
# $scope.handleCommentReplyKeyPress = (ev, entry) ->
|
|
|
|
# if ev.keyCode == 13 and !ev.shiftKey and !ev.ctrlKey and !ev.metaKey
|
|
|
|
# ev.preventDefault()
|
|
|
|
# ev.target.blur()
|
|
|
|
# $scope.submitReply(entry)
|
2016-11-11 05:51:32 -05:00
|
|
|
|
2016-11-09 10:25:41 -05:00
|
|
|
$scope.submitReply = (entry) ->
|
|
|
|
entry.thread.push {
|
|
|
|
content: entry.replyContent
|
|
|
|
ts: new Date()
|
|
|
|
user_id: window.user_id
|
|
|
|
}
|
|
|
|
entry.replyContent = ""
|
2016-11-09 10:46:47 -05:00
|
|
|
entry.replying = false
|
2016-11-14 06:47:36 -05:00
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-11 11:10:26 -05:00
|
|
|
# TODO Just for prototyping purposes; remove afterwards
|
|
|
|
window.setTimeout((() ->
|
|
|
|
$scope.$applyAsync(() -> submitMockedReply(entry))
|
|
|
|
), 1000 * 2)
|
|
|
|
|
|
|
|
# TODO Just for prototyping purposes; remove afterwards.
|
|
|
|
submitMockedReply = (entry) ->
|
|
|
|
entry.thread.push {
|
|
|
|
content: 'Lorem ipsum dolor sit amet'
|
|
|
|
ts: new Date()
|
|
|
|
user_id: mockedUserId
|
|
|
|
}
|
|
|
|
entry.replyContent = ""
|
|
|
|
entry.replying = false
|
2016-11-14 06:47:36 -05:00
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "review-panel:layout"
|
2016-11-09 10:51:40 -05:00
|
|
|
|
|
|
|
$scope.cancelReply = (entry) ->
|
|
|
|
entry.replying = false
|
|
|
|
entry.replyContent = ""
|
2016-11-09 11:23:08 -05:00
|
|
|
$scope.$broadcast "review-panel:layout"
|
|
|
|
|
2016-11-16 07:31:47 -05:00
|
|
|
$scope.setSubView = (subView) ->
|
|
|
|
$scope.reviewPanel.subView = subView
|
|
|
|
|
2016-11-09 11:34:23 -05:00
|
|
|
# TODO: Eventually we need to get this from the server, and update it
|
|
|
|
# when we get an id we don't know. This'll do for client side testing
|
2016-11-09 11:23:08 -05:00
|
|
|
refreshUsers = () ->
|
|
|
|
$scope.users = {}
|
2016-11-11 11:10:26 -05:00
|
|
|
# TODO Just for prototyping purposes; remove afterwards.
|
|
|
|
$scope.users[mockedUserId] = {
|
|
|
|
email: "gerald.butler@gmail.com"
|
|
|
|
name: "Gerald Butler"
|
|
|
|
isSelf: false
|
|
|
|
hue: 70
|
|
|
|
avatar_text: "G"
|
|
|
|
}
|
|
|
|
|
2016-11-09 11:23:08 -05:00
|
|
|
for member in $scope.project.members.concat($scope.project.owner)
|
2016-11-09 11:34:23 -05:00
|
|
|
if member._id == window.user_id
|
|
|
|
name = "You"
|
2016-11-11 11:10:26 -05:00
|
|
|
isSelf = true
|
2016-11-09 11:34:23 -05:00
|
|
|
else
|
|
|
|
name = "#{member.first_name} #{member.last_name}"
|
2016-11-11 11:10:26 -05:00
|
|
|
isSelf = false
|
|
|
|
|
2016-11-09 11:23:08 -05:00
|
|
|
$scope.users[member._id] = {
|
|
|
|
email: member.email
|
2016-11-09 11:34:23 -05:00
|
|
|
name: name
|
2016-11-11 11:10:26 -05:00
|
|
|
isSelf: isSelf
|
2016-11-09 11:23:08 -05:00
|
|
|
hue: ColorManager.getHueForUserId(member._id)
|
|
|
|
avatar_text: [member.first_name, member.last_name].filter((n) -> n?).map((n) -> n[0]).join ""
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.$watch "project.members", (members) ->
|
|
|
|
return if !members?
|
|
|
|
refreshUsers()
|