Folder.vue 8.0 KB

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