From c0d57c6a713e68c1b4b4b120a0f7133ccd34aa86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 13 Feb 2021 14:11:25 +0100 Subject: [PATCH] [pricelist] add first commit for plugin (with errors) --- src/boot/plugins.ts | 2 +- src/flaschengeist.d.ts | 163 +++++++++++------- src/plugins/pricelist/components/Drink.vue | 125 ++++++++++++++ .../pricelist/components/DrinkTypes.vue | 133 ++++++++++++++ .../pricelist/components/Pricelist.vue | 67 +++++++ src/plugins/pricelist/pages/MainPage.vue | 37 ++++ src/plugins/pricelist/pages/Pricelist.vue | 15 ++ src/plugins/pricelist/pages/Settings.vue | 86 +++++++++ src/plugins/pricelist/plugin.ts | 25 +++ src/plugins/pricelist/routes/index.ts | 33 ++++ src/plugins/pricelist/store/drinks.ts | 106 ++++++++++++ 11 files changed, 727 insertions(+), 65 deletions(-) create mode 100644 src/plugins/pricelist/components/Drink.vue create mode 100644 src/plugins/pricelist/components/DrinkTypes.vue create mode 100644 src/plugins/pricelist/components/Pricelist.vue create mode 100644 src/plugins/pricelist/pages/MainPage.vue create mode 100644 src/plugins/pricelist/pages/Pricelist.vue create mode 100644 src/plugins/pricelist/pages/Settings.vue create mode 100644 src/plugins/pricelist/plugin.ts create mode 100644 src/plugins/pricelist/routes/index.ts create mode 100644 src/plugins/pricelist/store/drinks.ts diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index a5a198a..7807578 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -12,7 +12,7 @@ const config = { // Do not change required Modules !! requiredModules: ['User'], // here you can import plugins. - loadModules: ['Balance', 'Schedule'] + loadModules: ['Balance', 'Schedule', 'Pricelist'] }; // do not change anything here !! diff --git a/src/flaschengeist.d.ts b/src/flaschengeist.d.ts index dc3bc42..ec9cc9d 100644 --- a/src/flaschengeist.d.ts +++ b/src/flaschengeist.d.ts @@ -1,66 +1,101 @@ declare namespace FG { - interface Session { - expires: Date; - token: string; - lifetime: number; - browser: string; - platform: string; - userid: string; - } - interface User { - userid: string; - display_name: string; - firstname: string; - lastname: string; - mail: string; - birthday?: Date; - roles: Array; - permissions?: Array; - avatar_url?: string; - } - type Permission = string; - interface Role { - id: number; - name: string; - permissions: Array; - } - interface Transaction { - id: number; - time: Date; - amount: number; - reversal_id: number; - sender_id?: string; - receiver_id?: string; - author_id?: string; - original_id?: number; - } - interface Event { - id: number; - start: Date; - end: Date; - description?: string; - type: EventType; - jobs: Array; - } - interface EventType { - id: number; - name: string; - } - interface Job { - id: number; - start: Date; - end?: Date; - comment: string; - type: JobType; - services: Array; - required_services: number; - } - interface JobType { - id: number; - name: string; - } - interface Service { - userid: string; - value: number; - } + interface Session { + expires: Date; + token: string; + lifetime: number; + browser: string; + platform: string; + userid: string; + } + interface User { + userid: string; + display_name: string; + firstname: string; + lastname: string; + mail: string; + birthday?: any; + roles: Array; + permissions?: any; + avatar_url?: any; + } + type Permission = string; + interface Role { + id: number; + name: string; + permissions: Array; + } + interface Transaction { + id: number; + time: Date; + amount: number; + reversal_id: number; + sender_id?: any; + receiver_id?: any; + author_id?: any; + original_id?: any; + } + interface Drink { + id: number; + name: string; + volume: number; + cost_price: number; + discount: number; + extra_charge?: any; + prices: Array; + ingredients: Array; + tags: Array; + } + interface DrinkPrice { + id: number; + volume: number; + price: number; + no_auto: boolean; + public: boolean; + description?: any; + round_step: number; + } + interface DrinkType { + id: number; + name: string; + } + interface Ingredient { + id: number; + volume: number; + drink_parent_id: number; + drink_ingredient_id: number; + drink_ingredient?: any; + } + interface Tag { + id: number; + name: string; + } + interface Event { + id: number; + start: Date; + end: Date; + description?: any; + type: EventType; + jobs: Array; + } + interface EventType { + id: number; + name: string; + } + interface Job { + id: number; + start: Date; + end?: any; + comment: string; + type: JobType; + services: Array; + required_services: number; + } + interface JobType { + id: number; + name: string; + } + interface Service { + userid: string; + value: number; + } } diff --git a/src/plugins/pricelist/components/Drink.vue b/src/plugins/pricelist/components/Drink.vue new file mode 100644 index 0000000..e233b18 --- /dev/null +++ b/src/plugins/pricelist/components/Drink.vue @@ -0,0 +1,125 @@ + + + + + diff --git a/src/plugins/pricelist/components/DrinkTypes.vue b/src/plugins/pricelist/components/DrinkTypes.vue new file mode 100644 index 0000000..4daefeb --- /dev/null +++ b/src/plugins/pricelist/components/DrinkTypes.vue @@ -0,0 +1,133 @@ + + + + + diff --git a/src/plugins/pricelist/components/Pricelist.vue b/src/plugins/pricelist/components/Pricelist.vue new file mode 100644 index 0000000..d125fec --- /dev/null +++ b/src/plugins/pricelist/components/Pricelist.vue @@ -0,0 +1,67 @@ + + diff --git a/src/plugins/pricelist/pages/MainPage.vue b/src/plugins/pricelist/pages/MainPage.vue new file mode 100644 index 0000000..861457b --- /dev/null +++ b/src/plugins/pricelist/pages/MainPage.vue @@ -0,0 +1,37 @@ + + + diff --git a/src/plugins/pricelist/pages/Pricelist.vue b/src/plugins/pricelist/pages/Pricelist.vue new file mode 100644 index 0000000..8a79475 --- /dev/null +++ b/src/plugins/pricelist/pages/Pricelist.vue @@ -0,0 +1,15 @@ + + + + + diff --git a/src/plugins/pricelist/pages/Settings.vue b/src/plugins/pricelist/pages/Settings.vue new file mode 100644 index 0000000..7f2aea1 --- /dev/null +++ b/src/plugins/pricelist/pages/Settings.vue @@ -0,0 +1,86 @@ + + + + + diff --git a/src/plugins/pricelist/plugin.ts b/src/plugins/pricelist/plugin.ts new file mode 100644 index 0000000..a7b69b0 --- /dev/null +++ b/src/plugins/pricelist/plugin.ts @@ -0,0 +1,25 @@ +import { Module } from 'vuex'; +import routes from './routes'; +import { StateInterface } from 'src/store'; +import drink, { DrinkInterface } from 'src/plugins/pricelist/store/drinks'; +import { FG_Plugin } from 'src/plugins'; + +const plugin: FG_Plugin.Plugin = { + name: 'Pricelist', + mainRoutes: routes, + requiredModules: [], + requiredBackendModules: ['pricelist'], + version: '0.0.1', + store: new Map>([['drink', drink]]), + widgets: [] + // widgets: [ + // { + // priority: 1, + // name: 'greeting', + // permissions: [] + // widget: () => import('./components/Widget.vue') + // } + // ] +}; + +export default plugin; diff --git a/src/plugins/pricelist/routes/index.ts b/src/plugins/pricelist/routes/index.ts new file mode 100644 index 0000000..113f29a --- /dev/null +++ b/src/plugins/pricelist/routes/index.ts @@ -0,0 +1,33 @@ +import { FG_Plugin } from 'src/plugins'; +const mainRoutes: FG_Plugin.PluginRouteConfig[] = [ + { + title: 'Getränke', + icon: 'mdi-glass-mug-variant', + path: 'drinks', + name: 'drinks', + component: () => import('../pages/MainPage.vue'), + meta: { permissions: ['user'] }, + children: [ + { + title: 'Preisliste', + icon: 'mdi-cash-100', + path: 'pricelist', + name: 'drinks-pricelist', + shortcut: true, + meta: { permissions: ['user'] }, + component: () => import('../pages/Pricelist.vue') + }, + { + title: 'Einstellungen', + icon: 'mdi-coffee-to-go', + path: 'settings', + name: 'drinks-settings', + shortcut: false, + meta: { permissions: ['users_edit_other'] }, + component: () => import('../pages/Settings.vue') + } + ] + } +]; + +export default mainRoutes; diff --git a/src/plugins/pricelist/store/drinks.ts b/src/plugins/pricelist/store/drinks.ts new file mode 100644 index 0000000..6048c02 --- /dev/null +++ b/src/plugins/pricelist/store/drinks.ts @@ -0,0 +1,106 @@ +import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'; +import { StateInterface } from 'src/store'; +import { axios } from 'src/boot/axios'; +import { AxiosResponse } from 'axios'; + +export interface DrinkInterface { + drinkTypes: FG.DrinkType[]; + drinks: FG.Drink[]; +} + +const state: DrinkInterface = { + drinkTypes: [], + drinks: [] +}; + +const mutations: MutationTree = { + setDrinkTypes(state, drinkTypes: FG.DrinkType[]) { + state.drinkTypes = drinkTypes; + }, + setDrinkType(state, drinkType: FG.DrinkType) { + const item = state.drinkTypes.find(item => item.id == drinkType.id); + if (item) { + item.name = drinkType.name; + } + }, + addDrinkType(state, drinkType: FG.DrinkType) { + state.drinkTypes.unshift(drinkType); + }, + removeDrinkType(state, id: number) { + const index = state.drinkTypes.findIndex(item => item.id == id); + state.drinkTypes.splice(index, 1); + }, + setDrinks(state, drinks: FG.Drink[]) { + state.drinks = drinks + }, + setDrink(state, drink: FG.Drink) { + const index = state.drinks.findIndex(item => item.id = drink.id) + if (index) { + state.drinks[index] = drink + } else { + state.drinks.push(drink) + } + } +}; + +const actions: ActionTree = { + getDrinkTypes({ commit }) { + axios + .get('/pricelist/drink-types') + .then((response: AxiosResponse) => { + commit('setDrinkTypes', response.data); + }) + .catch(err => console.warn(err)); + }, + addDrinkType({ commit }, data) { + axios + .post('/pricelist/drink-types', data) + .then((response: AxiosResponse) => { + commit('addDrinkType', response.data); + }) + .catch(err => { + console.warn(err); + }); + }, + removeDrinkType({ commit }, data: number) { + axios + .delete(`/pricelist/drink-types/${data}`) + .then(() => { + commit('removeDrinkType', data); + }) + .catch(err => console.warn(err)); + }, + changeDrinkTypeName({ commit }, drinkType: FG.DrinkType) { + axios + .put(`/pricelist/drink-types/${drinkType.id}`, drinkType) + .then(() => { + commit('setDrinkType', drinkType); + }) + .catch(err => console.warn(err)); + }, + getDrinks({commit}) { + axios.get('/pricelist/drinks') + .then((response: AxiosResponse) => { + commit('setDrinks', response.data) + }) + .catch(err => console.warn(err)) + }, + createDrink({commit}, data) { + axios.post('/pricelist/drinks', data) + .then((response: AxiosResponse) => { + commit('setDrink', response.data) + }) + .catch(err => console.warn(err)) + } +}; +const getters: GetterTree = {}; + +const schedule: Module = { + namespaced: true, + state, + mutations, + actions, + getters +}; + +export default schedule;