collection.vue 3.6 KB

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