collection.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div>
  3. <div class="row-wrapper">
  4. <button class="icon" @click="toggleShowChildren">
  5. <i class="material-icons" v-show="!showChildren">arrow_right</i>
  6. <i class="material-icons" v-show="showChildren">arrow_drop_down</i>
  7. <folderIcon class="material-icons" />
  8. <span>{{ collection.name }}</span>
  9. </button>
  10. <div>
  11. <button
  12. v-if="doc"
  13. class="icon"
  14. @click="$emit('select-collection')"
  15. v-tooltip.left="$t('import')"
  16. >
  17. <i class="material-icons">topic</i>
  18. </button>
  19. <v-popover>
  20. <button class="tooltip-target icon" v-tooltip.left="$t('more')">
  21. <i class="material-icons">more_vert</i>
  22. </button>
  23. <template slot="popover">
  24. <div>
  25. <button class="icon" @click="$emit('add-folder')" v-close-popover>
  26. <i class="material-icons">create_new_folder</i>
  27. <span>{{ $t("new_folder") }}</span>
  28. </button>
  29. </div>
  30. <div>
  31. <button class="icon" @click="$emit('edit-collection')" v-close-popover>
  32. <i class="material-icons">create</i>
  33. <span>{{ $t("edit") }}</span>
  34. </button>
  35. </div>
  36. <div>
  37. <button class="icon" @click="removeCollection" v-close-popover>
  38. <deleteIcon class="material-icons" />
  39. <span>{{ $t("delete") }}</span>
  40. </button>
  41. </div>
  42. </template>
  43. </v-popover>
  44. </div>
  45. </div>
  46. <div v-show="showChildren">
  47. <ul class="flex-col">
  48. <li
  49. v-for="(folder, index) in collection.folders"
  50. :key="folder.name"
  51. class="ml-8 border-l border-brdColor"
  52. >
  53. <folder
  54. :folder="folder"
  55. :folderIndex="index"
  56. :collection-index="collectionIndex"
  57. :doc="doc"
  58. @edit-folder="editFolder(collectionIndex, folder, index)"
  59. @edit-request="$emit('edit-request', $event)"
  60. />
  61. </li>
  62. <li
  63. v-if="collection.folders.length === 0 && collection.requests.length === 0"
  64. class="ml-8 border-l border-brdColor"
  65. >
  66. <label>{{ $t("collection_empty") }}</label>
  67. </li>
  68. </ul>
  69. <ul class="flex-col">
  70. <li
  71. v-for="(request, index) in collection.requests"
  72. :key="index"
  73. class="ml-8 border-l border-brdColor"
  74. >
  75. <request
  76. :request="request"
  77. :collection-index="collectionIndex"
  78. :folder-index="-1"
  79. :request-index="index"
  80. :doc="doc"
  81. @edit-request="
  82. $emit('edit-request', {
  83. request,
  84. collectionIndex,
  85. folderIndex: undefined,
  86. requestIndex: index,
  87. })
  88. "
  89. />
  90. </li>
  91. </ul>
  92. </div>
  93. </div>
  94. </template>
  95. <script>
  96. import { fb } from "~/helpers/fb"
  97. import folderIcon from "~/static/icons/folder-24px.svg?inline"
  98. import deleteIcon from "~/static/icons/delete-24px.svg?inline"
  99. export default {
  100. components: { folderIcon, deleteIcon },
  101. props: {
  102. collectionIndex: Number,
  103. collection: Object,
  104. doc: Boolean,
  105. },
  106. data() {
  107. return {
  108. showChildren: false,
  109. selectedFolder: {},
  110. }
  111. },
  112. methods: {
  113. syncCollections() {
  114. if (fb.currentUser !== null) {
  115. if (fb.currentSettings[0].value) {
  116. fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)))
  117. }
  118. }
  119. },
  120. toggleShowChildren() {
  121. this.showChildren = !this.showChildren
  122. },
  123. removeCollection() {
  124. if (!confirm(this.$t("are_you_sure_remove_collection"))) return
  125. this.$store.commit("postwoman/removeCollection", {
  126. collectionIndex: this.collectionIndex,
  127. })
  128. this.$toast.error(this.$t("deleted"), {
  129. icon: "delete",
  130. })
  131. this.syncCollections()
  132. },
  133. editFolder(collectionIndex, folder, folderIndex) {
  134. this.$emit("edit-folder", { collectionIndex, folder, folderIndex })
  135. },
  136. },
  137. }
  138. </script>