Collection.vue 7.1 KB

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