Collection.vue 7.9 KB

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