2017-01-05 12:15:27 -05:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2017-01-10 07:16:58 -05:00
|
|
|
App.directive "resolvedCommentsDropdown", (_) ->
|
2017-01-05 12:15:27 -05:00
|
|
|
restrict: "E"
|
|
|
|
templateUrl: "resolvedCommentsDropdownTemplate"
|
|
|
|
scope:
|
2017-01-09 09:59:01 -05:00
|
|
|
entries : "="
|
|
|
|
threads : "="
|
2017-01-10 11:29:27 -05:00
|
|
|
resolvedIds : "="
|
2017-01-09 09:59:01 -05:00
|
|
|
docs : "="
|
2017-01-12 05:52:39 -05:00
|
|
|
permissions: "="
|
2017-01-09 09:59:01 -05:00
|
|
|
onOpen : "&"
|
2017-01-09 12:22:01 -05:00
|
|
|
onUnresolve : "&"
|
2017-01-10 05:33:54 -05:00
|
|
|
onDelete : "&"
|
2017-01-09 09:59:01 -05:00
|
|
|
isLoading : "="
|
|
|
|
|
2017-01-05 12:15:27 -05:00
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
scope.state =
|
|
|
|
isOpen: false
|
|
|
|
|
2017-01-09 09:59:01 -05:00
|
|
|
scope.toggleOpenState = () ->
|
|
|
|
scope.state.isOpen = !scope.state.isOpen
|
|
|
|
if (scope.state.isOpen)
|
|
|
|
scope.onOpen()
|
2017-01-16 10:55:14 -05:00
|
|
|
.then () -> filterResolvedComments()
|
2017-01-09 09:59:01 -05:00
|
|
|
|
2017-01-10 07:16:58 -05:00
|
|
|
scope.resolvedComments = []
|
2017-01-05 12:15:27 -05:00
|
|
|
|
2017-01-09 12:22:01 -05:00
|
|
|
scope.handleUnresolve = (threadId) ->
|
|
|
|
scope.onUnresolve({ threadId })
|
|
|
|
|
2017-01-10 06:23:06 -05:00
|
|
|
scope.handleDelete = (entryId, threadId) ->
|
|
|
|
scope.onDelete({ entryId, threadId })
|
2017-01-10 05:33:54 -05:00
|
|
|
|
2017-01-10 07:16:58 -05:00
|
|
|
getDocNameById = (docId) ->
|
2017-01-12 07:44:54 -05:00
|
|
|
doc = _.find(scope.docs, (doc) -> doc.doc.id == docId)
|
2017-01-10 07:16:58 -05:00
|
|
|
if doc?
|
|
|
|
return doc.path
|
|
|
|
else
|
|
|
|
return null
|
2017-01-10 05:33:54 -05:00
|
|
|
|
2017-01-05 12:15:27 -05:00
|
|
|
filterResolvedComments = () ->
|
2017-01-10 07:16:58 -05:00
|
|
|
scope.resolvedComments = []
|
2017-01-05 12:15:27 -05:00
|
|
|
|
2017-01-10 07:16:58 -05:00
|
|
|
for docId, docEntries of scope.entries
|
|
|
|
for entryId, entry of docEntries
|
2017-01-06 10:24:33 -05:00
|
|
|
if entry.type == "comment" and scope.threads[entry.thread_id]?.resolved?
|
2017-01-10 07:16:58 -05:00
|
|
|
resolvedComment = angular.copy scope.threads[entry.thread_id]
|
|
|
|
|
|
|
|
resolvedComment.content = entry.content
|
|
|
|
resolvedComment.threadId = entry.thread_id
|
|
|
|
resolvedComment.entryId = entryId
|
|
|
|
resolvedComment.docId = docId
|
|
|
|
resolvedComment.docName = getDocNameById(docId)
|
|
|
|
|
|
|
|
scope.resolvedComments.push(resolvedComment)
|