Folder.vue 7.8 KB

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