Folder.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. () => {
  66. $emit('add-folder', { folder, path: folderPath })
  67. $refs.options.tippy().hide()
  68. }
  69. "
  70. />
  71. <SmartItem
  72. svg="edit"
  73. :label="$t('action.edit')"
  74. @click.native="
  75. () => {
  76. $emit('edit-folder', {
  77. folder,
  78. folderIndex,
  79. collectionIndex,
  80. folderPath,
  81. })
  82. $refs.options.tippy().hide()
  83. }
  84. "
  85. />
  86. <SmartItem
  87. svg="trash-2"
  88. color="red"
  89. :label="$t('action.delete')"
  90. @click.native="
  91. () => {
  92. confirmRemove = true
  93. $refs.options.tippy().hide()
  94. }
  95. "
  96. />
  97. </tippy>
  98. </span>
  99. </div>
  100. </div>
  101. <div v-if="showChildren || isFiltered" class="flex">
  102. <div
  103. class="
  104. flex
  105. w-1
  106. transform
  107. transition
  108. cursor-nsResize
  109. ml-5.5
  110. bg-dividerLight
  111. hover:scale-x-125 hover:bg-dividerDark
  112. "
  113. @click="toggleShowChildren()"
  114. ></div>
  115. <div class="flex flex-col flex-1 truncate">
  116. <CollectionsMyFolder
  117. v-for="(subFolder, subFolderIndex) in folder.folders"
  118. :key="`subFolder-${subFolderIndex}`"
  119. :folder="subFolder"
  120. :folder-index="subFolderIndex"
  121. :collection-index="collectionIndex"
  122. :doc="doc"
  123. :save-request="saveRequest"
  124. :collections-type="collectionsType"
  125. :folder-path="`${folderPath}/${subFolderIndex}`"
  126. :picked="picked"
  127. @add-folder="$emit('add-folder', $event)"
  128. @edit-folder="$emit('edit-folder', $event)"
  129. @edit-request="$emit('edit-request', $event)"
  130. @duplicate-request="$emit('duplicate-request', $event)"
  131. @update-team-collections="$emit('update-team-collections')"
  132. @select="$emit('select', $event)"
  133. @remove-request="removeRequest"
  134. />
  135. <CollectionsMyRequest
  136. v-for="(request, index) in folder.requests"
  137. :key="`request-${index}`"
  138. :request="request"
  139. :collection-index="collectionIndex"
  140. :folder-index="folderIndex"
  141. :folder-name="folder.name"
  142. :folder-path="folderPath"
  143. :request-index="index"
  144. :doc="doc"
  145. :picked="picked"
  146. :save-request="saveRequest"
  147. :collections-type="collectionsType"
  148. @edit-request="$emit('edit-request', $event)"
  149. @duplicate-request="$emit('duplicate-request', $event)"
  150. @select="$emit('select', $event)"
  151. @remove-request="removeRequest"
  152. />
  153. <div
  154. v-if="
  155. folder.folders &&
  156. folder.folders.length === 0 &&
  157. folder.requests &&
  158. folder.requests.length === 0
  159. "
  160. class="
  161. flex flex-col
  162. text-secondaryLight
  163. p-4
  164. items-center
  165. justify-center
  166. "
  167. >
  168. <img
  169. :src="`/images/states/${$colorMode.value}/pack.svg`"
  170. loading="lazy"
  171. class="
  172. flex-col
  173. mb-4
  174. object-contain object-center
  175. h-16
  176. w-16
  177. inline-flex
  178. "
  179. :alt="$t('empty.folder')"
  180. />
  181. <span class="text-center">
  182. {{ $t("empty.folder") }}
  183. </span>
  184. </div>
  185. </div>
  186. </div>
  187. <SmartConfirmModal
  188. :show="confirmRemove"
  189. :title="$t('confirm.remove_folder')"
  190. @hide-modal="confirmRemove = false"
  191. @resolve="removeFolder"
  192. />
  193. </div>
  194. </template>
  195. <script>
  196. import { defineComponent } from "@nuxtjs/composition-api"
  197. import {
  198. removeRESTFolder,
  199. removeRESTRequest,
  200. moveRESTRequest,
  201. } from "~/newstore/collections"
  202. export default defineComponent({
  203. name: "Folder",
  204. props: {
  205. folder: { type: Object, default: () => {} },
  206. folderIndex: { type: Number, default: null },
  207. collectionIndex: { type: Number, default: null },
  208. folderPath: { type: String, default: null },
  209. doc: Boolean,
  210. saveRequest: Boolean,
  211. isFiltered: Boolean,
  212. collectionsType: { type: Object, default: () => {} },
  213. picked: { type: Object, default: () => {} },
  214. },
  215. data() {
  216. return {
  217. showChildren: false,
  218. dragging: false,
  219. confirmRemove: false,
  220. prevCursor: "",
  221. cursor: "",
  222. }
  223. },
  224. computed: {
  225. isSelected() {
  226. return (
  227. this.picked &&
  228. this.picked.pickedType === "my-folder" &&
  229. this.picked.folderPath === this.folderPath
  230. )
  231. },
  232. getCollectionIcon() {
  233. if (this.isSelected) return "check-circle"
  234. else if (!this.showChildren && !this.isFiltered) return "folder"
  235. else if (this.showChildren || this.isFiltered) return "folder-minus"
  236. else return "folder"
  237. },
  238. },
  239. methods: {
  240. toggleShowChildren() {
  241. if (this.$props.saveRequest)
  242. this.$emit("select", {
  243. picked: {
  244. pickedType: "my-folder",
  245. collectionIndex: this.collectionIndex,
  246. folderName: this.folder.name,
  247. folderPath: this.folderPath,
  248. },
  249. })
  250. this.showChildren = !this.showChildren
  251. },
  252. removeFolder() {
  253. // TODO: Bubble it up ?
  254. // Cancel pick if picked folder was deleted
  255. if (
  256. this.picked &&
  257. this.picked.pickedType === "my-folder" &&
  258. this.picked.folderPath === this.folderPath
  259. ) {
  260. this.$emit("select", { picked: null })
  261. }
  262. removeRESTFolder(this.folderPath)
  263. this.$toast.success(this.$t("state.deleted"), {
  264. icon: "delete",
  265. })
  266. },
  267. dropEvent({ dataTransfer }) {
  268. this.dragging = !this.dragging
  269. const folderPath = dataTransfer.getData("folderPath")
  270. const requestIndex = dataTransfer.getData("requestIndex")
  271. moveRESTRequest(folderPath, requestIndex, this.folderPath)
  272. },
  273. removeRequest({ requestIndex }) {
  274. // TODO: Bubble it up to root ?
  275. // Cancel pick if the picked item is being deleted
  276. if (
  277. this.picked &&
  278. this.picked.pickedType === "my-request" &&
  279. this.picked.folderPath === this.folderPath &&
  280. this.picked.requestIndex === requestIndex
  281. ) {
  282. this.$emit("select", { picked: null })
  283. }
  284. removeRESTRequest(this.folderPath, requestIndex)
  285. },
  286. },
  287. })
  288. </script>