diff --git a/package.json b/package.json index 775126e..bce46ff 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,9 @@ "@vue/prettier", "eslint:recommended" ], - "rules": {}, + "rules": { + "no-console": "off" + }, "parserOptions": { "parser": "babel-eslint" } diff --git a/src/App.vue b/src/App.vue index 164699d..58a0a74 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,18 +1,20 @@ diff --git a/src/components/user/AddAmount.vue b/src/components/user/AddAmount.vue new file mode 100644 index 0000000..e60dfb4 --- /dev/null +++ b/src/components/user/AddAmount.vue @@ -0,0 +1,132 @@ + + + + + diff --git a/src/components/user/CreditOverview.vue b/src/components/user/CreditOverview.vue new file mode 100644 index 0000000..01c0cbe --- /dev/null +++ b/src/components/user/CreditOverview.vue @@ -0,0 +1,107 @@ + + + + + diff --git a/src/plugins/routes.js b/src/plugins/routes.js index 4a9c8a2..b4862fe 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -15,7 +15,9 @@ const url = { finanzerSetConfig: main + 'finanzerSetConfig', finanzerAddUser: main + 'finanzerAddUser', finanzerSendAllMail: main + 'finanzerSendAllMail', - finanzerSendOneMail: main + 'finanzerSendOneMail' + finanzerSendOneMail: main + 'finanzerSendOneMail', + userMain: main + 'user/main', + userAddAmount: main + 'user/addAmount' } export default url diff --git a/src/router/index.js b/src/router/index.js index e7f546e..013404d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,7 +3,12 @@ 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 GeruechteView from '../views/contents/GeruechteView' +import AddAmount from '../components/user/AddAmount' +import CreditOverview from '../components/user/CreditOverview' +import MainView from '../views/MainView' +import UserView from '../views/UserView' +import BarView from '../views/BarView' Vue.use(VueRouter) @@ -19,9 +24,45 @@ const routes = [ component: FinanzerView }, { - path: '/bar', - name: 'bar', - component: BarView + path: '/main', + name: 'main', + component: MainView, + children: [ + { + path: 'user', + name: 'user', + component: UserView, + children: [ + { + path: 'add', + name: 'add', + component: AddAmount + }, + { + path: 'overview', + name: 'userOverview', + component: CreditOverview + } + ] + }, + { + path: 'bar', + name: 'bar', + component: BarView, + children: [ + { + path: 'geruecht', + name: 'geruecht', + component: GeruechteView + } + ] + }, + { + path: 'finanzer', + name: 'finanzer', + component: FinanzerView + } + ] }, { path: '*', @@ -39,18 +80,23 @@ const router = new VueRouter({ router.beforeEach((to, from, next) => { store.dispatch('fetchAccessToken') - let sites = ['/finanzer', '/bar'] - if (sites.includes(to.fullPath)) { - if (to.fullPath === '/finanzer') { + console.log('fullPath', to.fullPath) + if (to.fullPath.includes('/main')) { + if (to.fullPath.includes('/main/finanzer')) { if (!store.state.login.user.group.includes('moneymaster')) { next('/login') } } - if (to.fullPath === '/bar') { + if (to.fullPath.includes('/main/bar')) { if (!store.state.login.user.group.includes('bar')) { next('/login') } } + if (to.fullPath.includes('/main/user')) { + if (!store.state.login.user.group.includes('user')) { + next('/login') + } + } if (!store.state.login.user.accessToken) { next('/login') } @@ -58,9 +104,11 @@ router.beforeEach((to, from, next) => { if (to.fullPath === '/login') { if (store.state.login.user.accessToken) { if (store.state.login.user.group.includes('moneymaster')) { - next('/finanzer') + next('/main/finanzer') } else if (store.state.login.user.group.includes('bar')) { - next('/bar') + next('/main/bar/geruecht') + } else if (store.state.login.user.group.includes('user')) { + next('/main/user/add') } } } diff --git a/src/store/index.js b/src/store/index.js index e8ca7be..8687346 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,6 +3,7 @@ import Vuex from 'vuex' import login from './modules/login' import finanzerUsers from './modules/finanzerUsers' import barUsers from '@/store/modules/barUsers' +import user from '@/store/modules/user' Vue.use(Vuex) @@ -10,6 +11,7 @@ export default new Vuex.Store({ modules: { login, finanzerUsers, - barUsers + barUsers, + user } }) diff --git a/src/store/modules/login.js b/src/store/modules/login.js index 8604395..7abbb6d 100644 --- a/src/store/modules/login.js +++ b/src/store/modules/login.js @@ -55,9 +55,11 @@ const actions = { commit('loginStop', null) commit('updateAccessToken', response.data) if (state.user.group.includes('moneymaster')) { - router.push('/finanzer') + router.push('/main/finanzer') } else if (state.user.group.includes('bar')) { - router.push('/bar') + router.push('/main/bar/geruecht') + } else if (state.user.group.includes('user')) { + router.push('/main/user/add') } } catch (err) { commit('loginStop', err.response.data.error) @@ -96,6 +98,30 @@ const getters = { }, loginError: state => { return state.loginError + }, + isBar: state => { + try { + return state.user.group.includes('bar') ? true : false + } catch (e) { + return false + } + }, + isFinanzer: state => { + try { + return state.user.group.includes('moneymaster') ? true : false + } catch (e) { + return false + } + }, + isUser: state => { + try { + return state.user.group.includes('user') ? true : false + } catch (e) { + return false + } + }, + isLoggedIn: state => { + return state.user.accessToken ? true : false } } diff --git a/src/store/modules/user.js b/src/store/modules/user.js new file mode 100644 index 0000000..4118304 --- /dev/null +++ b/src/store/modules/user.js @@ -0,0 +1,168 @@ +import axios from 'axios' +import url from '@/plugins/routes' + +const state = { + user: null, + creditList: [] +} + +const mutations = { + setUser: (state, user) => { + state.user = user + let list = {} + for (let creditList in user['creditList']) { + console.log(creditList) + let amount = mutations.createAmount(user['creditList'][creditList]) + let credit = mutations.createCredit(user['creditList'][creditList]) + let sum = mutations.createSum(credit, amount) + list[creditList] = [{ ...credit }, { ...amount }, { ...sum }] + } + state.user.creditList = list + state.creditList = [] + console.log(state.user) + }, + 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 + } +} + +const actions = { + async getUser({ commit, rootState, dispatch }) { + try { + const response = await axios.get(url.userMain, { + headers: { Token: rootState.login.user.accessToken } + }) + commit('setUser', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async addAmount({ commit, rootState, dispatch }, amount) { + try { + const response = await axios.post( + url.userAddAmount, + { amount: amount }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('setUser', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + } +} + +const getters = { + user: state => { + return state.user + }, + year: state => { + let year = 0 + for (let creditList in state.user.creditList) { + let currentYear = parseInt(creditList) + if (currentYear > year) year = currentYear + } + return year + } +} + +export default { + namespaced: true, + state, + mutations, + actions, + getters +} diff --git a/src/views/BarView.vue b/src/views/BarView.vue index 04a38a2..3487f61 100644 --- a/src/views/BarView.vue +++ b/src/views/BarView.vue @@ -1,29 +1,13 @@ - + diff --git a/src/views/FinanzerView.vue b/src/views/FinanzerView.vue index 067fd84..302413a 100644 --- a/src/views/FinanzerView.vue +++ b/src/views/FinanzerView.vue @@ -1,7 +1,14 @@