Collection.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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-tippy="{ theme: 'tooltip' }"
  31. svg="folder-plus"
  32. :title="$t('folder.new')"
  33. class="group-hover:inline-flex hidden"
  34. @click.native="
  35. $emit('add-folder', {
  36. path: `${collectionIndex}`,
  37. })
  38. "
  39. />
  40. <span>
  41. <tippy
  42. ref="options"
  43. interactive
  44. trigger="click"
  45. theme="popover"
  46. arrow
  47. >
  48. <template #trigger>
  49. <ButtonSecondary
  50. v-tippy="{ theme: 'tooltip' }"
  51. :title="$t('action.more')"
  52. svg="more-vertical"
  53. />
  54. </template>
  55. <SmartItem
  56. svg="folder-plus"
  57. :label="`${$t('folder.new')}`"
  58. @click.native="
  59. () => {
  60. $emit('add-folder', {
  61. path: `${collectionIndex}`,
  62. })
  63. $refs.options.tippy().hide()
  64. }
  65. "
  66. />
  67. <SmartItem
  68. svg="edit"
  69. :label="`${$t('action.edit')}`"
  70. @click.native="
  71. () => {
  72. $emit('edit-collection')
  73. $refs.options.tippy().hide()
  74. }
  75. "
  76. />
  77. <SmartItem
  78. svg="trash-2"
  79. color="red"
  80. :label="`${$t('action.delete')}`"
  81. @click.native="
  82. () => {
  83. confirmRemove = true
  84. $refs.options.tippy().hide()
  85. }
  86. "
  87. />
  88. </tippy>
  89. </span>
  90. </div>
  91. </div>
  92. <div v-if="showChildren || isFiltered" class="flex">
  93. <div
  94. class="flex w-1 transform transition cursor-nsResize ml-5.5 bg-dividerLight hover:scale-x-125 hover:bg-dividerDark"
  95. @click="toggleShowChildren()"
  96. ></div>
  97. <div class="flex flex-col flex-1 truncate">
  98. <CollectionsGraphqlFolder
  99. v-for="(folder, index) in collection.folders"
  100. :key="`folder-${String(index)}`"
  101. :picked="picked"
  102. :saving-mode="savingMode"
  103. :folder="folder"
  104. :folder-index="index"
  105. :folder-path="`${collectionIndex}/${String(index)}`"
  106. :collection-index="collectionIndex"
  107. :doc="doc"
  108. :is-filtered="isFiltered"
  109. @add-folder="$emit('add-folder', $event)"
  110. @edit-folder="$emit('edit-folder', $event)"
  111. @edit-request="$emit('edit-request', $event)"
  112. @duplicate-request="$emit('duplicate-request', $event)"
  113. @select="$emit('select', $event)"
  114. />
  115. <CollectionsGraphqlRequest
  116. v-for="(request, index) in collection.requests"
  117. :key="`request-${String(index)}`"
  118. :picked="picked"
  119. :saving-mode="savingMode"
  120. :request="request"
  121. :collection-index="collectionIndex"
  122. :folder-index="-1"
  123. :folder-name="collection.name"
  124. :folder-path="`${collectionIndex}`"
  125. :request-index="index"
  126. :doc="doc"
  127. @edit-request="$emit('edit-request', $event)"
  128. @duplicate-request="$emit('duplicate-request', $event)"
  129. @select="$emit('select', $event)"
  130. />
  131. <div
  132. v-if="
  133. collection.folders.length === 0 && collection.requests.length === 0
  134. "
  135. class="text-secondaryLight flex flex-col items-center justify-center p-4"
  136. >
  137. <img
  138. :src="`/images/states/${$colorMode.value}/pack.svg`"
  139. loading="lazy"
  140. class="inline-flex flex-col object-contain object-center w-16 h-16 mb-4"
  141. :alt="$t('empty.collection')"
  142. />
  143. <span class="text-center">
  144. {{ $t("empty.collection") }}
  145. </span>
  146. </div>
  147. </div>
  148. </div>
  149. <SmartConfirmModal
  150. :show="confirmRemove"
  151. :title="`${$t('confirm.remove_collection')}`"
  152. @hide-modal="confirmRemove = false"
  153. @resolve="removeCollection"
  154. />
  155. </div>
  156. </template>
  157. <script lang="ts">
  158. import { defineComponent } from "@nuxtjs/composition-api"
  159. import {
  160. removeGraphqlCollection,
  161. moveGraphqlRequest,
  162. } from "~/newstore/collections"
  163. export default defineComponent({
  164. props: {
  165. picked: { type: Object, default: null },
  166. // Whether the viewing context is related to picking (activates 'select' events)
  167. savingMode: { type: Boolean, default: false },
  168. collectionIndex: { type: Number, default: null },
  169. collection: { type: Object, default: () => {} },
  170. doc: Boolean,
  171. isFiltered: Boolean,
  172. },
  173. data() {
  174. return {
  175. showChildren: false,
  176. dragging: false,
  177. selectedFolder: {},
  178. confirmRemove: false,
  179. }
  180. },
  181. computed: {
  182. isSelected(): boolean {
  183. return (
  184. this.picked &&
  185. this.picked.pickedType === "gql-my-collection" &&
  186. this.picked.collectionIndex === this.collectionIndex
  187. )
  188. },
  189. getCollectionIcon() {
  190. if (this.isSelected) return "check-circle"
  191. else if (!this.showChildren && !this.isFiltered) return "folder"
  192. else if (this.showChildren || this.isFiltered) return "folder-minus"
  193. else return "folder"
  194. },
  195. },
  196. methods: {
  197. pick() {
  198. this.$emit("select", {
  199. picked: {
  200. pickedType: "gql-my-collection",
  201. collectionIndex: this.collectionIndex,
  202. },
  203. })
  204. },
  205. toggleShowChildren() {
  206. if (this.savingMode) {
  207. this.pick()
  208. }
  209. this.showChildren = !this.showChildren
  210. },
  211. removeCollection() {
  212. // Cancel pick if picked collection is deleted
  213. if (
  214. this.picked &&
  215. this.picked.pickedType === "gql-my-collection" &&
  216. this.picked.collectionIndex === this.collectionIndex
  217. ) {
  218. this.$emit("select", { picked: null })
  219. }
  220. removeGraphqlCollection(this.collectionIndex)
  221. this.$toast.success(`${this.$t("state.deleted")}`)
  222. },
  223. dropEvent({ dataTransfer }: any) {
  224. this.dragging = !this.dragging
  225. const folderPath = dataTransfer.getData("folderPath")
  226. const requestIndex = dataTransfer.getData("requestIndex")
  227. moveGraphqlRequest(folderPath, requestIndex, `${this.collectionIndex}`)
  228. },
  229. },
  230. })
  231. </script>