From b1c2a56c2a96446b2f8bd661168ff9722c4e25f1 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Sun, 25 Oct 2020 23:59:03 +0100 Subject: [PATCH] Add Groups to vue front-end --- resources/js/packages/fontawesome.js | 14 ++- resources/js/views/Accounts.vue | 134 +++++++++++++++++++++++++-- resources/js/views/Groups.vue | 81 ++++++++++++++++ resources/js/views/groups/Create.vue | 50 ++++++++++ resources/js/views/groups/Edit.vue | 63 +++++++++++++ resources/lang/en/groups.php | 30 ++++++ resources/sass/app.scss | 25 ++++- 7 files changed, 387 insertions(+), 10 deletions(-) create mode 100644 resources/js/views/Groups.vue create mode 100644 resources/js/views/groups/Create.vue create mode 100644 resources/js/views/groups/Edit.vue create mode 100644 resources/lang/en/groups.php diff --git a/resources/js/packages/fontawesome.js b/resources/js/packages/fontawesome.js index 74a6e8cb..16255350 100644 --- a/resources/js/packages/fontawesome.js +++ b/resources/js/packages/fontawesome.js @@ -5,6 +5,7 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { faPlus, + faPlusCircle, faQrcode, faImage, faTrash, @@ -16,7 +17,11 @@ import { faEllipsisH, faBars, faSpinner, - faChevronLeft + faChevronLeft, + faCaretUp, + faCaretDown, + faLayerGroup, + faMinusCircle, } from '@fortawesome/free-solid-svg-icons' import { @@ -25,6 +30,7 @@ import { library.add( faPlus, + faPlusCircle, faQrcode, faImage, faTrash, @@ -37,7 +43,11 @@ library.add( faBars, faSpinner, faGithubAlt, - faChevronLeft + faChevronLeft, + faCaretUp, + faCaretDown, + faLayerGroup, + faMinusCircle, ); Vue.component('font-awesome-icon', FontAwesomeIcon) \ No newline at end of file diff --git a/resources/js/views/Accounts.vue b/resources/js/views/Accounts.vue index 6593a2ca..6af079a2 100644 --- a/resources/js/views/Accounts.vue +++ b/resources/js/views/Accounts.vue @@ -1,5 +1,22 @@ @@ -120,18 +158,24 @@ import QuickUploader from './../components/QuickUploader' // import vuePullRefresh from 'vue-pull-refresh'; import draggable from 'vuedraggable' + import Form from './../components/Form' export default { data(){ return { accounts : [], + groups : [], selectedAccounts: [], + form: new Form({ + activeGroup: this.$root.appSettings.activeGroup, + }), showTwofaccountInModal : false, search: '', editMode: this.InitialEditMode, showUploader: false, showFooter: true, + showGroupSelector: false, drag: false, } }, @@ -151,9 +195,20 @@ }, showAccounts() { - return this.accounts.length > 0 && !this.showUploader ? true : false + return this.accounts.length > 0 && !this.showUploader && !this.showGroupSelector ? true : false }, + activeGroupName() { + let g = this.groups.find(el => el.id === parseInt(this.$root.appSettings.activeGroup)) + + if(g) { + return g.name + } + else { + return this.$t('commons.all') + } + } + }, props: ['InitialEditMode'], @@ -161,6 +216,7 @@ mounted() { this.fetchAccounts() + this.fetchGroups() // stop OTP generation on modal close this.$on('modalClose', function() { @@ -261,6 +317,72 @@ } }, + async moveAccounts() { + + let accountsIds = [] + this.selectedAccounts.forEach(id => accountsIds.push(id)) + + // Backend will associate all accounts with the selected group in the same move + await this.axios.patch('/api/group/accounts', {accountsIds: accountsIds, groupId: '3'} ) + + // we fetch the accounts again to prevent the js collection being + // desynchronize from the backend php collection + this.fetchAccounts() + + }, + + fetchGroups() { + this.groups = [] + + this.axios.get('api/groups').then(response => { + response.data.forEach((data) => { + this.groups.push({ + id : data.id, + name : data.name, + isActive: data.isActive, + count: data.twofaccounts_count + }) + }) + }) + }, + + async setActiveGroup(id) { + + this.form.activeGroup = id + + await this.form.post('/api/settings/options', {returnError: true}) + .then(response => { + + this.$root.appSettings.activeGroup = response.data.settings.activeGroup + + this.closeGroupSelector() + + }) + .catch(error => { + + this.$router.push({ name: 'genericError', params: { err: error.response } }) + }); + + this.fetchAccounts() + }, + + toggleGroupSelector: function(event) { + + if (event) { + this.showGroupSelector ? this.closeGroupSelector() : this.openGroupSelector() + } + }, + + openGroupSelector: function(event) { + + this.showGroupSelector = true + }, + + closeGroupSelector: function(event) { + + this.showGroupSelector = false + }, + setEditModeTo(state) { if( state === false ) { this.selectedAccounts = [] diff --git a/resources/js/views/Groups.vue b/resources/js/views/Groups.vue new file mode 100644 index 00000000..9c5472dc --- /dev/null +++ b/resources/js/views/Groups.vue @@ -0,0 +1,81 @@ + + + \ No newline at end of file diff --git a/resources/js/views/groups/Create.vue b/resources/js/views/groups/Create.vue new file mode 100644 index 00000000..83bf080a --- /dev/null +++ b/resources/js/views/groups/Create.vue @@ -0,0 +1,50 @@ + + + \ No newline at end of file diff --git a/resources/js/views/groups/Edit.vue b/resources/js/views/groups/Edit.vue new file mode 100644 index 00000000..719999e7 --- /dev/null +++ b/resources/js/views/groups/Edit.vue @@ -0,0 +1,63 @@ + + + \ No newline at end of file diff --git a/resources/lang/en/groups.php b/resources/lang/en/groups.php new file mode 100644 index 00000000..4460c802 --- /dev/null +++ b/resources/lang/en/groups.php @@ -0,0 +1,30 @@ + 'Groups', + 'select_accounts_to_show' => 'Select accounts to show', + 'manage_groups' => 'Manage groups', + 'manage_groups_legend' => 'You can create groups to manage your accounts the way you want. All your accounts remain visible in the pseudo group named \'All\', regardless of the group they belong to.', + 'deleting_group_does_not_delete_accounts' => 'Deleting a group does not delete accounts', + 'forms' => [ + 'new_group' => 'New group', + 'new_name' => 'New name', + 'rename_group' => 'Rename group', + ], + 'confirm' => [ + 'delete' => 'Are you sure you want to delete this group?', + ], + +]; \ No newline at end of file diff --git a/resources/sass/app.scss b/resources/sass/app.scss index 0bfd239f..c80ae2a0 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -51,13 +51,34 @@ a:hover { } } +.group-selector { + cursor: pointer; +} + +.group-item { + border-bottom: 1px solid hsl(0, 0%, 21%); + padding: 0.75rem; +} + +.group-item:first-of-type { + margin-top: 2.5rem; +} + +.group-item span { + display: block; +} + .accounts { - margin-top: 40px; + margin-top: 64px; +} + +.groups { + margin-top: 110px; } @media screen and (min-width: 769px) { .accounts { - margin-top: 60px; + margin-top: 84px; } }