Collection.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. () => {
  80. $emit('add-folder', {
  81. folder: collection,
  82. path: `${collectionIndex}`,
  83. })
  84. $refs.options.tippy().hide()
  85. }
  86. "
  87. />
  88. <SmartItem
  89. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  90. svg="edit"
  91. :label="$t('action.edit')"
  92. @click.native="
  93. () => {
  94. $emit('edit-collection')
  95. $refs.options.tippy().hide()
  96. }
  97. "
  98. />
  99. <SmartItem
  100. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  101. svg="trash-2"
  102. color="red"
  103. :label="$t('action.delete')"
  104. @click.native="
  105. () => {
  106. confirmRemove = true
  107. $refs.options.tippy().hide()
  108. }
  109. "
  110. />
  111. </tippy>
  112. </span>
  113. </div>
  114. </div>
  115. <div v-if="showChildren || isFiltered" class="flex">
  116. <div
  117. class="
  118. flex
  119. w-1
  120. transform
  121. transition
  122. cursor-nsResize
  123. ml-5.5
  124. bg-dividerLight
  125. hover:scale-x-125 hover:bg-dividerDark
  126. "
  127. @click="toggleShowChildren()"
  128. ></div>
  129. <div class="flex flex-col flex-1 truncate">
  130. <CollectionsTeamsFolder
  131. v-for="(folder, index) in collection.children"
  132. :key="`folder-${index}`"
  133. :folder="folder"
  134. :folder-index="index"
  135. :folder-path="`${collectionIndex}/${index}`"
  136. :collection-index="collectionIndex"
  137. :doc="doc"
  138. :save-request="saveRequest"
  139. :collections-type="collectionsType"
  140. :is-filtered="isFiltered"
  141. :picked="picked"
  142. @add-folder="$emit('add-folder', $event)"
  143. @edit-folder="$emit('edit-folder', $event)"
  144. @edit-request="$emit('edit-request', $event)"
  145. @select="$emit('select', $event)"
  146. @expand-collection="expandCollection"
  147. @remove-request="removeRequest"
  148. />
  149. <CollectionsTeamsRequest
  150. v-for="(request, index) in collection.requests"
  151. :key="`request-${index}`"
  152. :request="request.request"
  153. :collection-index="collectionIndex"
  154. :folder-index="-1"
  155. :folder-name="collection.name"
  156. :request-index="request.id"
  157. :doc="doc"
  158. :save-request="saveRequest"
  159. :collections-type="collectionsType"
  160. :picked="picked"
  161. @edit-request="editRequest($event)"
  162. @select="$emit('select', $event)"
  163. @remove-request="removeRequest"
  164. />
  165. <div
  166. v-if="
  167. (collection.children == undefined ||
  168. collection.children.length === 0) &&
  169. (collection.requests == undefined ||
  170. collection.requests.length === 0)
  171. "
  172. class="
  173. flex flex-col
  174. text-secondaryLight
  175. p-4
  176. items-center
  177. justify-center
  178. "
  179. >
  180. <img
  181. :src="`/images/states/${$colorMode.value}/pack.svg`"
  182. loading="lazy"
  183. class="
  184. flex-col
  185. mb-4
  186. object-contain object-center
  187. h-16
  188. w-16
  189. inline-flex
  190. "
  191. :alt="$t('empty.collection')"
  192. />
  193. <span class="text-center">
  194. {{ $t("empty.collection") }}
  195. </span>
  196. </div>
  197. </div>
  198. </div>
  199. <SmartConfirmModal
  200. :show="confirmRemove"
  201. :title="$t('confirm.remove_collection')"
  202. @hide-modal="confirmRemove = false"
  203. @resolve="removeCollection"
  204. />
  205. </div>
  206. </template>
  207. <script>
  208. import { defineComponent } from "@nuxtjs/composition-api"
  209. export default defineComponent({
  210. props: {
  211. collectionIndex: { type: Number, default: null },
  212. collection: { type: Object, default: () => {} },
  213. doc: Boolean,
  214. isFiltered: Boolean,
  215. selected: Boolean,
  216. saveRequest: Boolean,
  217. collectionsType: { type: Object, default: () => {} },
  218. picked: { type: Object, default: () => {} },
  219. },
  220. data() {
  221. return {
  222. showChildren: false,
  223. selectedFolder: {},
  224. confirmRemove: false,
  225. prevCursor: "",
  226. cursor: "",
  227. pageNo: 0,
  228. }
  229. },
  230. computed: {
  231. isSelected() {
  232. return (
  233. this.picked &&
  234. this.picked.pickedType === "teams-collection" &&
  235. this.picked.collectionID === this.collection.id
  236. )
  237. },
  238. getCollectionIcon() {
  239. if (this.isSelected) return "check-circle"
  240. else if (!this.showChildren && !this.isFiltered) return "folder"
  241. else if (this.showChildren || this.isFiltered) return "folder-minus"
  242. else return "folder"
  243. },
  244. },
  245. methods: {
  246. editRequest(event) {
  247. this.$emit("edit-request", event)
  248. if (this.$props.saveRequest)
  249. this.$emit("select", {
  250. picked: {
  251. pickedType: "teams-collection",
  252. collectionID: this.collection.id,
  253. },
  254. })
  255. },
  256. toggleShowChildren() {
  257. if (this.$props.saveRequest)
  258. this.$emit("select", {
  259. picked: {
  260. pickedType: "teams-collection",
  261. collectionID: this.collection.id,
  262. },
  263. })
  264. this.$emit("expand-collection", this.collection.id)
  265. this.showChildren = !this.showChildren
  266. },
  267. removeCollection() {
  268. this.$emit("remove-collection", {
  269. collectionsType: this.collectionsType,
  270. collectionIndex: this.collectionIndex,
  271. collectionID: this.collection.id,
  272. })
  273. },
  274. expandCollection(collectionID) {
  275. this.$emit("expand-collection", collectionID)
  276. },
  277. removeRequest({ collectionIndex, folderName, requestIndex }) {
  278. this.$emit("remove-request", {
  279. collectionIndex,
  280. folderName,
  281. requestIndex,
  282. })
  283. },
  284. },
  285. })
  286. </script>