From c70e6dd64fb4c8919e9575c84d53105ab48c42df Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Tue, 3 Nov 2020 14:44:12 +0500 Subject: [PATCH] feat(web2): edit account dialog --- web2/src/App.vue | 37 ++++++- web2/src/components/NewProjectDialog.vue | 3 +- web2/src/components/ProjectForm.vue | 3 +- web2/src/components/UserDialog.vue | 93 ++++++++++++++++ web2/src/components/UserForm.vue | 134 +++++++++++++++++++++++ web2/src/views/Users.vue | 31 +++--- 6 files changed, 284 insertions(+), 17 deletions(-) create mode 100644 web2/src/components/UserDialog.vue diff --git a/web2/src/App.vue b/web2/src/App.vue index 2a469466..b07d3266 100644 --- a/web2/src/App.vue +++ b/web2/src/App.vue @@ -4,6 +4,11 @@ v-model="newProjectDialog" /> + + - + mdi-pencil @@ -320,6 +325,7 @@ import axios from 'axios'; import NewProjectDialog from '@/components/NewProjectDialog.vue'; import { getErrorMessage } from '@/lib/error'; +import UserDialog from '@/components/UserDialog.vue'; import EventBus from './event-bus'; const PROJECT_COLORS = [ @@ -333,6 +339,7 @@ export default { name: 'App', components: { NewProjectDialog, + UserDialog, }, data() { return { @@ -344,6 +351,7 @@ export default { snackbarColor: '', projects: null, newProjectDialog: null, + userDialog: null, }; }, @@ -420,6 +428,33 @@ export default { await this.tryToSwitchToLastProject(); }); + EventBus.$on('i-user', async (e) => { + let text; + + switch (e.action) { + case 'new': + text = `User ${e.item.name} created`; + break; + case 'edit': + text = `User ${e.item.name} saved`; + break; + case 'delete': + text = `User #${e.item.id} deleted`; + break; + default: + throw new Error('Unknown project action'); + } + + EventBus.$emit('i-snackbar', { + color: 'success', + text, + }); + + if (e.item.id === this.user.id) { + await this.loadUserInfo(); + } + }); + EventBus.$on('i-project', async (e) => { let text; diff --git a/web2/src/components/NewProjectDialog.vue b/web2/src/components/NewProjectDialog.vue index 5f56d514..8e195420 100644 --- a/web2/src/components/NewProjectDialog.vue +++ b/web2/src/components/NewProjectDialog.vue @@ -73,13 +73,14 @@ export default { async save() { const item = await this.$refs.form.save(); if (!item) { - return; + return null; } EventBus.$emit('i-project', { action: 'new', item, }); this.dialog = false; + return item; }, }, }; diff --git a/web2/src/components/ProjectForm.vue b/web2/src/components/ProjectForm.vue index 62004644..5dca68e3 100644 --- a/web2/src/components/ProjectForm.vue +++ b/web2/src/components/ProjectForm.vue @@ -85,8 +85,7 @@ export default { /** * Saves or creates project via API. - * Method must be wrapped to try-catch block because it can throws exception. - * @returns {Promise} null if validation not passed or project data if project saved. + * @returns {Promise} null if validation didn't pass or project data if project saved. */ async save() { this.formError = null; diff --git a/web2/src/components/UserDialog.vue b/web2/src/components/UserDialog.vue new file mode 100644 index 00000000..825042a8 --- /dev/null +++ b/web2/src/components/UserDialog.vue @@ -0,0 +1,93 @@ + + diff --git a/web2/src/components/UserForm.vue b/web2/src/components/UserForm.vue index e69de29b..658a4b9d 100644 --- a/web2/src/components/UserForm.vue +++ b/web2/src/components/UserForm.vue @@ -0,0 +1,134 @@ + + diff --git a/web2/src/views/Users.vue b/web2/src/views/Users.vue index e1d1b355..736a70ef 100644 --- a/web2/src/views/Users.vue +++ b/web2/src/views/Users.vue @@ -1,5 +1,7 @@