resolvedCommentsDropdown.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import _ from 'lodash'
  2. /* eslint-disable
  3. max-len,
  4. no-return-assign,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS205: Consider reworking code to avoid use of IIFEs
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. import App from '../../../base'
  16. export default App.directive('resolvedCommentsDropdown', () => ({
  17. restrict: 'E',
  18. templateUrl: 'resolvedCommentsDropdownTemplate',
  19. scope: {
  20. entries: '=',
  21. threads: '=',
  22. resolvedIds: '=',
  23. docs: '=',
  24. permissions: '=',
  25. onOpen: '&',
  26. onUnresolve: '&',
  27. onDelete: '&',
  28. isLoading: '=',
  29. },
  30. link(scope, element, attrs) {
  31. let filterResolvedComments
  32. scope.state = { isOpen: false }
  33. scope.toggleOpenState = function () {
  34. scope.state.isOpen = !scope.state.isOpen
  35. if (scope.state.isOpen) {
  36. return scope.onOpen().then(() => filterResolvedComments())
  37. }
  38. }
  39. scope.resolvedComments = []
  40. scope.handleUnresolve = function (threadId) {
  41. scope.onUnresolve({ threadId })
  42. return (scope.resolvedComments = scope.resolvedComments.filter(
  43. c => c.threadId !== threadId
  44. ))
  45. }
  46. scope.handleDelete = function (entryId, docId, threadId) {
  47. scope.onDelete({ entryId, docId, threadId })
  48. return (scope.resolvedComments = scope.resolvedComments.filter(
  49. c => c.threadId !== threadId
  50. ))
  51. }
  52. const getDocNameById = function (docId) {
  53. const doc = _.find(scope.docs, doc => doc.doc.id === docId)
  54. if (doc != null) {
  55. return doc.path
  56. } else {
  57. return null
  58. }
  59. }
  60. return (filterResolvedComments = function () {
  61. scope.resolvedComments = []
  62. return (() => {
  63. const result = []
  64. for (const docId in scope.entries) {
  65. const docEntries = scope.entries[docId]
  66. result.push(
  67. (() => {
  68. const result1 = []
  69. for (const entryId in docEntries) {
  70. const entry = docEntries[entryId]
  71. if (
  72. entry.type === 'comment' &&
  73. (scope.threads[entry.thread_id] != null
  74. ? scope.threads[entry.thread_id].resolved
  75. : undefined) != null
  76. ) {
  77. const resolvedComment = angular.copy(
  78. scope.threads[entry.thread_id]
  79. )
  80. resolvedComment.content = entry.content
  81. resolvedComment.threadId = entry.thread_id
  82. resolvedComment.entryId = entryId
  83. resolvedComment.docId = docId
  84. resolvedComment.docName = getDocNameById(docId)
  85. result1.push(scope.resolvedComments.push(resolvedComment))
  86. } else {
  87. result1.push(undefined)
  88. }
  89. }
  90. return result1
  91. })()
  92. )
  93. }
  94. return result
  95. })()
  96. })
  97. },
  98. }))