Collection.vue 7.3 KB

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