From fb8fc09e8d2e564806066c868269baf210292ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 18 Mar 2021 22:33:25 +0100 Subject: [PATCH] [pricelist] persistent save visible_columns --- .../pricelist/components/CalculationTable.vue | 31 ++++++++--------- src/plugins/pricelist/store/altStore.ts | 34 +++++++++++++++++++ yarn.lock | 5 +++ 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/plugins/pricelist/components/CalculationTable.vue b/src/plugins/pricelist/components/CalculationTable.vue index cb8ffa1..d49998a 100644 --- a/src/plugins/pricelist/components/CalculationTable.vue +++ b/src/plugins/pricelist/components/CalculationTable.vue @@ -601,6 +601,9 @@ import { defineComponent, onBeforeMount, ref, computed, ComputedRef } from '@vue import store, { DrinkPriceVolume, Drink } from '../store/altStore'; import PriceTable from 'src/plugins/pricelist/components/CalculationTable/PriceTable.vue'; import Ingredients from 'src/plugins/pricelist/components/CalculationTable/Ingredients.vue'; +import { StateInterface } from 'src/store'; +import { Store } from 'vuex'; +import { UserStateInterface } from 'src/plugins/user/store/user'; function sort(a: string | number, b: string | number) { if (a > b) return 1; if (b > a) return -1; @@ -609,7 +612,12 @@ function sort(a: string | number, b: string | number) { export default defineComponent({ name: 'CalculationTable', components: { PriceTable, Ingredients }, - setup() { + setup(_, { root }) { + onBeforeMount(() => { + store.actions.getPriceCalcColumn(user); + }); + const userstore = >root.$store; + const user = userstore.state.user.currentUser?.userid; const columns = [ { name: 'name', @@ -705,21 +713,12 @@ export default defineComponent({ field: 'public', }, ]; - const visibleColumn = ref([ - 'name', - 'drink_type', - 'volume_package', - 'cost_price_package_netto', - 'package_size', - 'cost_price_pro_volume', - 'volumes', - 'volume', - 'min_prices', - 'prices', - 'price', - 'description', - 'public', - ]); + const visibleColumn = computed({ + get: () => store.state.pricecalc_columns, + set: (val) => { + store.actions.updatePriceCalcColumn(user, val); + }, + }); const emptyVolume: DrinkPriceVolume = { id: -1, _volume: 0, diff --git a/src/plugins/pricelist/store/altStore.ts b/src/plugins/pricelist/store/altStore.ts index 114bbfb..ef227c6 100644 --- a/src/plugins/pricelist/store/altStore.ts +++ b/src/plugins/pricelist/store/altStore.ts @@ -7,11 +7,27 @@ const state = reactive<{ tags: FG.Tag[]; drinkTypes: FG.DrinkType[]; extraIngredients: FG.ExtraIngredient[]; + pricecalc_columns: Array; }>({ drinks: [], tags: [], drinkTypes: [], extraIngredients: [], + pricecalc_columns: [ + 'name', + 'drink_type', + 'volume_package', + 'cost_price_package_netto', + 'package_size', + 'cost_price_pro_volume', + 'volumes', + 'volume', + 'min_prices', + 'prices', + 'price', + 'description', + 'public', + ], }); interface MinPrice extends Omit { @@ -307,6 +323,24 @@ const actions = { }) .catch((err) => console.warn(err)); }, + getPriceCalcColumn(userid: string) { + axios + .get(`pricelist/users/${userid}/pricecalc_columns`) + .then(({ data }: AxiosResponse>) => { + if (data.length > 0) { + state.pricecalc_columns = data; + } + }) + .catch((err) => console.log(err)); + }, + updatePriceCalcColumn(userid: string, data: Array) { + axios + .put(`pricelist/users/${userid}/pricecalc_columns`, data) + .then(() => { + state.pricecalc_columns = data; + }) + .catch((err) => console.log(err)); + }, }; const getters = {}; diff --git a/yarn.lock b/yarn.lock index 64ff3f4..a621a08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7989,6 +7989,11 @@ prettier@^1.18.2: resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== +prettier@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" + integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== + pretty-error@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-2.1.2.tgz#be89f82d81b1c86ec8fdfbc385045882727f93b6"