Collection.vue 8.1 KB

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