2020-06-23 04:45:38 -04:00
|
|
|
import _ from 'lodash'
|
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-06-23 04:45:38 -04:00
|
|
|
export default App.directive('resolvedCommentsDropdown', () => ({
|
2020-05-19 05:02:56 -04:00
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: 'resolvedCommentsDropdownTemplate',
|
|
|
|
scope: {
|
|
|
|
entries: '=',
|
|
|
|
threads: '=',
|
|
|
|
resolvedIds: '=',
|
|
|
|
docs: '=',
|
|
|
|
permissions: '=',
|
|
|
|
onOpen: '&',
|
|
|
|
onUnresolve: '&',
|
|
|
|
onDelete: '&',
|
2021-04-27 03:52:58 -04:00
|
|
|
isLoading: '=',
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
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 }
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
scope.toggleOpenState = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
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
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
scope.handleUnresolve = function (threadId) {
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.onUnresolve({ threadId })
|
|
|
|
return (scope.resolvedComments = scope.resolvedComments.filter(
|
|
|
|
c => c.threadId !== threadId
|
|
|
|
))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
scope.handleDelete = function (entryId, docId, threadId) {
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.onDelete({ entryId, docId, threadId })
|
|
|
|
return (scope.resolvedComments = scope.resolvedComments.filter(
|
|
|
|
c => c.threadId !== threadId
|
|
|
|
))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const getDocNameById = function (docId) {
|
2020-05-19 05:02:56 -04:00
|
|
|
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
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return (filterResolvedComments = function () {
|
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
|
|
|
return (() => {
|
|
|
|
const result = []
|
2021-10-26 04:08:56 -04:00
|
|
|
for (const docId in scope.entries) {
|
|
|
|
const docEntries = scope.entries[docId]
|
2020-05-19 05:02:56 -04:00
|
|
|
result.push(
|
|
|
|
(() => {
|
|
|
|
const result1 = []
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const entryId in docEntries) {
|
2020-05-19 05:02:56 -04:00
|
|
|
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
|
|
|
|
})()
|
|
|
|
})
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}))
|