Collection.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="flex flex-col">
  3. <div class="flex items-center group">
  4. <span
  5. class="cursor-pointer flex px-4 justify-center items-center"
  6. @click="toggleShowChildren()"
  7. >
  8. <SmartIcon
  9. class="svg-icons"
  10. :class="{ 'text-green-500': isSelected }"
  11. :name="getCollectionIcon"
  12. />
  13. </span>
  14. <span
  15. class="
  16. cursor-pointer
  17. flex flex-1
  18. min-w-0
  19. py-2
  20. pr-2
  21. transition
  22. group-hover:text-secondaryDark
  23. "
  24. @click="toggleShowChildren()"
  25. >
  26. <span class="truncate"> {{ collection.title }} </span>
  27. </span>
  28. <div class="flex">
  29. <ButtonSecondary
  30. v-if="doc && !selected"
  31. v-tippy="{ theme: 'tooltip' }"
  32. :title="$t('import.title')"
  33. svg="circle"
  34. color="green"
  35. @click.native="$emit('select-collection')"
  36. />
  37. <ButtonSecondary
  38. v-if="doc && selected"
  39. v-tippy="{ theme: 'tooltip' }"
  40. :title="$t('action.remove')"
  41. svg="check-circle"
  42. color="green"
  43. @click.native="$emit('unselect-collection')"
  44. />
  45. <ButtonSecondary
  46. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  47. v-tippy="{ theme: 'tooltip' }"
  48. svg="folder-plus"
  49. :title="$t('folder.new')"
  50. class="hidden group-hover:inline-flex"
  51. @click.native="
  52. $emit('add-folder', {
  53. folder: collection,
  54. path: `${collectionIndex}`,
  55. })
  56. "
  57. />
  58. <span>
  59. <tippy
  60. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  61. ref="options"
  62. interactive
  63. trigger="click"
  64. theme="popover"
  65. arrow
  66. >
  67. <template #trigger>
  68. <ButtonSecondary
  69. v-tippy="{ theme: 'tooltip' }"
  70. :title="$t('action.more')"
  71. svg="more-vertical"
  72. />
  73. </template>
  74. <SmartItem
  75. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  76. svg="folder-plus"
  77. :label="$t('folder.new')"
  78. @click.native="
  79. $emit('add-folder', {
  80. folder: collection,
  81. path: `${collectionIndex}`,
  82. })
  83. $refs.options.tippy().hide()
  84. "
  85. />
  86. <SmartItem
  87. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  88. svg="edit"
  89. :label="$t('action.edit')"
  90. @click.native="
  91. $emit('edit-collection')
  92. $refs.options.tippy().hide()
  93. "
  94. />
  95. <SmartItem
  96. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  97. svg="trash-2"
  98. color="red"
  99. :label="$t('action.delete')"
  100. @click.native="
  101. confirmRemove = true
  102. $refs.options.tippy().hide()
  103. "
  104. />
  105. </tippy>
  106. </span>
  107. </div>
  108. </div>
  109. <div v-if="showChildren || isFiltered">
  110. <CollectionsTeamsFolder
  111. v-for="(folder, index) in collection.children"
  112. :key="`folder-${index}`"
  113. class="border-l border-dividerLight ml-6"
  114. :folder="folder"
  115. :folder-index="index"
  116. :folder-path="`${collectionIndex}/${index}`"
  117. :collection-index="collectionIndex"
  118. :doc="doc"
  119. :save-request="saveRequest"
  120. :collections-type="collectionsType"
  121. :is-filtered="isFiltered"
  122. :picked="picked"
  123. @add-folder="$emit('add-folder', $event)"
  124. @edit-folder="$emit('edit-folder', $event)"
  125. @edit-request="$emit('edit-request', $event)"
  126. @select="$emit('select', $event)"
  127. @expand-collection="expandCollection"
  128. @remove-request="removeRequest"
  129. />
  130. <CollectionsTeamsRequest
  131. v-for="(request, index) in collection.requests"
  132. :key="`request-${index}`"
  133. class="border-l border-dividerLight ml-6"
  134. :request="request.request"
  135. :collection-index="collectionIndex"
  136. :folder-index="-1"
  137. :folder-name="collection.name"
  138. :request-index="request.id"
  139. :doc="doc"
  140. :save-request="saveRequest"
  141. :collections-type="collectionsType"
  142. :picked="picked"
  143. @edit-request="editRequest($event)"
  144. @select="$emit('select', $event)"
  145. @remove-request="removeRequest"
  146. />
  147. <div
  148. v-if="
  149. (collection.children == undefined ||
  150. collection.children.length === 0) &&
  151. (collection.requests == undefined || collection.requests.length === 0)
  152. "
  153. class="
  154. border-l border-dividerLight
  155. flex flex-col
  156. text-secondaryLight
  157. ml-6
  158. p-4
  159. items-center
  160. justify-center
  161. "
  162. >
  163. <i class="opacity-75 pb-2 material-icons">folder_open</i>
  164. <span class="text-center">
  165. {{ $t("empty.collection") }}
  166. </span>
  167. </div>
  168. </div>
  169. <SmartConfirmModal
  170. :show="confirmRemove"
  171. :title="$t('confirm.remove_collection')"
  172. @hide-modal="confirmRemove = false"
  173. @resolve="removeCollection"
  174. />
  175. </div>
  176. </template>
  177. <script>
  178. import { defineComponent } from "@nuxtjs/composition-api"
  179. export default defineComponent({
  180. props: {
  181. collectionIndex: { type: Number, default: null },
  182. collection: { type: Object, default: () => {} },
  183. doc: Boolean,
  184. isFiltered: Boolean,
  185. selected: Boolean,
  186. saveRequest: Boolean,
  187. collectionsType: { type: Object, default: () => {} },
  188. picked: { type: Object, default: () => {} },
  189. },
  190. data() {
  191. return {
  192. showChildren: false,
  193. selectedFolder: {},
  194. confirmRemove: false,
  195. prevCursor: "",
  196. cursor: "",
  197. pageNo: 0,
  198. }
  199. },
  200. computed: {
  201. isSelected() {
  202. return (
  203. this.picked &&
  204. this.picked.pickedType === "teams-collection" &&
  205. this.picked.collectionID === this.collection.id
  206. )
  207. },
  208. getCollectionIcon() {
  209. if (this.isSelected) return "check-circle"
  210. else if (!this.showChildren && !this.isFiltered) return "folder"
  211. else if (this.showChildren || this.isFiltered) return "folder-minus"
  212. else return "folder"
  213. },
  214. },
  215. methods: {
  216. editRequest(event) {
  217. this.$emit("edit-request", event)
  218. if (this.$props.saveRequest)
  219. this.$emit("select", {
  220. picked: {
  221. pickedType: "teams-collection",
  222. collectionID: this.collection.id,
  223. },
  224. })
  225. },
  226. toggleShowChildren() {
  227. if (this.$props.saveRequest)
  228. this.$emit("select", {
  229. picked: {
  230. pickedType: "teams-collection",
  231. collectionID: this.collection.id,
  232. },
  233. })
  234. this.$emit("expand-collection", this.collection.id)
  235. this.showChildren = !this.showChildren
  236. },
  237. removeCollection() {
  238. this.$emit("remove-collection", {
  239. collectionsType: this.collectionsType,
  240. collectionIndex: this.collectionIndex,
  241. collectionID: this.collection.id,
  242. })
  243. },
  244. expandCollection(collectionID) {
  245. this.$emit("expand-collection", collectionID)
  246. },
  247. removeRequest({ collectionIndex, folderName, requestIndex }) {
  248. this.$emit("remove-request", {
  249. collectionIndex,
  250. folderName,
  251. requestIndex,
  252. })
  253. },
  254. },
  255. })
  256. </script>