2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS205: Consider reworking code to avoid use of IIFEs
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
export default App.directive('resolvedCommentsDropdown', _ => ({
|
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: 'resolvedCommentsDropdownTemplate',
|
|
|
|
scope: {
|
|
|
|
entries: '=',
|
|
|
|
threads: '=',
|
|
|
|
resolvedIds: '=',
|
|
|
|
docs: '=',
|
|
|
|
permissions: '=',
|
|
|
|
onOpen: '&',
|
|
|
|
onUnresolve: '&',
|
|
|
|
onDelete: '&',
|
|
|
|
isLoading: '='
|
|
|
|
},
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
link(scope, element, attrs) {
|
|
|
|
let filterResolvedComments
|
|
|
|
scope.state = { isOpen: false }
|
|
|
|
|
|
|
|
scope.toggleOpenState = function() {
|
|
|
|
scope.state.isOpen = !scope.state.isOpen
|
|
|
|
if (scope.state.isOpen) {
|
|
|
|
return scope.onOpen().then(() => filterResolvedComments())
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.resolvedComments = []
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.handleUnresolve = function(threadId) {
|
|
|
|
scope.onUnresolve({ threadId })
|
|
|
|
return (scope.resolvedComments = scope.resolvedComments.filter(
|
|
|
|
c => c.threadId !== threadId
|
|
|
|
))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.handleDelete = function(entryId, docId, threadId) {
|
|
|
|
scope.onDelete({ entryId, docId, threadId })
|
|
|
|
return (scope.resolvedComments = scope.resolvedComments.filter(
|
|
|
|
c => c.threadId !== threadId
|
|
|
|
))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const getDocNameById = function(docId) {
|
|
|
|
const doc = _.find(scope.docs, doc => doc.doc.id === docId)
|
|
|
|
if (doc != null) {
|
|
|
|
return doc.path
|
|
|
|
} else {
|
|
|
|
return null
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return (filterResolvedComments = function() {
|
|
|
|
scope.resolvedComments = []
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return (() => {
|
|
|
|
const result = []
|
|
|
|
for (var docId in scope.entries) {
|
|
|
|
var docEntries = scope.entries[docId]
|
|
|
|
result.push(
|
|
|
|
(() => {
|
|
|
|
const result1 = []
|
|
|
|
for (let entryId in docEntries) {
|
|
|
|
const entry = docEntries[entryId]
|
|
|
|
if (
|
|
|
|
entry.type === 'comment' &&
|
|
|
|
(scope.threads[entry.thread_id] != null
|
|
|
|
? scope.threads[entry.thread_id].resolved
|
|
|
|
: undefined) != null
|
|
|
|
) {
|
|
|
|
const resolvedComment = angular.copy(
|
|
|
|
scope.threads[entry.thread_id]
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
resolvedComment.content = entry.content
|
|
|
|
resolvedComment.threadId = entry.thread_id
|
|
|
|
resolvedComment.entryId = entryId
|
|
|
|
resolvedComment.docId = docId
|
|
|
|
resolvedComment.docName = getDocNameById(docId)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
result1.push(scope.resolvedComments.push(resolvedComment))
|
|
|
|
} else {
|
|
|
|
result1.push(undefined)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
return result1
|
|
|
|
})()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
})()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}))
|