Collection.vue 7.7 KB

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