Collection.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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"> {{ collection.title }} </span>
  27. </span>
  28. <div class="flex">
  29. <ButtonSecondary
  30. v-if="doc && !selected"
  31. v-tippy="{ theme: 'tooltip' }"
  32. :title="$t('import.title')"
  33. svg="circle"
  34. color="green"
  35. @click.native="$emit('select-collection')"
  36. />
  37. <ButtonSecondary
  38. v-if="doc && selected"
  39. v-tippy="{ theme: 'tooltip' }"
  40. :title="$t('action.remove')"
  41. svg="check-circle"
  42. color="green"
  43. @click.native="$emit('unselect-collection')"
  44. />
  45. <ButtonSecondary
  46. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  47. v-tippy="{ theme: 'tooltip' }"
  48. svg="folder-plus"
  49. :title="$t('folder.new')"
  50. class="hidden group-hover:inline-flex"
  51. @click.native="
  52. $emit('add-folder', {
  53. folder: collection,
  54. path: `${collectionIndex}`,
  55. })
  56. "
  57. />
  58. <span>
  59. <tippy
  60. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  61. ref="options"
  62. interactive
  63. trigger="click"
  64. theme="popover"
  65. arrow
  66. >
  67. <template #trigger>
  68. <ButtonSecondary
  69. v-tippy="{ theme: 'tooltip' }"
  70. :title="$t('action.more')"
  71. svg="more-vertical"
  72. />
  73. </template>
  74. <SmartItem
  75. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  76. svg="folder-plus"
  77. :label="$t('folder.new')"
  78. @click.native="
  79. () => {
  80. $emit('add-folder', {
  81. folder: collection,
  82. path: `${collectionIndex}`,
  83. })
  84. $refs.options.tippy().hide()
  85. }
  86. "
  87. />
  88. <SmartItem
  89. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  90. svg="edit"
  91. :label="$t('action.edit')"
  92. @click.native="
  93. () => {
  94. $emit('edit-collection')
  95. $refs.options.tippy().hide()
  96. }
  97. "
  98. />
  99. <SmartItem
  100. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  101. svg="trash-2"
  102. color="red"
  103. :label="$t('action.delete')"
  104. @click.native="
  105. () => {
  106. confirmRemove = true
  107. $refs.options.tippy().hide()
  108. }
  109. "
  110. />
  111. </tippy>
  112. </span>
  113. </div>
  114. </div>
  115. <div v-if="showChildren || isFiltered">
  116. <CollectionsTeamsFolder
  117. v-for="(folder, index) in collection.children"
  118. :key="`folder-${index}`"
  119. class="border-l border-dividerLight ml-6"
  120. :folder="folder"
  121. :folder-index="index"
  122. :folder-path="`${collectionIndex}/${index}`"
  123. :collection-index="collectionIndex"
  124. :doc="doc"
  125. :save-request="saveRequest"
  126. :collections-type="collectionsType"
  127. :is-filtered="isFiltered"
  128. :picked="picked"
  129. @add-folder="$emit('add-folder', $event)"
  130. @edit-folder="$emit('edit-folder', $event)"
  131. @edit-request="$emit('edit-request', $event)"
  132. @select="$emit('select', $event)"
  133. @expand-collection="expandCollection"
  134. @remove-request="removeRequest"
  135. />
  136. <CollectionsTeamsRequest
  137. v-for="(request, index) in collection.requests"
  138. :key="`request-${index}`"
  139. class="border-l border-dividerLight ml-6"
  140. :request="request.request"
  141. :collection-index="collectionIndex"
  142. :folder-index="-1"
  143. :folder-name="collection.name"
  144. :request-index="request.id"
  145. :doc="doc"
  146. :save-request="saveRequest"
  147. :collections-type="collectionsType"
  148. :picked="picked"
  149. @edit-request="editRequest($event)"
  150. @select="$emit('select', $event)"
  151. @remove-request="removeRequest"
  152. />
  153. <div
  154. v-if="
  155. (collection.children == undefined ||
  156. collection.children.length === 0) &&
  157. (collection.requests == undefined || collection.requests.length === 0)
  158. "
  159. class="
  160. border-l border-dividerLight
  161. flex flex-col
  162. text-secondaryLight
  163. ml-6
  164. p-4
  165. items-center
  166. justify-center
  167. "
  168. >
  169. <i class="opacity-75 pb-2 material-icons">folder_open</i>
  170. <span class="text-center">
  171. {{ $t("empty.collection") }}
  172. </span>
  173. </div>
  174. </div>
  175. <SmartConfirmModal
  176. :show="confirmRemove"
  177. :title="$t('confirm.remove_collection')"
  178. @hide-modal="confirmRemove = false"
  179. @resolve="removeCollection"
  180. />
  181. </div>
  182. </template>
  183. <script>
  184. import { defineComponent } from "@nuxtjs/composition-api"
  185. export default defineComponent({
  186. props: {
  187. collectionIndex: { type: Number, default: null },
  188. collection: { type: Object, default: () => {} },
  189. doc: Boolean,
  190. isFiltered: Boolean,
  191. selected: Boolean,
  192. saveRequest: Boolean,
  193. collectionsType: { type: Object, default: () => {} },
  194. picked: { type: Object, default: () => {} },
  195. },
  196. data() {
  197. return {
  198. showChildren: 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 === "teams-collection" &&
  211. this.picked.collectionID === this.collection.id
  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. if (this.$props.saveRequest)
  225. this.$emit("select", {
  226. picked: {
  227. pickedType: "teams-collection",
  228. collectionID: this.collection.id,
  229. },
  230. })
  231. },
  232. toggleShowChildren() {
  233. if (this.$props.saveRequest)
  234. this.$emit("select", {
  235. picked: {
  236. pickedType: "teams-collection",
  237. collectionID: this.collection.id,
  238. },
  239. })
  240. this.$emit("expand-collection", this.collection.id)
  241. this.showChildren = !this.showChildren
  242. },
  243. removeCollection() {
  244. this.$emit("remove-collection", {
  245. collectionsType: this.collectionsType,
  246. collectionIndex: this.collectionIndex,
  247. collectionID: this.collection.id,
  248. })
  249. },
  250. expandCollection(collectionID) {
  251. this.$emit("expand-collection", collectionID)
  252. },
  253. removeRequest({ collectionIndex, folderName, requestIndex }) {
  254. this.$emit("remove-request", {
  255. collectionIndex,
  256. folderName,
  257. requestIndex,
  258. })
  259. },
  260. },
  261. })
  262. </script>