Collection.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. $emit('add-folder', {
  68. path: `${collectionIndex}`,
  69. })
  70. $refs.options.tippy().hide()
  71. "
  72. />
  73. <SmartItem
  74. svg="edit"
  75. :label="$t('action.edit')"
  76. @click.native="
  77. $emit('edit-collection')
  78. $refs.options.tippy().hide()
  79. "
  80. />
  81. <SmartItem
  82. svg="trash-2"
  83. color="red"
  84. :label="$t('action.delete')"
  85. @click.native="
  86. confirmRemove = true
  87. $refs.options.tippy().hide()
  88. "
  89. />
  90. </tippy>
  91. </span>
  92. </div>
  93. </div>
  94. <div v-if="showChildren || isFiltered">
  95. <CollectionsGraphqlFolder
  96. v-for="(folder, index) in collection.folders"
  97. :key="`folder-${index}`"
  98. class="border-l border-dividerLight ml-6"
  99. :picked="picked"
  100. :saving-mode="savingMode"
  101. :folder="folder"
  102. :folder-index="index"
  103. :folder-path="`${collectionIndex}/${index}`"
  104. :collection-index="collectionIndex"
  105. :doc="doc"
  106. :is-filtered="isFiltered"
  107. @add-folder="$emit('add-folder', $event)"
  108. @edit-folder="$emit('edit-folder', $event)"
  109. @edit-request="$emit('edit-request', $event)"
  110. @select="$emit('select', $event)"
  111. />
  112. <CollectionsGraphqlRequest
  113. v-for="(request, index) in collection.requests"
  114. :key="`request-${index}`"
  115. class="border-l border-dividerLight ml-6"
  116. :picked="picked"
  117. :saving-mode="savingMode"
  118. :request="request"
  119. :collection-index="collectionIndex"
  120. :folder-index="-1"
  121. :folder-name="collection.name"
  122. :folder-path="`${collectionIndex}`"
  123. :request-index="index"
  124. :doc="doc"
  125. @edit-request="$emit('edit-request', $event)"
  126. @select="$emit('select', $event)"
  127. />
  128. <div
  129. v-if="
  130. collection.folders.length === 0 && collection.requests.length === 0
  131. "
  132. class="
  133. border-l border-dividerLight
  134. flex flex-col
  135. text-secondaryLight
  136. ml-6
  137. p-4
  138. items-center
  139. justify-center
  140. "
  141. >
  142. <i class="opacity-75 pb-2 material-icons">folder_open</i>
  143. <span class="text-center">
  144. {{ $t("empty.collection") }}
  145. </span>
  146. </div>
  147. </div>
  148. <SmartConfirmModal
  149. :show="confirmRemove"
  150. :title="$t('confirm.remove_collection')"
  151. @hide-modal="confirmRemove = false"
  152. @resolve="removeCollection"
  153. />
  154. </div>
  155. </template>
  156. <script lang="ts">
  157. import { defineComponent } from "@nuxtjs/composition-api"
  158. import {
  159. removeGraphqlCollection,
  160. moveGraphqlRequest,
  161. } from "~/newstore/collections"
  162. export default defineComponent({
  163. props: {
  164. picked: { type: Object, default: null },
  165. // Whether the viewing context is related to picking (activates 'select' events)
  166. savingMode: { type: Boolean, default: false },
  167. collectionIndex: { type: Number, default: null },
  168. collection: { type: Object, default: () => {} },
  169. doc: Boolean,
  170. isFiltered: Boolean,
  171. },
  172. data() {
  173. return {
  174. showChildren: false,
  175. dragging: false,
  176. selectedFolder: {},
  177. confirmRemove: false,
  178. }
  179. },
  180. computed: {
  181. isSelected(): boolean {
  182. return (
  183. this.picked &&
  184. this.picked.pickedType === "gql-my-collection" &&
  185. this.picked.collectionIndex === this.collectionIndex
  186. )
  187. },
  188. getCollectionIcon() {
  189. if (this.isSelected) return "check-circle"
  190. else if (!this.showChildren && !this.isFiltered) return "folder"
  191. else if (this.showChildren || this.isFiltered) return "folder-minus"
  192. else return "folder"
  193. },
  194. },
  195. methods: {
  196. pick() {
  197. this.$emit("select", {
  198. picked: {
  199. pickedType: "gql-my-collection",
  200. collectionIndex: this.collectionIndex,
  201. },
  202. })
  203. },
  204. toggleShowChildren() {
  205. if (this.savingMode) {
  206. this.pick()
  207. }
  208. this.showChildren = !this.showChildren
  209. },
  210. removeCollection() {
  211. // Cancel pick if picked collection is deleted
  212. if (
  213. this.picked &&
  214. this.picked.pickedType === "gql-my-collection" &&
  215. this.picked.collectionIndex === this.collectionIndex
  216. ) {
  217. this.$emit("select", { picked: null })
  218. }
  219. removeGraphqlCollection(this.collectionIndex)
  220. this.$toast.success(this.$t("state.deleted").toString(), {
  221. icon: "delete",
  222. })
  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>