UserFlags.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template lang="html">
  2. <div id="user-flags">
  3. <h2
  4. class="mdi mdi-folder-outline"
  5. >{{ $t("materio.My folders") }} ({{collsLength}})</h2>
  6. <ul>
  7. <li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
  8. <h5
  9. :flagcollid="coll.id"
  10. @click.prevent="onOpenFlagColl"
  11. >{{ coll.name }} ({{ coll.items.length }})</h5>
  12. <div class="actions">
  13. <span
  14. class="delete-btn mdi"
  15. :class="flagDeletingClassObj"
  16. :flagcollid="coll.id"
  17. @click.prevent="onDeleteFlagColl"
  18. />
  19. </div>
  20. </li>
  21. <li v-if="collsLength<15" class="create-flag">
  22. <input
  23. placeholder="new folder"
  24. v-model="new_folder_name"
  25. @keyup.enter.prevent.stop="onCreateFlagColl"
  26. />
  27. <span
  28. class="add-btn mdi"
  29. :class="addFlagBtnClassObj"
  30. @click.prevent.stop="onCreateFlagColl"
  31. />
  32. </li>
  33. </ul>
  34. </div>
  35. </template>
  36. <script>
  37. import { mapState, mapActions } from 'vuex'
  38. export default {
  39. name: "userFlags",
  40. data: () => ({
  41. new_folder_name: "",
  42. is_creating_folder: false,
  43. is_deleting_folder: false
  44. }),
  45. computed: {
  46. ...mapState({
  47. flagcolls: state => state.User.flagcolls
  48. }),
  49. collsLength() {
  50. return Object.keys(this.flagcolls).length
  51. },
  52. addFlagBtnClassObj() {
  53. return {
  54. 'mdi-plus-circle-outline': !this.is_creating_folder,
  55. 'mdi-loading': this.is_creating_folder,
  56. active: this.new_folder_name.length > 4 && !this.is_creating_folder,
  57. loading: this.is_creating_folder
  58. }
  59. },
  60. flagDeletingClassObj() {
  61. return {
  62. 'mdi-trash-can-outline': !this.is_deleting_folder,
  63. 'mdi-loading': this.is_deleting_folder,
  64. 'loading': this.is_deleting_folder
  65. }
  66. }
  67. },
  68. methods: {
  69. ...mapActions({
  70. createFlagColl: 'User/createFlagColl',
  71. deleteFlagColl: 'User/deleteFlagColl',
  72. openFlagColl: 'User/openFlagColl'
  73. }),
  74. onCreateFlagColl () {
  75. console.log("UserFlags onCreateFlagColl", this.new_folder_name)
  76. this.is_creating_folder = true;
  77. this.createFlagColl(this.new_folder_name)
  78. .then(data => {
  79. console.log("onCreateFlagColl then", data);
  80. this.new_folder_name = "";
  81. this.is_creating_folder = false;
  82. })
  83. },
  84. onDeleteFlagColl (e) {
  85. const flagcollid = e.target.getAttribute('flagcollid');
  86. console.log("UserFlags onDeleteFlagColl", flagcollid);
  87. this.is_deleting_folder = flagcollid;
  88. this.deleteFlagColl(flagcollid)
  89. .then(() => {
  90. // console.log("onDeleteFlagColl then", data);
  91. this.is_deleting_folder = false;
  92. })
  93. },
  94. onOpenFlagColl (e) {
  95. const flagcollid = e.target.getAttribute('flagcollid');
  96. console.log("UserFlags onOpenFlagColl", flagcollid);
  97. this.openFlagColl(flagcollid)
  98. .then(() => {
  99. // console.log("onDeleteFlagColl then", data);
  100. })
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. </style>