Collection.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="flex flex-col">
  3. <div class="group flex items-center">
  4. <span
  5. class="flex items-center justify-center px-4 cursor-pointer"
  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="group-hover:text-secondaryDark flex flex-1 min-w-0 py-2 pr-2 transition cursor-pointer"
  16. @click="toggleShowChildren()"
  17. >
  18. <span class="truncate"> {{ collection.title }} </span>
  19. </span>
  20. <div class="flex">
  21. <ButtonSecondary
  22. v-if="doc && !selected"
  23. v-tippy="{ theme: 'tooltip' }"
  24. :title="$t('import.title')"
  25. svg="circle"
  26. color="green"
  27. @click.native="$emit('select-collection')"
  28. />
  29. <ButtonSecondary
  30. v-if="doc && selected"
  31. v-tippy="{ theme: 'tooltip' }"
  32. :title="$t('action.remove')"
  33. svg="check-circle"
  34. color="green"
  35. @click.native="$emit('unselect-collection')"
  36. />
  37. <ButtonSecondary
  38. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  39. v-tippy="{ theme: 'tooltip' }"
  40. svg="folder-plus"
  41. :title="$t('folder.new')"
  42. class="group-hover:inline-flex hidden"
  43. @click.native="
  44. $emit('add-folder', {
  45. folder: collection,
  46. path: `${collectionIndex}`,
  47. })
  48. "
  49. />
  50. <span>
  51. <tippy
  52. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  53. ref="options"
  54. interactive
  55. trigger="click"
  56. theme="popover"
  57. arrow
  58. >
  59. <template #trigger>
  60. <ButtonSecondary
  61. v-tippy="{ theme: 'tooltip' }"
  62. :title="$t('action.more')"
  63. svg="more-vertical"
  64. />
  65. </template>
  66. <SmartItem
  67. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  68. svg="folder-plus"
  69. :label="$t('folder.new')"
  70. @click.native="
  71. () => {
  72. $emit('add-folder', {
  73. folder: collection,
  74. path: `${collectionIndex}`,
  75. })
  76. $refs.options.tippy().hide()
  77. }
  78. "
  79. />
  80. <SmartItem
  81. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  82. svg="edit"
  83. :label="$t('action.edit')"
  84. @click.native="
  85. () => {
  86. $emit('edit-collection')
  87. $refs.options.tippy().hide()
  88. }
  89. "
  90. />
  91. <SmartItem
  92. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  93. svg="trash-2"
  94. color="red"
  95. :label="$t('action.delete')"
  96. @click.native="
  97. () => {
  98. confirmRemove = true
  99. $refs.options.tippy().hide()
  100. }
  101. "
  102. />
  103. </tippy>
  104. </span>
  105. </div>
  106. </div>
  107. <div v-if="showChildren || isFiltered" class="flex">
  108. <div
  109. class="flex w-1 transform transition cursor-nsResize ml-5.5 bg-dividerLight hover:scale-x-125 hover:bg-dividerDark"
  110. @click="toggleShowChildren()"
  111. ></div>
  112. <div class="flex flex-col flex-1 truncate">
  113. <CollectionsTeamsFolder
  114. v-for="(folder, index) in collection.children"
  115. :key="`folder-${index}`"
  116. :folder="folder"
  117. :folder-index="index"
  118. :folder-path="`${collectionIndex}/${index}`"
  119. :collection-index="collectionIndex"
  120. :doc="doc"
  121. :save-request="saveRequest"
  122. :collections-type="collectionsType"
  123. :is-filtered="isFiltered"
  124. :picked="picked"
  125. @add-folder="$emit('add-folder', $event)"
  126. @edit-folder="$emit('edit-folder', $event)"
  127. @edit-request="$emit('edit-request', $event)"
  128. @select="$emit('select', $event)"
  129. @expand-collection="expandCollection"
  130. @remove-request="removeRequest"
  131. />
  132. <CollectionsTeamsRequest
  133. v-for="(request, index) in collection.requests"
  134. :key="`request-${index}`"
  135. :request="request.request"
  136. :collection-index="collectionIndex"
  137. :folder-index="-1"
  138. :folder-name="collection.name"
  139. :request-index="request.id"
  140. :doc="doc"
  141. :save-request="saveRequest"
  142. :collections-type="collectionsType"
  143. :picked="picked"
  144. @edit-request="editRequest($event)"
  145. @select="$emit('select', $event)"
  146. @remove-request="removeRequest"
  147. />
  148. <div
  149. v-if="
  150. (collection.children == undefined ||
  151. collection.children.length === 0) &&
  152. (collection.requests == undefined ||
  153. collection.requests.length === 0)
  154. "
  155. class="text-secondaryLight flex flex-col items-center justify-center p-4"
  156. >
  157. <img
  158. :src="`/images/states/${$colorMode.value}/pack.svg`"
  159. loading="lazy"
  160. class="inline-flex flex-col object-contain object-center w-16 h-16 mb-4"
  161. :alt="$t('empty.collection')"
  162. />
  163. <span class="text-center">
  164. {{ $t("empty.collection") }}
  165. </span>
  166. </div>
  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>