Collection.vue 7.3 KB

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