materio-d9/web/themes/custom/materiotheme/vuejs/components/User/UserFlags.vue

112 lines
3.0 KiB
Vue
Raw Normal View History

<template lang="html">
<div id="user-flags">
2020-11-19 21:43:56 +01:00
<h2
class="mdi mdi-folder-outline"
>{{ $t("materio.My folders") }} ({{collsLength}})</h2>
<ul>
<li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
<h5
:flagcollid="coll.id"
@click.prevent="onOpenFlagColl"
>{{ coll.name }} ({{ coll.items.length }})</h5>
2020-11-19 21:43:56 +01:00
<div class="actions">
<span
2020-11-20 10:39:19 +01:00
class="delete-btn mdi"
:class="flagDeletingClassObj"
2020-11-24 14:07:10 +01:00
:flagcollid="coll.id"
@click.prevent="onDeleteFlagColl"
2020-11-19 21:43:56 +01:00
/>
</div>
</li>
2020-12-01 20:40:37 +01:00
<li v-if="collsLength<15" class="create-flag">
2020-11-19 17:09:48 +01:00
<input
placeholder="new folder"
v-model="new_folder_name"
2020-12-01 20:40:37 +01:00
@keyup.enter.prevent.stop="onCreateFlagColl"
2020-11-19 17:09:48 +01:00
/>
<span
2020-11-20 10:39:19 +01:00
class="add-btn mdi"
:class="addFlagBtnClassObj"
@click.prevent.stop="onCreateFlagColl"
2020-11-19 17:09:48 +01:00
/>
</li>
</ul>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
export default {
name: "userFlags",
data: () => ({
2020-11-19 21:43:56 +01:00
new_folder_name: "",
2020-11-20 10:39:19 +01:00
is_creating_folder: false,
is_deleting_folder: false
}),
computed: {
...mapState({
2020-11-24 14:07:10 +01:00
flagcolls: state => state.User.flagcolls
2020-11-20 10:39:19 +01:00
}),
2020-12-01 20:40:37 +01:00
collsLength() {
return Object.keys(this.flagcolls).length
},
2020-11-20 10:39:19 +01:00
addFlagBtnClassObj() {
return {
'mdi-plus-circle-outline': !this.is_creating_folder,
'mdi-loading': this.is_creating_folder,
active: this.new_folder_name.length > 4 && !this.is_creating_folder,
loading: this.is_creating_folder
}
},
flagDeletingClassObj() {
return {
'mdi-trash-can-outline': !this.is_deleting_folder,
'mdi-loading': this.is_deleting_folder,
'loading': this.is_deleting_folder
}
}
},
methods: {
...mapActions({
2020-11-24 14:07:10 +01:00
createFlagColl: 'User/createFlagColl',
deleteFlagColl: 'User/deleteFlagColl',
openFlagColl: 'User/openFlagColl'
}),
2020-11-24 14:07:10 +01:00
onCreateFlagColl () {
console.log("UserFlags onCreateFlagColl", this.new_folder_name)
2020-11-20 10:39:19 +01:00
this.is_creating_folder = true;
2020-11-24 14:07:10 +01:00
this.createFlagColl(this.new_folder_name)
2020-11-19 19:02:04 +01:00
.then(data => {
2020-11-24 14:07:10 +01:00
console.log("onCreateFlagColl then", data);
2020-11-19 19:02:04 +01:00
this.new_folder_name = "";
2020-11-20 10:39:19 +01:00
this.is_creating_folder = false;
2020-11-19 19:02:04 +01:00
})
},
2020-11-24 14:07:10 +01:00
onDeleteFlagColl (e) {
const flagcollid = e.target.getAttribute('flagcollid');
2020-11-24 14:07:10 +01:00
console.log("UserFlags onDeleteFlagColl", flagcollid);
this.is_deleting_folder = flagcollid;
this.deleteFlagColl(flagcollid)
2020-11-20 10:39:19 +01:00
.then(() => {
2020-11-24 14:07:10 +01:00
// console.log("onDeleteFlagColl then", data);
2020-11-20 10:39:19 +01:00
this.is_deleting_folder = false;
2020-11-19 19:02:04 +01:00
})
},
onOpenFlagColl (e) {
const flagcollid = e.target.getAttribute('flagcollid');
console.log("UserFlags onOpenFlagColl", flagcollid);
this.openFlagColl(flagcollid)
.then(() => {
// console.log("onDeleteFlagColl then", data);
})
}
}
}
</script>
<style lang="scss" scoped>
2020-11-19 21:43:56 +01:00
</style>