From 4374eaa3d7d4ff64fa97bc2b9ece6109b29c6029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 14 Jan 2020 22:01:24 +0100 Subject: [PATCH] used prettier on code --- src/App.vue | 14 +- src/components/TitleBar.vue | 90 ++- src/components/baruser/CreditLists.vue | 212 ++++---- src/components/baruser/SearchBar.vue | 84 +-- src/components/finanzer/Overview.vue | 516 +++++++++++------- src/components/finanzer/Table.vue | 223 ++++---- src/components/finanzer/User.vue | 502 ++++++++++------- src/plugins/routes.js | 34 +- src/plugins/vuetify.js | 14 +- src/router/index.js | 33 +- src/store/index.js | 8 +- src/store/modules/barUsers.js | 225 ++++---- src/store/modules/finanzerUsers.js | 724 +++++++++++++++---------- src/store/modules/login.js | 183 ++++--- src/views/BarView.vue | 47 +- src/views/FinanzerView.vue | 162 +++--- src/views/Home.vue | 4 +- src/views/Login.vue | 137 +++-- 18 files changed, 1794 insertions(+), 1418 deletions(-) diff --git a/src/App.vue b/src/App.vue index 82cdfcc..164699d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,24 +1,20 @@ diff --git a/src/components/TitleBar.vue b/src/components/TitleBar.vue index 0359649..60949de 100644 --- a/src/components/TitleBar.vue +++ b/src/components/TitleBar.vue @@ -1,59 +1,51 @@ diff --git a/src/components/baruser/CreditLists.vue b/src/components/baruser/CreditLists.vue index 4a0fc08..35bff87 100644 --- a/src/components/baruser/CreditLists.vue +++ b/src/components/baruser/CreditLists.vue @@ -1,107 +1,127 @@ diff --git a/src/components/baruser/SearchBar.vue b/src/components/baruser/SearchBar.vue index 14d75e6..c1abe10 100644 --- a/src/components/baruser/SearchBar.vue +++ b/src/components/baruser/SearchBar.vue @@ -1,50 +1,54 @@ diff --git a/src/components/finanzer/Overview.vue b/src/components/finanzer/Overview.vue index cee5221..37da410 100644 --- a/src/components/finanzer/Overview.vue +++ b/src/components/finanzer/Overview.vue @@ -1,227 +1,323 @@ diff --git a/src/components/finanzer/Table.vue b/src/components/finanzer/Table.vue index 0f8ddfb..bfb57c9 100644 --- a/src/components/finanzer/Table.vue +++ b/src/components/finanzer/Table.vue @@ -1,118 +1,125 @@ diff --git a/src/components/finanzer/User.vue b/src/components/finanzer/User.vue index 452484a..0496546 100644 --- a/src/components/finanzer/User.vue +++ b/src/components/finanzer/User.vue @@ -1,212 +1,310 @@ diff --git a/src/plugins/routes.js b/src/plugins/routes.js index 47ed526..9d79aca 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -1,20 +1,20 @@ -const main = 'http://192.168.5.118:5000/'; +const main = 'http://192.168.5.118:5000/' const url = { - login: main + 'login', - getFinanzerMain: main + 'getFinanzerMain', - bar: main + 'bar', - barGetUser: main + 'barGetUser', - barAddAmount: main + 'baradd', - finanzerAddAmount: main + 'finanzerAddAmount', - finanzerAddCredit: main + 'finanzerAddCredit', - searchUser: main + 'search', - getAllUser: main + 'barGetUsers', - lockUser: main + 'finanzerLock', - finanzerSetConfig: main + 'finanzerSetConfig', - finanzerAddUser: main + 'finanzerAddUser', - finanzerSendAllMail: main + 'finanzerSendAllMail', - finanzerSendOneMail: main + 'finanzerSendOneMail' -}; + login: main + 'login', + getFinanzerMain: main + 'getFinanzerMain', + bar: main + 'bar', + barGetUser: main + 'barGetUser', + barAddAmount: main + 'baradd', + finanzerAddAmount: main + 'finanzerAddAmount', + finanzerAddCredit: main + 'finanzerAddCredit', + searchUser: main + 'search', + getAllUser: main + 'barGetUsers', + lockUser: main + 'finanzerLock', + finanzerSetConfig: main + 'finanzerSetConfig', + finanzerAddUser: main + 'finanzerAddUser', + finanzerSendAllMail: main + 'finanzerSendAllMail', + finanzerSendOneMail: main + 'finanzerSendOneMail' +} -export default url; +export default url diff --git a/src/plugins/vuetify.js b/src/plugins/vuetify.js index 392f1a1..fa57d63 100644 --- a/src/plugins/vuetify.js +++ b/src/plugins/vuetify.js @@ -1,11 +1,11 @@ -import Vue from 'vue'; -import Vuetify from 'vuetify/lib'; +import Vue from 'vue' +import Vuetify from 'vuetify/lib' import 'material-design-icons-iconfont' -Vue.use(Vuetify); +Vue.use(Vuetify) export default new Vuetify({ - icons: { - iconfont: 'md', - } -}); + icons: { + iconfont: 'md' + } +}) diff --git a/src/router/index.js b/src/router/index.js index efe673b..e7f546e 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,36 +1,34 @@ import Vue from 'vue' import VueRouter from 'vue-router' -import FinanzerView from "@/views/FinanzerView"; -import Login from "@/views/Login"; -import store from "@/store/index"; -import BarView from "@/views/BarView"; +import FinanzerView from '@/views/FinanzerView' +import Login from '@/views/Login' +import store from '@/store/index' +import BarView from '@/views/BarView' Vue.use(VueRouter) const routes = [ - { - path: "/login", - name: "login", + path: '/login', + name: 'login', component: Login }, { - path: "/finanzer", - name: "finanzer", + path: '/finanzer', + name: 'finanzer', component: FinanzerView }, { - path: "/bar", - name: "bar", + path: '/bar', + name: 'bar', component: BarView }, { path: '*', redirect: { - name: "login" + name: 'login' } - }, - + } ] const router = new VueRouter({ @@ -40,7 +38,7 @@ const router = new VueRouter({ }) router.beforeEach((to, from, next) => { - store.dispatch('fetchAccessToken'); + store.dispatch('fetchAccessToken') let sites = ['/finanzer', '/bar'] if (sites.includes(to.fullPath)) { if (to.fullPath === '/finanzer') { @@ -64,10 +62,9 @@ router.beforeEach((to, from, next) => { } else if (store.state.login.user.group.includes('bar')) { next('/bar') } - } } - next(); -}); + next() +}) export default router diff --git a/src/store/index.js b/src/store/index.js index d4aa58f..e8ca7be 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,8 +1,8 @@ -import Vue from 'vue'; -import Vuex from 'vuex'; -import login from './modules/login'; +import Vue from 'vue' +import Vuex from 'vuex' +import login from './modules/login' import finanzerUsers from './modules/finanzerUsers' -import barUsers from "@/store/modules/barUsers"; +import barUsers from '@/store/modules/barUsers' Vue.use(Vuex) diff --git a/src/store/modules/barUsers.js b/src/store/modules/barUsers.js index e6b7d1e..ed4186a 100644 --- a/src/store/modules/barUsers.js +++ b/src/store/modules/barUsers.js @@ -1,115 +1,138 @@ -import axios from 'axios'; -import url from '@/plugins/routes'; +import axios from 'axios' +import url from '@/plugins/routes' const state = { - users: [], - allUsers: [] -}; + 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}) + 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 + 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.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}) - } + // eslint-disable-next-line no-unused-vars + async getUsers({ commit, rootState, dispatch }) { + 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 } -}; + users: state => { + return state.users + }, + allUsers: state => { + return state.allUsers + } +} export default { - namespaced: true, - state, - mutations, - actions, - getters + namespaced: true, + state, + mutations, + actions, + getters } diff --git a/src/store/modules/finanzerUsers.js b/src/store/modules/finanzerUsers.js index f3b50fb..d379a36 100644 --- a/src/store/modules/finanzerUsers.js +++ b/src/store/modules/finanzerUsers.js @@ -1,311 +1,443 @@ -import axios from 'axios'; +import axios from 'axios' // eslint-disable-next-line no-unused-vars import url from '@/plugins/routes' const state = { - users: [], - activeUser: { - username: null, - }, - allUsers: [], - user: null, - errorMails: null, - errorMail: null, - year: new Date().getFullYear(), - years: [], - months: [ - {value: 1, text: 'Januar'}, - {value: 2, text: 'Februar'}, - {value: 3, text: 'März'}, - {value: 4, text:'April'}, - {value: 5, text: 'Mai'}, - {value: 6, text: 'Juni'}, - {value: 7, text: 'Juli'}, - {value: 8, text: 'August'}, - {value: 9, text: 'September'}, - {value: 10, text: 'Oktober'}, - {value: 11, text: 'November'}, - {value: 12, text: 'Dezember'} - ], -}; + users: [], + activeUser: { + username: null + }, + allUsers: [], + user: null, + errorMails: null, + errorMail: null, + year: new Date().getFullYear(), + years: [], + months: [ + { value: 1, text: 'Januar' }, + { value: 2, text: 'Februar' }, + { value: 3, text: 'März' }, + { value: 4, text: 'April' }, + { value: 5, text: 'Mai' }, + { value: 6, text: 'Juni' }, + { value: 7, text: 'Juli' }, + { value: 8, text: 'August' }, + { value: 9, text: 'September' }, + { value: 10, text: 'Oktober' }, + { value: 11, text: 'November' }, + { value: 12, text: 'Dezember' } + ] +} 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 - } - }, - setActiveUser: (state, user) => { - if (state.activeUser.username === user.username) { - state.activeUser = {username: null} - } else { - state.activeUser = user - } - state.errorMail = null - }, - setUsers: (state, users) => { - // eslint-disable-next-line no-console - console.log('users', users) - for (let user in users) { - // eslint-disable-next-line no-console - console.log('user', user) - let list = {} - for (let creditList in users[user]['creditList']) { - let amount = mutations.createAmount(users[user]['creditList'][creditList]) - let credit = mutations.createCredit(users[user]['creditList'][creditList]) - let sum = mutations.createSum(credit, amount) - list[creditList] = [{...credit}, {...amount}, {...sum}] - } - - let existUser = state.users.find(a => {return a.username === user}) - - // eslint-disable-next-line no-console - console.log(existUser) - if (existUser) { - existUser.username = users[user].username - existUser.firstname = users[user].firstname - existUser.lastname = users[user].lastname - existUser.limit = users[user].limit - existUser.locked = users[user].locked - existUser.autoLock = users[user].autoLock - existUser.creditList = list - } else { - state.users.push({ - username: users[user].username, - firstname: users[user].firstname, - lastname: users[user].lastname, - limit: users[user].limit, - locked: users[user].locked, - autoLock: users[user].autoLock, - creditList: list, - expand: false - }) - } - } - mutations.sortUsers(state) - - // eslint-disable-next-line no-console - console.log(state.users) - }, - createAmount(creditList) { - let amount = { - type:'Schulden', - jan_amount: 0 - creditList.jan.depts, - feb_amount: 0 - creditList.feb.depts, - maer_amount: 0 - creditList.maer.depts, - apr_amount:0 - creditList.apr.depts, - mai_amount: 0 - creditList.mai.depts, - jun_amount: 0 - creditList.jun.depts, - jul_amount: 0 - creditList.jul.depts, - aug_amount: 0 - creditList.aug.depts, - sep_amount: 0 - creditList.sep.depts, - okt_amount: 0 - creditList.okt.depts, - nov_amount: 0 - creditList.nov.depts, - dez_amount: 0 - creditList.dez.depts, - last: 0 - creditList['last'] - } - - amount.sum = amount.jan_amount + amount.feb_amount + amount.maer_amount + amount.apr_amount + amount.mai_amount + amount.jun_amount + amount.jul_amount + amount.aug_amount + amount.sep_amount + amount.okt_amount + amount.nov_amount + amount.dez_amount - return amount - }, - createCredit(creditList) { - let credit = { - type:'Guthaben', - jan_amount: creditList.jan.credit, - feb_amount: creditList.feb.credit, - maer_amount: creditList.maer.credit, - apr_amount: creditList.apr.credit, - mai_amount: creditList.mai.credit, - jun_amount: creditList.jun.credit, - jul_amount: creditList.jul.credit, - aug_amount: creditList.aug.credit, - sep_amount: creditList.sep.credit, - okt_amount: creditList.okt.credit, - nov_amount: creditList.nov.credit, - dez_amount: creditList.dez.credit - } - credit.sum = credit.jan_amount + credit.feb_amount + credit.maer_amount + credit.apr_amount + credit.mai_amount + credit.jun_amount + credit.jul_amount + credit.aug_amount + credit.sep_amount + credit.okt_amount + credit.nov_amount + credit.dez_amount - return credit - }, - createSum(credit, amount) { - let sum = { - type:'Summe', - jan_amount: credit.jan_amount + amount.jan_amount, - feb_amount: credit.feb_amount + amount.feb_amount, - maer_amount: credit.maer_amount + amount.maer_amount, - apr_amount: credit.apr_amount + amount.apr_amount, - mai_amount: credit.mai_amount + amount.mai_amount, - jun_amount: credit.jun_amount + amount.jun_amount, - jul_amount: credit.jul_amount + amount.jul_amount, - aug_amount: credit.aug_amount + amount.aug_amount, - sep_amount: credit.sep_amount + amount.sep_amount, - okt_amount: credit.okt_amount + amount.okt_amount, - nov_amount: credit.nov_amount + amount.nov_amount, - dez_amount: credit.dez_amount + amount.dez_amount, - } - sum.sum = sum.jan_amount + sum.feb_amount + sum.maer_amount + sum.apr_amount + sum.mai_amount + sum.jun_amount + sum.jul_amount + sum.aug_amount + sum.sep_amount + sum.okt_amount + sum.nov_amount + sum.dez_amount - return sum - }, - 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 - }) - }, - updateUsers: (state, data) => { - let index = state.users.indexOf(state.users.find(a => {return a.username === data.username})) - if (data.creditLists !== undefined) { - let list = {} - for (let creditList in data.creditLists) { - let amount = mutations.createAmount(data.creditLists[creditList]) - let credit = mutations.createCredit(data.creditLists[creditList]) - let sum = mutations.createSum(credit, amount) - list[creditList] = [{...credit}, {...amount}, {...sum}] - } - state.users[index].creditList = list - } - if (data.locked !== undefined) state.users[index].locked = data.locked - if (data.limit !== undefined) state.users[index].limit = data.limit - if (data.autoLock !== undefined) state.users[index].autoLock = data.autoLock - }, - setMails: (state, data) => { - state.errorMails = data - }, - setMail: (state, data) => { - state.errorMail = data - }, - setYears: (state) => { - for (let year = new Date().getFullYear(); year >= 2000; year--) { - state.years.push({value: year, text: year}) - } - }, - setYear: (state, value) => { - if(value) state.year++ - else state.year-- + 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 } -}; + }, + setActiveUser: (state, user) => { + if (state.activeUser.username === user.username) { + state.activeUser = { username: null } + } else { + state.activeUser = user + } + state.errorMail = null + }, + setUsers: (state, users) => { + // eslint-disable-next-line no-console + console.log('users', users) + for (let user in users) { + // eslint-disable-next-line no-console + console.log('user', user) + let list = {} + for (let creditList in users[user]['creditList']) { + let amount = mutations.createAmount( + users[user]['creditList'][creditList] + ) + let credit = mutations.createCredit( + users[user]['creditList'][creditList] + ) + let sum = mutations.createSum(credit, amount) + list[creditList] = [{ ...credit }, { ...amount }, { ...sum }] + } + + let existUser = state.users.find(a => { + return a.username === user + }) + + // eslint-disable-next-line no-console + console.log(existUser) + if (existUser) { + existUser.username = users[user].username + existUser.firstname = users[user].firstname + existUser.lastname = users[user].lastname + existUser.limit = users[user].limit + existUser.locked = users[user].locked + existUser.autoLock = users[user].autoLock + existUser.creditList = list + } else { + state.users.push({ + username: users[user].username, + firstname: users[user].firstname, + lastname: users[user].lastname, + limit: users[user].limit, + locked: users[user].locked, + autoLock: users[user].autoLock, + creditList: list, + expand: false + }) + } + } + mutations.sortUsers(state) + + // eslint-disable-next-line no-console + console.log(state.users) + }, + createAmount(creditList) { + let amount = { + type: 'Schulden', + jan_amount: 0 - creditList.jan.depts, + feb_amount: 0 - creditList.feb.depts, + maer_amount: 0 - creditList.maer.depts, + apr_amount: 0 - creditList.apr.depts, + mai_amount: 0 - creditList.mai.depts, + jun_amount: 0 - creditList.jun.depts, + jul_amount: 0 - creditList.jul.depts, + aug_amount: 0 - creditList.aug.depts, + sep_amount: 0 - creditList.sep.depts, + okt_amount: 0 - creditList.okt.depts, + nov_amount: 0 - creditList.nov.depts, + dez_amount: 0 - creditList.dez.depts, + last: 0 - creditList['last'] + } + + amount.sum = + amount.jan_amount + + amount.feb_amount + + amount.maer_amount + + amount.apr_amount + + amount.mai_amount + + amount.jun_amount + + amount.jul_amount + + amount.aug_amount + + amount.sep_amount + + amount.okt_amount + + amount.nov_amount + + amount.dez_amount + return amount + }, + createCredit(creditList) { + let credit = { + type: 'Guthaben', + jan_amount: creditList.jan.credit, + feb_amount: creditList.feb.credit, + maer_amount: creditList.maer.credit, + apr_amount: creditList.apr.credit, + mai_amount: creditList.mai.credit, + jun_amount: creditList.jun.credit, + jul_amount: creditList.jul.credit, + aug_amount: creditList.aug.credit, + sep_amount: creditList.sep.credit, + okt_amount: creditList.okt.credit, + nov_amount: creditList.nov.credit, + dez_amount: creditList.dez.credit + } + credit.sum = + credit.jan_amount + + credit.feb_amount + + credit.maer_amount + + credit.apr_amount + + credit.mai_amount + + credit.jun_amount + + credit.jul_amount + + credit.aug_amount + + credit.sep_amount + + credit.okt_amount + + credit.nov_amount + + credit.dez_amount + return credit + }, + createSum(credit, amount) { + let sum = { + type: 'Summe', + jan_amount: credit.jan_amount + amount.jan_amount, + feb_amount: credit.feb_amount + amount.feb_amount, + maer_amount: credit.maer_amount + amount.maer_amount, + apr_amount: credit.apr_amount + amount.apr_amount, + mai_amount: credit.mai_amount + amount.mai_amount, + jun_amount: credit.jun_amount + amount.jun_amount, + jul_amount: credit.jul_amount + amount.jul_amount, + aug_amount: credit.aug_amount + amount.aug_amount, + sep_amount: credit.sep_amount + amount.sep_amount, + okt_amount: credit.okt_amount + amount.okt_amount, + nov_amount: credit.nov_amount + amount.nov_amount, + dez_amount: credit.dez_amount + amount.dez_amount + } + sum.sum = + sum.jan_amount + + sum.feb_amount + + sum.maer_amount + + sum.apr_amount + + sum.mai_amount + + sum.jun_amount + + sum.jul_amount + + sum.aug_amount + + sum.sep_amount + + sum.okt_amount + + sum.nov_amount + + sum.dez_amount + return sum + }, + 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 + }) + }, + updateUsers: (state, data) => { + let index = state.users.indexOf( + state.users.find(a => { + return a.username === data.username + }) + ) + if (data.creditLists !== undefined) { + let list = {} + for (let creditList in data.creditLists) { + let amount = mutations.createAmount(data.creditLists[creditList]) + let credit = mutations.createCredit(data.creditLists[creditList]) + let sum = mutations.createSum(credit, amount) + list[creditList] = [{ ...credit }, { ...amount }, { ...sum }] + } + state.users[index].creditList = list + } + if (data.locked !== undefined) state.users[index].locked = data.locked + if (data.limit !== undefined) state.users[index].limit = data.limit + if (data.autoLock !== undefined) state.users[index].autoLock = data.autoLock + }, + setMails: (state, data) => { + state.errorMails = data + }, + setMail: (state, data) => { + state.errorMail = data + }, + setYears: state => { + for (let year = new Date().getFullYear(); year >= 2000; year--) { + state.years.push({ value: year, text: year }) + } + }, + setYear: (state, value) => { + if (value) state.year++ + else state.year-- + } +} const actions = { - // eslint-disable-next-line no-unused-vars - async getAllUsers({commit, rootState, dispatch}) { - // eslint-disable-next-line no-console - console.log(rootState) - try { - const response = await axios.post(url.searchUser, {searchString: ""}, {headers: {Token: rootState.login.user.accessToken}}) - commit('setAllUsers', response.data) - } catch (err) { - // eslint-disable-next-line no-console - if (err.response) if (err.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - async getUsers({commit, rootState, dispatch}) { - try { - const response = await axios.get(url.getFinanzerMain, {headers: {Token: rootState.login.user.accessToken}}) - // eslint-disable-next-line no-console - console.log('response', response.data) - commit('setUsers', response.data) - } catch (err) { - // eslint-disable-next-line no-console - console.log(err) - if (err.response) if (err.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - setActiveUser({ commit }, user) { - commit('setActiveUser', user) - }, - async addAmount({commit, rootState, dispatch}, data) { - try { - const response = await axios.post(url.finanzerAddAmount, {userId: data.user.username, amount: data.amount * 100, year: data.year, month: data.month}, {headers: {Token: rootState.login.user.accessToken}}) - const creditLists = {...response.data} - delete creditLists.locked - commit('updateUsers', {creditLists: creditLists, locked: response.data.locked, username: data.user.username}) - } catch (err) { - if (err.response) if (err.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - async addCredit({commit, rootState, dispatch}, data) { - try { - const response = await axios.post(url.finanzerAddCredit, {userId: data.user.username, credit: data.credit * 100, year: data.year, month: data.month}, {headers: {Token: rootState.login.user.accessToken}}) - const creditLists = {...response.data} - delete creditLists.locked - commit('updateUsers', {creditLists: creditLists, locked: response.data.locked, username: data.user.username}) - } catch (err) { - if (err.response) if (err.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - async doLock({commit, rootState, dispatch}, data) { - try { - const response = await axios.post(url.lockUser, {userId: data.user.username, locked: data.locked}, {headers: {Token: rootState.login.user.accessToken}}) - commit('updateUsers', response.data) - } catch (e) { - if (e.response) if(e.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - async saveConfig({commit, rootState, dispatch}, data) { - try { - const response = await axios.post(url.finanzerSetConfig, {userId: data.user.username, limit: data.limit * 100, autoLock: data.autoLock}, {headers: {Token: rootState.login.user.accessToken}}) - commit('updateUsers', response.data) - } catch (e) { - if (e.response) if(e.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - async addUser({commit, rootState, dispatch}, data) { - try { - const response = await axios.post(url.finanzerAddUser, {userId: data.username}, {headers: {Token: rootState.login.user.accessToken}}) - commit('setUsers', response.data) - } catch (e) { - if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - async sendMails({commit, rootState, dispatch}) { - try { - const response = await axios.get(url.finanzerSendAllMail, {headers: {Token: rootState.login.user.accessToken}}) - commit('setMails', response.data) - } catch (e) { - if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - async sendMail({commit, rootState, dispatch}, data) { - try { - const response = await axios.post(url.finanzerSendOneMail, {userId: data.username}, {headers: {Token: rootState.login.user.accessToken}}) - commit('setMail', response.data) - } catch (e) { - if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) - } - }, - createYears({commit}) { - commit('setYears') - return 'hallo' - }, - countYear({commit}, value) { - commit('setYear', value) + // eslint-disable-next-line no-unused-vars + async getAllUsers({ commit, rootState, dispatch }) { + // eslint-disable-next-line no-console + console.log(rootState) + try { + const response = await axios.post( + url.searchUser, + { searchString: '' }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('setAllUsers', response.data) + } catch (err) { + // eslint-disable-next-line no-console + if (err.response) + if (err.response.status === 401) + dispatch('logout', null, { root: true }) } -}; + }, + async getUsers({ commit, rootState, dispatch }) { + try { + const response = await axios.get(url.getFinanzerMain, { + headers: { Token: rootState.login.user.accessToken } + }) + // eslint-disable-next-line no-console + console.log('response', response.data) + commit('setUsers', response.data) + } catch (err) { + // eslint-disable-next-line no-console + console.log(err) + if (err.response) + if (err.response.status === 401) + dispatch('logout', null, { root: true }) + } + }, + setActiveUser({ commit }, user) { + commit('setActiveUser', user) + }, + async addAmount({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.finanzerAddAmount, + { + userId: data.user.username, + amount: data.amount * 100, + year: data.year, + month: data.month + }, + { headers: { Token: rootState.login.user.accessToken } } + ) + const creditLists = { ...response.data } + delete creditLists.locked + commit('updateUsers', { + creditLists: creditLists, + locked: response.data.locked, + username: data.user.username + }) + } catch (err) { + if (err.response) + if (err.response.status === 401) + dispatch('logout', null, { root: true }) + } + }, + async addCredit({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.finanzerAddCredit, + { + userId: data.user.username, + credit: data.credit * 100, + year: data.year, + month: data.month + }, + { headers: { Token: rootState.login.user.accessToken } } + ) + const creditLists = { ...response.data } + delete creditLists.locked + commit('updateUsers', { + creditLists: creditLists, + locked: response.data.locked, + username: data.user.username + }) + } catch (err) { + if (err.response) + if (err.response.status === 401) + dispatch('logout', null, { root: true }) + } + }, + async doLock({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.lockUser, + { userId: data.user.username, locked: data.locked }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updateUsers', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async saveConfig({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.finanzerSetConfig, + { + userId: data.user.username, + limit: data.limit * 100, + autoLock: data.autoLock + }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updateUsers', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async addUser({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.finanzerAddUser, + { userId: data.username }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('setUsers', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async sendMails({ commit, rootState, dispatch }) { + try { + const response = await axios.get(url.finanzerSendAllMail, { + headers: { Token: rootState.login.user.accessToken } + }) + commit('setMails', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async sendMail({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.finanzerSendOneMail, + { userId: data.username }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('setMail', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + createYears({ commit }) { + commit('setYears') + return 'hallo' + }, + countYear({ commit }, value) { + commit('setYear', value) + } +} const getters = { - users: state => { return state.users }, - activeUser: state => { return state.activeUser }, - allUsers: state => { return state.allUsers }, - user: state => { return state.user }, - errorMails: state => { return state.errorMails }, - errorMail: state => { return state.errorMail }, - years: state => { return state.years }, - selectYears: state => {return state.years}, - year: state => { return state.year }, - months: state => { return state.months}, - - -}; + users: state => { + return state.users + }, + activeUser: state => { + return state.activeUser + }, + allUsers: state => { + return state.allUsers + }, + user: state => { + return state.user + }, + errorMails: state => { + return state.errorMails + }, + errorMail: state => { + return state.errorMail + }, + years: state => { + return state.years + }, + selectYears: state => { + return state.years + }, + year: state => { + return state.year + }, + months: state => { + return state.months + } +} export default { - namespaced: true, - state, - mutations, - actions, - getters + namespaced: true, + state, + mutations, + actions, + getters } diff --git a/src/store/modules/login.js b/src/store/modules/login.js index fa0eae0..8604395 100644 --- a/src/store/modules/login.js +++ b/src/store/modules/login.js @@ -1,98 +1,107 @@ -import axios from 'axios'; -import router from "@/router"; +import axios from 'axios' +import router from '@/router' import url from '@/plugins/routes' const state = { - user: { + user: { + username: null, + accessToken: null, + group: null + }, + loggingIn: false, + loginError: null +} + +const mutations = { + loginStart: state => (state.loggingIn = true), + loginStop(state, errorMessage) { + state.loggingIn = false + state.loginError = errorMessage + }, + updateAccessToken(state, data) { + if (typeof data === typeof '') { + data = JSON.parse(data) + } + if (data === null || data === undefined) { + state.user.username = null + state.user.accessToken = null + state.user.group = null + } else { + state.user.username = data.username + state.user.accessToken = data.accessToken + state.user.group = data.group + } + }, + logout(state) { + state.user.accessToken = null + state.user.username = null + state.user.group = null + } +} + +const actions = { + async doLogin({ commit }, loginData) { + commit('loginStart') + try { + const response = await axios.post(url.login, { ...loginData }) + localStorage.setItem( + 'user', + JSON.stringify({ + username: response.data.username, + accessToken: response.data.token, + group: response.data.group + }) + ) + commit('loginStop', null) + commit('updateAccessToken', response.data) + if (state.user.group.includes('moneymaster')) { + router.push('/finanzer') + } else if (state.user.group.includes('bar')) { + router.push('/bar') + } + } catch (err) { + commit('loginStop', err.response.data.error) + commit('updateAccessToken', { username: null, accessToken: null, group: null - }, - loggingIn: false, - loginError: null -}; - -const mutations = { - loginStart: state => state.loggingIn = true, - loginStop (state, errorMessage){ - state.loggingIn = false; - state.loginError = errorMessage; - }, - updateAccessToken (state, data) { - if (typeof(data) === typeof("")) { - data = JSON.parse(data) - } - if (data === null || data === undefined) { - state.user.username = null; - state.user.accessToken = null; - state.user.group = null; - } else { - state.user.username = data.username; - state.user.accessToken = data.accessToken; - state.user.group = data.group; - } - }, - logout (state) { - state.user.accessToken = null; - state.user.username = null; - state.user.group = null; + }) } -}; - -const actions = { - async doLogin({ commit }, loginData) { - commit('loginStart'); - try { - const response = await axios.post(url.login, {...loginData}) - localStorage.setItem('user', JSON.stringify({ username: response.data.username, accessToken: response.data.token, group: response.data.group})); - commit('loginStop', null); - commit('updateAccessToken', response.data) - if (state.user.group.includes('moneymaster')) { - router.push('/finanzer'); - } - else if (state.user.group.includes('bar')) { - router.push('/bar') - } - - } catch (err) { - commit('loginStop', err.response.data.error) - commit('updateAccessToken', {username: null, accessToken: null, group: null}) - } - }, - fetchAccessToken({ commit }) { - commit('updateAccessToken', localStorage.getItem('user')) - }, - logout({ commit }) { - localStorage.removeItem('user'); - commit('logout'); - router.push('/login'); - }, - resetLoginError({ commit }) { - commit("loginStop") - } -}; + }, + fetchAccessToken({ commit }) { + commit('updateAccessToken', localStorage.getItem('user')) + }, + logout({ commit }) { + localStorage.removeItem('user') + commit('logout') + router.push('/login') + }, + resetLoginError({ commit }) { + commit('loginStop') + } +} const getters = { - getGroup: state => { - return state.user.group - }, - group: state => { - return state.user.group - }, - getToken: state => { - return state.user.accessToken - }, - token: state => { - return state.user.accessToken - }, - loginError: state => { - return state.loginError - } -}; + getGroup: state => { + return state.user.group + }, + group: state => { + return state.user.group + }, + getToken: state => { + return state.user.accessToken + }, + token: state => { + return state.user.accessToken + }, + loginError: state => { + return state.loginError + } +} export default { - state, - mutations, - actions, - getters -}; + state, + mutations, + actions, + getters +} diff --git a/src/views/BarView.vue b/src/views/BarView.vue index 8ce1bba..04a38a2 100644 --- a/src/views/BarView.vue +++ b/src/views/BarView.vue @@ -1,34 +1,29 @@ diff --git a/src/views/FinanzerView.vue b/src/views/FinanzerView.vue index 34c64c4..067fd84 100644 --- a/src/views/FinanzerView.vue +++ b/src/views/FinanzerView.vue @@ -1,82 +1,100 @@ diff --git a/src/views/Home.vue b/src/views/Home.vue index 2a8d522..d076a9f 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,13 +1,13 @@