Folder.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class="flex flex-col">
  3. <div class="flex items-center group">
  4. <span
  5. class="cursor-pointer flex px-4 justify-center items-center"
  6. @click="toggleShowChildren()"
  7. >
  8. <SmartIcon
  9. class="svg-icons"
  10. :class="{ 'text-green-500': isSelected }"
  11. :name="getCollectionIcon"
  12. />
  13. </span>
  14. <span
  15. class="
  16. cursor-pointer
  17. flex flex-1
  18. min-w-0
  19. py-2
  20. pr-2
  21. transition
  22. group-hover:text-secondaryDark
  23. "
  24. @click="toggleShowChildren()"
  25. >
  26. <span class="truncate">
  27. {{ folder.name ? folder.name : folder.title }}
  28. </span>
  29. </span>
  30. <div class="flex">
  31. <ButtonSecondary
  32. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  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. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  42. ref="options"
  43. interactive
  44. trigger="click"
  45. theme="popover"
  46. arrow
  47. >
  48. <template #trigger>
  49. <ButtonSecondary
  50. v-tippy="{ theme: 'tooltip' }"
  51. :title="$t('action.more')"
  52. svg="more-vertical"
  53. />
  54. </template>
  55. <SmartItem
  56. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  57. svg="folder-plus"
  58. :label="$t('folder.new')"
  59. @click.native="
  60. () => {
  61. $emit('add-folder', { folder, path: folderPath })
  62. $refs.options.tippy().hide()
  63. }
  64. "
  65. />
  66. <SmartItem
  67. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  68. svg="edit"
  69. :label="$t('action.edit')"
  70. @click.native="
  71. () => {
  72. $emit('edit-folder', {
  73. folder,
  74. folderIndex,
  75. collectionIndex,
  76. folderPath: '',
  77. })
  78. $refs.options.tippy().hide()
  79. }
  80. "
  81. />
  82. <SmartItem
  83. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  84. svg="trash-2"
  85. color="red"
  86. :label="$t('action.delete')"
  87. @click.native="
  88. () => {
  89. confirmRemove = true
  90. $refs.options.tippy().hide()
  91. }
  92. "
  93. />
  94. </tippy>
  95. </span>
  96. </div>
  97. </div>
  98. <div v-if="showChildren || isFiltered" class="flex">
  99. <div
  100. class="
  101. flex
  102. w-1
  103. transform
  104. transition
  105. cursor-nsResize
  106. ml-5.5
  107. bg-dividerLight
  108. hover:scale-x-125 hover:bg-dividerDark
  109. "
  110. @click="toggleShowChildren()"
  111. ></div>
  112. <div class="flex flex-col flex-1 truncate">
  113. <CollectionsTeamsFolder
  114. v-for="(subFolder, subFolderIndex) in folder.children"
  115. :key="`subFolder-${subFolderIndex}`"
  116. :folder="subFolder"
  117. :folder-index="subFolderIndex"
  118. :collection-index="collectionIndex"
  119. :doc="doc"
  120. :save-request="saveRequest"
  121. :collections-type="collectionsType"
  122. :folder-path="`${folderPath}/${subFolderIndex}`"
  123. :picked="picked"
  124. @add-folder="$emit('add-folder', $event)"
  125. @edit-folder="$emit('edit-folder', $event)"
  126. @edit-request="$emit('edit-request', $event)"
  127. @update-team-collections="$emit('update-team-collections')"
  128. @select="$emit('select', $event)"
  129. @expand-collection="expandCollection"
  130. @remove-request="removeRequest"
  131. />
  132. <CollectionsTeamsRequest
  133. v-for="(request, index) in folder.requests"
  134. :key="`request-${index}`"
  135. :request="request.request"
  136. :collection-index="collectionIndex"
  137. :folder-index="folderIndex"
  138. :folder-name="folder.name"
  139. :request-index="request.id"
  140. :doc="doc"
  141. :save-request="saveRequest"
  142. :collections-type="collectionsType"
  143. :picked="picked"
  144. @edit-request="$emit('edit-request', $event)"
  145. @select="$emit('select', $event)"
  146. @remove-request="removeRequest"
  147. />
  148. <div
  149. v-if="
  150. (folder.children == undefined || folder.children.length === 0) &&
  151. (folder.requests == undefined || folder.requests.length === 0)
  152. "
  153. class="
  154. flex flex-col
  155. text-secondaryLight
  156. p-4
  157. items-center
  158. justify-center
  159. "
  160. >
  161. <img
  162. :src="`/images/states/${$colorMode.value}/pack.svg`"
  163. loading="lazy"
  164. class="
  165. flex-col
  166. mb-4
  167. object-contain object-center
  168. h-16
  169. w-16
  170. inline-flex
  171. "
  172. :alt="$t('empty.folder')"
  173. />
  174. <span class="text-center">
  175. {{ $t("empty.folder") }}
  176. </span>
  177. </div>
  178. </div>
  179. </div>
  180. <SmartConfirmModal
  181. :show="confirmRemove"
  182. :title="$t('confirm.remove_folder')"
  183. @hide-modal="confirmRemove = false"
  184. @resolve="removeFolder"
  185. />
  186. </div>
  187. </template>
  188. <script>
  189. import { defineComponent } from "@nuxtjs/composition-api"
  190. import * as teamUtils from "~/helpers/teams/utils"
  191. export default defineComponent({
  192. name: "Folder",
  193. props: {
  194. folder: { type: Object, default: () => {} },
  195. folderIndex: { type: Number, default: null },
  196. collectionIndex: { type: Number, default: null },
  197. folderPath: { type: String, default: null },
  198. doc: Boolean,
  199. saveRequest: Boolean,
  200. isFiltered: Boolean,
  201. collectionsType: { type: Object, default: () => {} },
  202. picked: { type: Object, default: () => {} },
  203. },
  204. data() {
  205. return {
  206. showChildren: false,
  207. confirmRemove: false,
  208. prevCursor: "",
  209. cursor: "",
  210. }
  211. },
  212. computed: {
  213. isSelected() {
  214. return (
  215. this.picked &&
  216. this.picked.pickedType === "teams-folder" &&
  217. this.picked.folderID === this.folder.id
  218. )
  219. },
  220. getCollectionIcon() {
  221. if (this.isSelected) return "check-circle"
  222. else if (!this.showChildren && !this.isFiltered) return "folder"
  223. else if (this.showChildren || this.isFiltered) return "folder-minus"
  224. else return "folder"
  225. },
  226. },
  227. methods: {
  228. toggleShowChildren() {
  229. if (this.$props.saveRequest)
  230. this.$emit("select", {
  231. picked: {
  232. pickedType: "teams-folder",
  233. folderID: this.folder.id,
  234. },
  235. })
  236. this.$emit("expand-collection", this.$props.folder.id)
  237. this.showChildren = !this.showChildren
  238. },
  239. removeFolder() {
  240. if (this.collectionsType.selectedTeam.myRole !== "VIEWER") {
  241. // Cancel pick if picked collection folder was deleted
  242. if (
  243. this.picked &&
  244. this.picked.pickedType === "teams-folder" &&
  245. this.picked.folderID === this.folder.id
  246. ) {
  247. this.$emit("select", { picked: null })
  248. }
  249. teamUtils
  250. .deleteCollection(this.$apollo, this.folder.id)
  251. .then(() => {
  252. this.$toast.success(this.$t("state.deleted"), {
  253. icon: "delete",
  254. })
  255. this.$emit("update-team-collections")
  256. })
  257. .catch((e) => {
  258. this.$toast.error(this.$t("error.something_went_wrong"), {
  259. icon: "error_outline",
  260. })
  261. console.error(e)
  262. })
  263. this.$emit("update-team-collections")
  264. }
  265. },
  266. expandCollection(collectionID) {
  267. this.$emit("expand-collection", collectionID)
  268. },
  269. removeRequest({ collectionIndex, folderName, requestIndex }) {
  270. this.$emit("remove-request", {
  271. collectionIndex,
  272. folderName,
  273. requestIndex,
  274. })
  275. },
  276. },
  277. })
  278. </script>