overleaf/services/web/public/coffee/ide/review-panel/directives/resolvedCommentsDropdown.coffee

59 lines
1.5 KiB
CoffeeScript
Raw Normal View History

define [
"base"
], (App) ->
App.directive "resolvedCommentsDropdown", (_) ->
restrict: "E"
templateUrl: "resolvedCommentsDropdownTemplate"
scope:
entries : "="
threads : "="
resolvedIds : "="
docs : "="
permissions: "="
onOpen : "&"
2017-01-09 12:22:01 -05:00
onUnresolve : "&"
2017-01-10 05:33:54 -05:00
onDelete : "&"
isLoading : "="
link: (scope, element, attrs) ->
scope.state =
isOpen: false
scope.toggleOpenState = () ->
scope.state.isOpen = !scope.state.isOpen
if (scope.state.isOpen)
scope.onOpen()
.then () -> filterResolvedComments()
scope.resolvedComments = []
2017-01-09 12:22:01 -05:00
scope.handleUnresolve = (threadId) ->
scope.onUnresolve({ threadId })
scope.resolvedComments = scope.resolvedComments.filter (c) -> c.threadId != threadId
2017-01-09 12:22:01 -05:00
scope.handleDelete = (entryId, threadId) ->
scope.onDelete({ entryId, threadId })
2017-01-10 05:33:54 -05:00
getDocNameById = (docId) ->
doc = _.find(scope.docs, (doc) -> doc.doc.id == docId)
if doc?
return doc.path
else
return null
2017-01-10 05:33:54 -05:00
filterResolvedComments = () ->
scope.resolvedComments = []
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?
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)