Folder.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. $emit('add-folder', { folder, path: folderPath })
  61. $refs.options.tippy().hide()
  62. "
  63. />
  64. <SmartItem
  65. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  66. svg="edit"
  67. :label="$t('action.edit')"
  68. @click.native="
  69. $emit('edit-folder', {
  70. folder,
  71. folderIndex,
  72. collectionIndex,
  73. folderPath: '',
  74. })
  75. $refs.options.tippy().hide()
  76. "
  77. />
  78. <SmartItem
  79. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  80. svg="trash-2"
  81. color="red"
  82. :label="$t('action.delete')"
  83. @click.native="
  84. confirmRemove = true
  85. $refs.options.tippy().hide()
  86. "
  87. />
  88. </tippy>
  89. </span>
  90. </div>
  91. </div>
  92. <div v-if="showChildren || isFiltered">
  93. <CollectionsTeamsFolder
  94. v-for="(subFolder, subFolderIndex) in folder.children"
  95. :key="`subFolder-${subFolderIndex}`"
  96. class="border-l border-dividerLight ml-6"
  97. :folder="subFolder"
  98. :folder-index="subFolderIndex"
  99. :collection-index="collectionIndex"
  100. :doc="doc"
  101. :save-request="saveRequest"
  102. :collections-type="collectionsType"
  103. :folder-path="`${folderPath}/${subFolderIndex}`"
  104. :picked="picked"
  105. @add-folder="$emit('add-folder', $event)"
  106. @edit-folder="$emit('edit-folder', $event)"
  107. @edit-request="$emit('edit-request', $event)"
  108. @update-team-collections="$emit('update-team-collections')"
  109. @select="$emit('select', $event)"
  110. @expand-collection="expandCollection"
  111. @remove-request="removeRequest"
  112. />
  113. <CollectionsTeamsRequest
  114. v-for="(request, index) in folder.requests"
  115. :key="`request-${index}`"
  116. class="border-l border-dividerLight ml-6"
  117. :request="request.request"
  118. :collection-index="collectionIndex"
  119. :folder-index="folderIndex"
  120. :folder-name="folder.name"
  121. :request-index="request.id"
  122. :doc="doc"
  123. :save-request="saveRequest"
  124. :collections-type="collectionsType"
  125. :picked="picked"
  126. @edit-request="$emit('edit-request', $event)"
  127. @select="$emit('select', $event)"
  128. @remove-request="removeRequest"
  129. />
  130. <div
  131. v-if="
  132. (folder.children == undefined || folder.children.length === 0) &&
  133. (folder.requests == undefined || folder.requests.length === 0)
  134. "
  135. class="
  136. border-l border-dividerLight
  137. flex flex-col
  138. text-secondaryLight
  139. ml-6
  140. p-4
  141. items-center
  142. justify-center
  143. "
  144. >
  145. <i class="opacity-75 pb-2 material-icons">folder_open</i>
  146. <span class="text-center">
  147. {{ $t("empty.folder") }}
  148. </span>
  149. </div>
  150. </div>
  151. <SmartConfirmModal
  152. :show="confirmRemove"
  153. :title="$t('confirm.remove_folder')"
  154. @hide-modal="confirmRemove = false"
  155. @resolve="removeFolder"
  156. />
  157. </div>
  158. </template>
  159. <script>
  160. import { defineComponent } from "@nuxtjs/composition-api"
  161. import * as teamUtils from "~/helpers/teams/utils"
  162. export default defineComponent({
  163. name: "Folder",
  164. props: {
  165. folder: { type: Object, default: () => {} },
  166. folderIndex: { type: Number, default: null },
  167. collectionIndex: { type: Number, default: null },
  168. folderPath: { type: String, default: null },
  169. doc: Boolean,
  170. saveRequest: Boolean,
  171. isFiltered: Boolean,
  172. collectionsType: { type: Object, default: () => {} },
  173. picked: { type: Object, default: () => {} },
  174. },
  175. data() {
  176. return {
  177. showChildren: false,
  178. confirmRemove: false,
  179. prevCursor: "",
  180. cursor: "",
  181. }
  182. },
  183. computed: {
  184. isSelected() {
  185. return (
  186. this.picked &&
  187. this.picked.pickedType === "teams-folder" &&
  188. this.picked.folderID === this.folder.id
  189. )
  190. },
  191. getCollectionIcon() {
  192. if (this.isSelected) return "check-circle"
  193. else if (!this.showChildren && !this.isFiltered) return "folder"
  194. else if (this.showChildren || this.isFiltered) return "folder-minus"
  195. else return "folder"
  196. },
  197. },
  198. methods: {
  199. toggleShowChildren() {
  200. if (this.$props.saveRequest)
  201. this.$emit("select", {
  202. picked: {
  203. pickedType: "teams-folder",
  204. folderID: this.folder.id,
  205. },
  206. })
  207. this.$emit("expand-collection", this.$props.folder.id)
  208. this.showChildren = !this.showChildren
  209. },
  210. removeFolder() {
  211. if (this.collectionsType.selectedTeam.myRole !== "VIEWER") {
  212. // Cancel pick if picked collection folder was deleted
  213. if (
  214. this.picked &&
  215. this.picked.pickedType === "teams-folder" &&
  216. this.picked.folderID === this.folder.id
  217. ) {
  218. this.$emit("select", { picked: null })
  219. }
  220. teamUtils
  221. .deleteCollection(this.$apollo, this.folder.id)
  222. .then(() => {
  223. this.$toast.success(this.$t("state.deleted"), {
  224. icon: "delete",
  225. })
  226. this.$emit("update-team-collections")
  227. })
  228. .catch((e) => {
  229. this.$toast.error(this.$t("error.something_went_wrong"), {
  230. icon: "error_outline",
  231. })
  232. console.error(e)
  233. })
  234. this.$emit("update-team-collections")
  235. }
  236. },
  237. expandCollection(collectionID) {
  238. this.$emit("expand-collection", collectionID)
  239. },
  240. removeRequest({ collectionIndex, folderName, requestIndex }) {
  241. this.$emit("remove-request", {
  242. collectionIndex,
  243. folderName,
  244. requestIndex,
  245. })
  246. },
  247. },
  248. })
  249. </script>