Folder.vue 6.6 KB

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