From 398c7d7defd1c3a5104666b2a91804e1e68432b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 5 Jan 2020 23:39:30 +0100 Subject: [PATCH 1/3] start change commandlayout for vuex, FinanzerView.vue is ready next steps: overview, table, user ... --- src/components/finanzer/Overview.vue | 9 +- src/plugins/restService.js | 4 +- src/plugins/routes.js | 20 ++ src/router/index.js | 12 +- src/store/index.js | 86 +------- src/store/modules/login.js | 98 +++++++++ src/store/modules/users.js | 274 +++++++++++++++++++++++++ src/views/FinanzerView.vue | 287 +-------------------------- src/views/Login.vue | 31 +-- 9 files changed, 433 insertions(+), 388 deletions(-) create mode 100644 src/plugins/routes.js create mode 100644 src/store/modules/login.js create mode 100644 src/store/modules/users.js diff --git a/src/components/finanzer/Overview.vue b/src/components/finanzer/Overview.vue index 8c9168f..824c189 100644 --- a/src/components/finanzer/Overview.vue +++ b/src/components/finanzer/Overview.vue @@ -2,13 +2,13 @@
Gesamtübersicht - + keyboard_arrow_left {{year}} keyboard_arrow_right - + Emails senden @@ -119,11 +119,11 @@ diff --git a/src/views/Login.vue b/src/views/Login.vue index 8d68a0e..35bbf8a 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -33,8 +33,8 @@ type="text" v-model="username" ref="first" - @keyup.enter="login" - @change="resetError" + @keyup.enter="doLogin({username: username, password: password})" + @input="resetLoginError" /> - {{ loginFail }} + {{ loginError }} - Login + Login @@ -64,6 +64,9 @@ From 9ba50a429ca47bd21d0da07963e60ccf4dd81673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 14 Jan 2020 18:20:05 +0100 Subject: [PATCH 2/3] set namespaced in module finanzerUsers.js todos: barview --- src/components/finanzer/Overview.vue | 113 ++++++++---------- src/components/finanzer/User.vue | 78 ++++-------- src/store/index.js | 7 +- src/store/modules/barUsers.js | 32 +++++ .../modules/{users.js => finanzerUsers.js} | 59 +++++++-- src/views/FinanzerView.vue | 17 +-- 6 files changed, 166 insertions(+), 140 deletions(-) create mode 100644 src/store/modules/barUsers.js rename src/store/modules/{users.js => finanzerUsers.js} (88%) diff --git a/src/components/finanzer/Overview.vue b/src/components/finanzer/Overview.vue index 824c189..cee5221 100644 --- a/src/components/finanzer/Overview.vue +++ b/src/components/finanzer/Overview.vue @@ -4,18 +4,18 @@ Gesamtübersicht - keyboard_arrow_left + keyboard_arrow_left {{year}} - keyboard_arrow_right + keyboard_arrow_right Emails senden - + - + $expand - {{errorMessage(error)}} - + +
+ {{errorMessage(error)}} + +
+
-
- + {{user.lastname}}, {{user.firstname}} @@ -119,39 +123,21 @@ From 42996d8ad121a9adbd7fcd1daf278af003a07bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 14 Jan 2020 19:57:45 +0100 Subject: [PATCH 3/3] finish to use Vuex --- src/components/baruser/CreditLists.vue | 29 ++++---- src/components/baruser/SearchBar.vue | 30 +++----- src/components/finanzer/User.vue | 7 +- src/plugins/restService.js | 57 --------------- src/store/modules/barUsers.js | 97 ++++++++++++++++++++++++-- src/store/modules/finanzerUsers.js | 2 +- src/views/BarView.vue | 77 +------------------- 7 files changed, 125 insertions(+), 174 deletions(-) delete mode 100644 src/plugins/restService.js diff --git a/src/components/baruser/CreditLists.vue b/src/components/baruser/CreditLists.vue index d521dfa..4a0fc08 100644 --- a/src/components/baruser/CreditLists.vue +++ b/src/components/baruser/CreditLists.vue @@ -11,17 +11,17 @@ - 2 € - 1 € - 0,50 € @@ -29,19 +29,19 @@ - 0,40 € - 0,20 € - 0,10 € @@ -67,30 +67,35 @@ diff --git a/src/components/baruser/SearchBar.vue b/src/components/baruser/SearchBar.vue index 1735cbe..14d75e6 100644 --- a/src/components/baruser/SearchBar.vue +++ b/src/components/baruser/SearchBar.vue @@ -13,7 +13,7 @@ diff --git a/src/components/finanzer/User.vue b/src/components/finanzer/User.vue index 3e0d11a..452484a 100644 --- a/src/components/finanzer/User.vue +++ b/src/components/finanzer/User.vue @@ -134,7 +134,12 @@ this.autoLock = {value: this.activeUser.autoLock, text: this.activeUser.autoLock? "Aktiviert" : "Deaktiviert"} }, methods: { - ...mapActions(['finanzerUsers/addAmount', 'finanzerUsers/addCredit', 'finanzerUsers/sendMail', 'finanzerUsers/doLock', 'finanzerUsers/saveConfig']), + ...mapActions({ + addAmount: 'finanzerUsers/addAmount', + addCredit: 'finanzerUsers/addCredit', + sendMail: 'finanzerUsers/sendMail', + doLock: 'finanzerUsers/doLock', + saveConfig: 'finanzerUsers/saveConfig'}), getLastColor (value) { return value < 0 ? 'red' : 'green' }, diff --git a/src/plugins/restService.js b/src/plugins/restService.js deleted file mode 100644 index 01a694f..0000000 --- a/src/plugins/restService.js +++ /dev/null @@ -1,57 +0,0 @@ -import axios from 'axios' - -class Service { - constructor(url) { - this.url = url - } - getFinanzerMain(token) { - return axios.get(this.url + "getFinanzerMain", {headers: {Token: token}}) - - } - login(loginData) { - return axios.post(this.url+'login', {...loginData}) - } - getUserBar(token) { - return axios.get(this.url+'bar', {headers: {Token: token}}) - } - getOneUserBar(token, data) { - return axios.post(this.url+'barGetUser', {...data}, {headers: {Token: token}}) - } - addAmountBar(token, data) { - return axios.post(this.url+'baradd', {...data}, {headers: {Token: token}}) - } - addAmountFinanzer(token, data) { - return axios.post(this.url+'finanzerAddAmount', {...data}, {headers: {Token: token}}) - } - addCreditFinanzer(token, data) { - return axios.post(this.url+'finanzerAddCredit', {...data}, {headers: {Token: token}}) - } - searchUser(token, data) { - return axios.post(this.url+'search', {...data}, {headers: {Token: token}}) - } - getAllUser(token) { - return axios.get(this.url+'barGetUsers', {headers: {Token: token}}) - } - lockUser(token, data) { - return axios.post(this.url+'finanzerLock', {...data}, {headers: {Token: token}}) - } - finanzerSetConfig(token, data) { - return axios.post(this.url+'finanzerSetConfig', {...data}, {headers: {Token: token}}) - } - finanzerAddUser(token, data) { - return axios.post(this.url+'finanzerAddUser', {...data}, {headers: {Token: token}}) - } - finanzerSendAllMail(token) { - return axios.get(this.url+"finanzerSendAllMail", {headers: {Token: token}}) - } - finanzerSendOneMail(token, data) { - return axios.post(this.url+"finanzerSendOneMail", {...data}, {headers: {Token: token}}) - } -} - -//const httpClient = new Service("http://localhost:5000/") -const httpClient = new Service("http://192.168.5.118:5000/") -//const httpClient = new Service("http://192.168.5.128:5000/") -//const httpClient = new Service("http://groeger-clan.duckdns.org:5000/") - -export default httpClient diff --git a/src/store/modules/barUsers.js b/src/store/modules/barUsers.js index 21485f7..e6b7d1e 100644 --- a/src/store/modules/barUsers.js +++ b/src/store/modules/barUsers.js @@ -1,26 +1,109 @@ -//import axios from 'axios'; -//import url from '@/plugins/routes'; +import axios from 'axios'; +import url from '@/plugins/routes'; const state = { - users: null + users: [], + allUsers: [] }; const mutations = { + setAllUsers: (state, users) => { + state.allUsers = [] + state.allUsers = users + for (let i = 0; i < state.allUsers.length; i++) { + state.allUsers[i].fullName = state.allUsers[i].firstname + " " + state.allUsers[i].lastname + } + }, + setUsers: (state, users) => { + // eslint-disable-next-line no-console + console.log(users) + for (let user in users) { + // eslint-disable-next-line no-console + console.log(user) + let existuser = state.users.find(a => {return user === a.username}) + + if (existuser) { + existuser.sername = users[user].username + existuser.firstname = users[user].firstname + existuser.lastname = users[user].lastname + existuser.locked = users[user].locked + existuser.amount = users[user].amount + existuser.type = users[user].type + } else { + state.users.push({ + username: users[user].username, + firstname: users[user].firstname, + lastname: users[user].lastname, + locked: users[user].locked, + amount: users[user].amount, + type: users[user].type + }) + } + } + // eslint-disable-next-line no-console + console.log(state.users) + mutations.sortUsers(state) + }, + sortUsers: (state) => { + state.users = state.users.sort((a,b) => { + if (a.lastname > b.lastname) return 1 + if (a.lastname < b.lastname) return -1 + if (a.firstname > b.firstname) return 1 + if (a.firstname < b.firstname) return -1 + return 0 + }) + }, }; const actions = { // eslint-disable-next-line no-unused-vars async getUsers({commit, rootState, dispatch}) { - // try { - // const response = await axios.get(url) - // } + try { + const response = await axios.get(url.bar, {headers: {Token: rootState.login.user.accessToken}}) + // eslint-disable-next-line no-console + console.log(response.data) + commit('setUsers', response.data) + } catch (e) { + if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) + } + }, + async addAmount({commit, rootState, dispatch}, data) { + try { + const response = await axios.post(url.barAddAmount, {userId: data.username, amount: data.amount}, {headers: {Token: rootState.login.user.accessToken}}) + commit('setUsers', {[response.data.username]: response.data}) + } catch (e) { + if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) + } + }, + async addCreditList({commit, rootState, dispatch}, data) { + try { + const response = await axios.post(url.barGetUser, {userId: data.username}, {headers: {Token: rootState.login.user.accessToken}}) + commit('setUsers', {[response.data.username]: response.data}) + } catch (e) { + if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) + } + }, + async getAllUsers({commit, rootState, dispatch}) { + // eslint-disable-next-line no-console + console.log('hier bin ich') + try { + const response = await axios.post(url.searchUser, {searchString: ""}, {headers: {Token: rootState.login.user.accessToken}}) + // eslint-disable-next-line no-console + console.log(response) + commit('setAllUsers', response.data) + } catch (e) { + // eslint-disable-next-line no-console + console.log(e) + if (e.response) if (e.response.data === 401) dispatch('logout', null, {root: true}) + } } }; const getters = { - + users: (state) => { return state.users }, + allUsers: (state) => { return state.allUsers } }; export default { diff --git a/src/store/modules/finanzerUsers.js b/src/store/modules/finanzerUsers.js index 9a5de7c..f3b50fb 100644 --- a/src/store/modules/finanzerUsers.js +++ b/src/store/modules/finanzerUsers.js @@ -200,7 +200,7 @@ const actions = { commit('setAllUsers', response.data) } catch (err) { // eslint-disable-next-line no-console - if (err.response.status === 401) dispatch('logout', null, {root: true}) + if (err.response) if (err.response.status === 401) dispatch('logout', null, {root: true}) } }, async getUsers({commit, rootState, dispatch}) { diff --git a/src/views/BarView.vue b/src/views/BarView.vue index 0cfadd3..8ce1bba 100644 --- a/src/views/BarView.vue +++ b/src/views/BarView.vue @@ -2,8 +2,8 @@
- - + +
@@ -11,7 +11,6 @@