2020-10-25 23:59:03 +01:00
|
|
|
<template>
|
2022-10-12 12:56:16 +02:00
|
|
|
<responsive-width-wrapper>
|
|
|
|
<h1 class="title has-text-grey-dark">
|
|
|
|
{{ $t('groups.groups') }}
|
|
|
|
</h1>
|
|
|
|
<div class="is-size-7-mobile">
|
|
|
|
{{ $t('groups.manage_groups_legend')}}
|
|
|
|
</div>
|
|
|
|
<div class="mt-3 mb-6">
|
|
|
|
<router-link class="is-link mt-5" :to="{ name: 'createGroup' }">
|
|
|
|
<font-awesome-icon :icon="['fas', 'plus-circle']" /> {{ $t('groups.create_group') }}
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
<div v-if="groups.length > 0">
|
2023-02-01 17:21:55 +01:00
|
|
|
<div v-for="group in groups" :key="group.id" class="group-item is-size-5 is-size-6-mobile">
|
2022-10-12 12:56:16 +02:00
|
|
|
{{ group.name }}
|
|
|
|
<!-- delete icon -->
|
2023-02-01 17:21:55 +01:00
|
|
|
<button class="button tag is-pulled-right" :class="$root.showDarkMode ? 'is-dark' : 'is-white'" @click="deleteGroup(group.id)" :title="$t('commons.delete')">
|
2022-10-12 12:56:16 +02:00
|
|
|
{{ $t('commons.delete') }}
|
|
|
|
</button>
|
|
|
|
<!-- edit link -->
|
2022-10-12 11:30:20 +02:00
|
|
|
<router-link :to="{ name: 'editGroup', params: { id: group.id, name: group.name }}" class="has-text-grey px-1" :title="$t('commons.rename')">
|
2022-10-12 12:56:16 +02:00
|
|
|
<font-awesome-icon :icon="['fas', 'pen-square']" />
|
2020-11-25 21:56:04 +01:00
|
|
|
</router-link>
|
2022-10-12 12:56:16 +02:00
|
|
|
<span class="is-family-primary is-size-6 is-size-7-mobile has-text-grey">{{ group.twofaccounts_count }} {{ $t('twofaccounts.accounts') }}</span>
|
2020-11-25 21:56:04 +01:00
|
|
|
</div>
|
2022-10-12 12:56:16 +02:00
|
|
|
<div class="mt-2 is-size-7 is-pulled-right" v-if="groups.length > 0">
|
|
|
|
{{ $t('groups.deleting_group_does_not_delete_accounts')}}
|
2020-10-25 23:59:03 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-12 12:56:16 +02:00
|
|
|
<div v-if="isFetching && groups.length === 0" class="has-text-centered">
|
|
|
|
<span class="is-size-4">
|
|
|
|
<font-awesome-icon :icon="['fas', 'spinner']" spin />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<!-- footer -->
|
|
|
|
<vue-footer :showButtons="true">
|
|
|
|
<!-- close button -->
|
|
|
|
<p class="control">
|
2023-02-01 17:21:55 +01:00
|
|
|
<router-link :to="{ name: 'accounts', params: { toRefresh: true } }" class="button is-rounded" :class="{'is-dark' : $root.showDarkMode}">{{ $t('commons.close') }}</router-link>
|
2022-10-12 12:56:16 +02:00
|
|
|
</p>
|
|
|
|
</vue-footer>
|
|
|
|
</responsive-width-wrapper>
|
2020-10-25 23:59:03 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
groups : [],
|
2020-11-27 13:54:54 +01:00
|
|
|
TheAllGroup : null,
|
2020-11-29 18:57:17 +01:00
|
|
|
isFetching: false,
|
2020-10-25 23:59:03 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2020-11-26 20:41:02 +01:00
|
|
|
// Load groups for localstorage at first to avoid latency
|
|
|
|
const groups = this.$storage.get('groups', null) // use null as fallback if localstorage is empty
|
|
|
|
|
2020-11-27 13:54:54 +01:00
|
|
|
// We don't want the pseudo group 'All' to be managed so we shift it
|
|
|
|
if( groups ) {
|
|
|
|
this.groups = groups
|
|
|
|
this.TheAllGroup = this.groups.shift()
|
|
|
|
}
|
|
|
|
|
|
|
|
// we refresh the collection whatever
|
2020-10-25 23:59:03 +01:00
|
|
|
this.fetchGroups()
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
/**
|
|
|
|
* Get all groups from backend
|
|
|
|
*/
|
2020-10-25 23:59:03 +01:00
|
|
|
async fetchGroups() {
|
|
|
|
|
2020-11-29 18:57:17 +01:00
|
|
|
this.isFetching = true
|
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
await this.axios.get('api/v1/groups').then(response => {
|
2020-11-26 20:41:02 +01:00
|
|
|
const groups = []
|
|
|
|
|
2020-10-25 23:59:03 +01:00
|
|
|
response.data.forEach((data) => {
|
2021-10-09 19:23:24 +02:00
|
|
|
groups.push(data)
|
2020-10-25 23:59:03 +01:00
|
|
|
})
|
2020-11-26 20:41:02 +01:00
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
// Remove the 'All' pseudo group from the collection
|
|
|
|
// and push it the TheAllGroup
|
2020-11-27 13:54:54 +01:00
|
|
|
this.TheAllGroup = groups.shift()
|
|
|
|
|
2020-11-26 20:41:02 +01:00
|
|
|
this.groups = groups
|
2020-10-25 23:59:03 +01:00
|
|
|
})
|
2020-11-29 18:57:17 +01:00
|
|
|
|
|
|
|
this.isFetching = false
|
2020-10-25 23:59:03 +01:00
|
|
|
},
|
|
|
|
|
2021-10-09 19:23:24 +02:00
|
|
|
/**
|
|
|
|
* Delete a group (after confirmation)
|
|
|
|
*/
|
2020-10-25 23:59:03 +01:00
|
|
|
deleteGroup(id) {
|
|
|
|
if(confirm(this.$t('groups.confirm.delete'))) {
|
2021-11-07 21:57:22 +01:00
|
|
|
this.axios.delete('/api/v1/groups/' + id)
|
2020-10-25 23:59:03 +01:00
|
|
|
|
|
|
|
// Remove the deleted group from the collection
|
|
|
|
this.groups = this.groups.filter(a => a.id !== id)
|
2022-09-19 12:19:34 +02:00
|
|
|
this.$notify({ type: 'is-success', text: this.$t('groups.group_successfully_deleted') })
|
2020-12-01 07:03:45 +01:00
|
|
|
|
|
|
|
// Reset persisted group filter to 'All' (groupId=0)
|
2021-10-09 19:23:24 +02:00
|
|
|
// (backend will save to change automatically)
|
2020-12-01 07:03:45 +01:00
|
|
|
if( parseInt(this.$root.appSettings.activeGroup) === id ) {
|
2021-10-09 19:23:24 +02:00
|
|
|
this.$root.appSettings.activeGroup = 0
|
2020-12-01 07:03:45 +01:00
|
|
|
}
|
2020-10-25 23:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2020-11-26 20:41:02 +01:00
|
|
|
beforeRouteLeave(to, from, next) {
|
2021-10-09 19:23:24 +02:00
|
|
|
// reinject the 'All' pseudo group before refreshing the localstorage
|
2020-11-27 13:54:54 +01:00
|
|
|
this.groups.unshift(this.TheAllGroup)
|
2020-11-26 20:41:02 +01:00
|
|
|
this.$storage.set('groups', this.groups)
|
|
|
|
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
|
2020-10-25 23:59:03 +01:00
|
|
|
}
|
|
|
|
</script>
|