From f0a2231a5b02f157e5c01c6320718e3caac9df9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 1 Mar 2020 19:18:58 +0100 Subject: [PATCH] finished ##172 edit and add pricelist edit and add drinktypes --- src/components/TitleBar.vue | 10 +- .../finanzer/FinanzerNavigation.vue | 19 +- src/components/gastro/GastroNavigation.vue | 28 ++ src/components/pricelist/PriceList.vue | 471 ++++++++++++++++-- .../vorstand/ManagementNavigation.vue | 26 + src/components/vorstand/ServiceManagement.vue | 97 ++-- src/plugins/routes.js | 13 +- src/router/index.js | 38 +- src/store/modules/login.js | 22 +- src/store/modules/pricelist.js | 167 ++++++- src/views/MainView.vue | 28 +- src/views/contents/PriceListView.vue | 17 + 12 files changed, 798 insertions(+), 138 deletions(-) create mode 100644 src/components/gastro/GastroNavigation.vue create mode 100644 src/components/vorstand/ManagementNavigation.vue create mode 100644 src/views/contents/PriceListView.vue diff --git a/src/components/TitleBar.vue b/src/components/TitleBar.vue index 23ee238..3876b0c 100644 --- a/src/components/TitleBar.vue +++ b/src/components/TitleBar.vue @@ -8,6 +8,9 @@ {{attach_money}} + + {{gastro}} + {{local_bar}} @@ -22,7 +25,7 @@ + + diff --git a/src/components/pricelist/PriceList.vue b/src/components/pricelist/PriceList.vue index 5636d3b..25ec347 100644 --- a/src/components/pricelist/PriceList.vue +++ b/src/components/pricelist/PriceList.vue @@ -1,10 +1,10 @@ diff --git a/src/components/vorstand/ManagementNavigation.vue b/src/components/vorstand/ManagementNavigation.vue new file mode 100644 index 0000000..8db8cf6 --- /dev/null +++ b/src/components/vorstand/ManagementNavigation.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/src/components/vorstand/ServiceManagement.vue b/src/components/vorstand/ServiceManagement.vue index d951ba3..1e4d562 100644 --- a/src/components/vorstand/ServiceManagement.vue +++ b/src/components/vorstand/ServiceManagement.vue @@ -1,51 +1,49 @@ @@ -100,7 +98,12 @@ export default { for (var week in this.month) { for (var dayint in this.month[week].days) { var day = this.month[week].days[dayint] - this.lockDay({year: day.date.getFullYear(), month: day.date.getMonth() + 1, day: day.date.getDate(), locked: value}) + this.lockDay({ + year: day.date.getFullYear(), + month: day.date.getMonth() + 1, + day: day.date.getDate(), + locked: value + }) } } } diff --git a/src/plugins/routes.js b/src/plugins/routes.js index c982777..86df7f1 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -1,11 +1,12 @@ //const main = 'https://192.168.5.128:5000/' //const main = 'http://localhost:5000/' -//const main = 'http://192.168.5.118:5000/' -const main = 'https://groeger-clan.duckdns.org:5000/' +const main = 'http://192.168.5.118:5000/' +//const main = 'https://groeger-clan.duckdns.org:5000/' const url = { login: main + 'login', pricelist: main + 'pricelist', + getTypes: main + 'drinkTypes', getFinanzerMain: main + 'getFinanzerMain', bar: main + 'bar', barGetUser: main + 'barGetUser', @@ -43,6 +44,14 @@ const url = { }, barU: { storno: main + 'bar/storno' + }, + gastro: { + setDrink: main + 'gastro/setDrink', + updateDrink: main + 'gastro/updateDrink', + deleteDrink: main + 'gastro/deleteDrink', + setType: main + 'gastro/setDrinkType', + updateType: main + 'gastro/updateDrinkType', + deleteType: main + 'gastro/deleteDrinkType' } } diff --git a/src/router/index.js b/src/router/index.js index a996d80..2a9774f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -18,7 +18,10 @@ import ServiceManagement from '../components/vorstand/ServiceManagement' import Config from '@/components/user/Config' import Jobs from '@/components/user/Jobs' import JobRequests from '@/components/user/JobRequests' -import PriceList from "@/components/pricelist/PriceList"; +import PriceList from '@/components/pricelist/PriceList' +import ManagementNavigation from "@/components/vorstand/ManagementNavigation"; +import GastroNavigation from "@/components/gastro/GastroNavigation"; +import PriceListView from "@/views/contents/PriceListView"; Vue.use(VueRouter) @@ -26,7 +29,7 @@ const routes = [ { path: '/pricelist', name: 'priceListNoLogin', - component: PriceList + component: PriceListView }, { path: '/login', @@ -38,10 +41,21 @@ const routes = [ name: 'main', component: MainView, children: [ + { + path: 'management', + name: 'management', + components: { nav: ManagementNavigation, default: BarView}, + children: [ + { + path: 'servicemanagement', + component: ServiceManagement + } + ] + }, { path: 'user', name: 'user', - components: { userNav: UserNavigation, default: UserView }, + components: { nav: UserNavigation, default: UserView }, children: [ { path: 'add', @@ -73,7 +87,7 @@ const routes = [ { path: 'bar', name: 'bar', - components: { userNav: BarNavigation, default: BarView }, + components: { nav: BarNavigation, default: BarView }, children: [ { path: 'geruecht', @@ -85,7 +99,7 @@ const routes = [ { path: 'finanzer', name: 'finanzer', - components: { default: FinanzerView, finanzerNav: FinanzerNavigation }, + components: { default: FinanzerView, nav: FinanzerNavigation }, children: [ { path: 'overview', @@ -96,10 +110,18 @@ const routes = [ name: 'activeUser', props: true, component: User - }, + } + ] + }, + { + path: 'gastro', + name: 'gastro', + components: { nav: GastroNavigation, default: BarView}, + children: [ { - path: 'servicemanagement', - component: ServiceManagement + path: 'pricelist', + name: 'gastroPricelist', + component: PriceList } ] } diff --git a/src/store/modules/login.js b/src/store/modules/login.js index 4f778a9..2575952 100644 --- a/src/store/modules/login.js +++ b/src/store/modules/login.js @@ -115,27 +115,41 @@ const getters = { }, isBar: state => { try { - return state.user.group.includes('bar') ? true : false + return state.user.group.includes('bar') } catch (e) { return false } }, isFinanzer: state => { try { - return state.user.group.includes('moneymaster') ? true : false + return state.user.group.includes('moneymaster') } catch (e) { return false } }, isUser: state => { try { - return state.user.group.includes('user') ? true : false + return state.user.group.includes('user') + } catch (e) { + return false + } + }, + isGastro: state => { + try { + return state.user.group.includes('gastro') + } catch (e) { + return false + } + }, + isManagement: state => { + try { + return state.user.group.includes('management') || state.user.group.includes('gastro') || state.user.group.includes('moneymaster') } catch (e) { return false } }, isLoggedIn: state => { - return state.user.accessToken ? true : false + return state.user.accessToken }, user: state => { return state.user diff --git a/src/store/modules/pricelist.js b/src/store/modules/pricelist.js index 67f0461..79df600 100644 --- a/src/store/modules/pricelist.js +++ b/src/store/modules/pricelist.js @@ -2,12 +2,87 @@ import url from '@/plugins/routes' import axios from 'axios' const state = { - priceList: [] + priceList: [], + types: [] } const mutations = { setPriceList: (state, priceList) => { state.priceList = priceList + }, + setTypes: (state, types) => { + state.types = types + state.types.sort((a, b) => { + const low = b.name.toLowerCase() + const high = a.name.toLowerCase() + if (high < low) return -1 + if (high > low) return 1 + return 0 + }) + }, + updatePriceList: (state, drink) => { + var a = state.priceList.find(b => { + return b.id === drink.id + }) + if (a) { + a.name = drink.name + a.type = drink.type + a.price = drink.price + a.price_big = drink.price_big + a.price_club = drink.price_club + a.price_club_big = drink.price_club_big + a.premium = drink.premium + a.premium_club = drink.premium_club + a.price_extern_club = drink.price_extern_club + } else { + state.priceList.push({ + id: drink.id, + name: drink.name, + type: drink.type, + price: drink.price, + price_big: drink.price_big, + price_club: drink.price_club, + price_club_big: drink.price_club_big, + premium: drink.premium, + premium_club: drink.premium_club, + price_extern_club: drink.price_extern_club + }) + } + }, + deleteDrinkPrice: (state, data) => { + var index = state.priceList.indexOf( + state.priceList.find(a => { + return a.id === data.id + }) + ) + state.priceList.splice(index, 1) + }, + updateDrinkType: (state, type) => { + var a = state.types.find(b => { + return b.id === type.id + }) + if (a) { + a.name = type.name + } else { + state.types.push({ + ...type + }) + } + state.types.sort((a, b) => { + const low = b.name.toLowerCase() + const high = a.name.toLowerCase() + if (high < low) return -1 + if (high > low) return 1 + return 0 + }) + }, + deleteDrinkType: (state, type) => { + var index = state.types.indexOf( + state.types.find(a => { + return a.id === type.id + }) + ) + state.types.splice(index, 1) } } @@ -19,12 +94,102 @@ const actions = { } catch (e) { console.log(e) } + }, + async getTypes({ commit, dispatch }) { + try { + const response = await axios.get(url.getTypes) + commit('setTypes', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async setDrink({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.gastro.setDrink, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updatePriceList', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async updateDrink({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.gastro.updateDrink, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updatePriceList', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async deleteDrink({ commit, rootState, dispatch }, data) { + try { + await axios.post( + url.gastro.deleteDrink, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('deleteDrinkPrice', data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async setDrinkType({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.gastro.setType, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updateDrinkType', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async updateDrinkType({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.gastro.updateType, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updateDrinkType', response.data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async deleteDrinkType({ commit, rootState, dispatch }, data) { + try { + await axios.post( + url.gastro.deleteType, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('deleteDrinkType', data) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } } } const getters = { priceList: state => { return state.priceList + }, + types: state => { + return state.types } } diff --git a/src/views/MainView.vue b/src/views/MainView.vue index 85b04f8..482c4ed 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -24,6 +24,22 @@ Bar + + + {{king}} + + + Vorstand + + + + + {{gastro}} + + + Gastro + + {{attach_money}} @@ -32,9 +48,7 @@ - - - +