[pricelist] add public (outer) pricelist withoud login

This commit is contained in:
Tim Gröger 2021-03-28 16:43:30 +02:00
parent 59d6023462
commit 8eecb70df0
4 changed files with 72 additions and 8 deletions

View File

@ -30,6 +30,7 @@
hide-header hide-header
:hide-bottom="props.row.volumes.length < 5" :hide-bottom="props.row.volumes.length < 5"
flat flat
:visible-columns="visibleColumn"
> >
<template #body-cell-prices="props_volumes"> <template #body-cell-prices="props_volumes">
<q-td :props="props_volumes"> <q-td :props="props_volumes">
@ -39,6 +40,7 @@
hide-header hide-header
:hide-bottom="props_volumes.row.prices.length < 5" :hide-bottom="props_volumes.row.prices.length < 5"
flat flat
:visible-columns="visibleColumn"
> >
<template #body-cell-public="props_prices"> <template #body-cell-public="props_prices">
<q-td :props="props_prices"> <q-td :props="props_prices">
@ -74,7 +76,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, onBeforeMount, computed } from 'vue'; import { defineComponent, onBeforeMount, computed, ref } from 'vue';
import { usePricelistStore } from '../store'; import { usePricelistStore } from '../store';
import { useMainStore } from 'src/store'; import { useMainStore } from 'src/store';
@ -91,14 +93,27 @@ export default defineComponent({
return `${price.toFixed(2)}`; return `${price.toFixed(2)}`;
}, },
}, },
setup() { props: {
public: {
type: Boolean,
default: false,
},
},
setup(props) {
let user: string | null;
onBeforeMount(() => { onBeforeMount(() => {
store.getPriceCalcColumn(user); if (user) {
store.getPriceCalcColumn(user);
}
}); });
const store = usePricelistStore(); const store = usePricelistStore();
onBeforeMount(() => { onBeforeMount(() => {
void store.getDrinks(); void store.getDrinks();
try {
user = mainStore.currentUser.userid;
} catch {
user = null;
}
}); });
const drinks = computed(() => store.drinks); const drinks = computed(() => store.drinks);
const columns_drinks = [ const columns_drinks = [
@ -151,14 +166,36 @@ export default defineComponent({
field: 'public', field: 'public',
}, },
]; ];
const canBeVisible = createVisibleColumns();
const _visibleColumns = ref(canBeVisible);
const visibleColumn = computed({ const visibleColumn = computed({
get: () => store.pricecalc_columns, get: () => {
if (user) {
return store.pricecalc_columns;
} else {
return _visibleColumns.value;
}
},
set: (val) => { set: (val) => {
store.updatePriceCalcColumn(user, val); if (user) {
store.updatePriceCalcColumn(user, val);
} else {
_visibleColumns.value = val;
}
}, },
}); });
const mainStore = useMainStore(); const mainStore = useMainStore();
const user = mainStore.currentUser.userid;
function createVisibleColumns() {
const retVal: Array<string> = [];
columns_drinks.forEach((drink) => retVal.push(drink.name));
columns_volumes.forEach((volume) => retVal.push(volume.name));
columns_prices.forEach((price) => {
if (user || price.name !== 'public') retVal.push(price.name);
});
return retVal;
}
return { columns_drinks, columns_volumes, columns_prices, drinks, visibleColumn }; return { columns_drinks, columns_volumes, columns_prices, drinks, visibleColumn };
}, },
}); });

View File

@ -0,0 +1,13 @@
<template>
<pricelist public />
</template>
<script>
import Pricelist from '../components/Pricelist.vue';
export default {
name: 'OuterPricelist',
components: { Pricelist },
};
</script>
<style scoped></style>

View File

@ -1,9 +1,10 @@
import { innerRoutes } from './routes'; import { innerRoutes, outerRoutes } from './routes';
import { FG_Plugin } from 'src/plugins'; import { FG_Plugin } from 'src/plugins';
const plugin: FG_Plugin.Plugin = { const plugin: FG_Plugin.Plugin = {
name: 'Pricelist', name: 'Pricelist',
innerRoutes, innerRoutes,
outerRoutes,
requiredModules: [], requiredModules: [],
requiredBackendModules: ['pricelist'], requiredBackendModules: ['pricelist'],
version: '0.0.1', version: '0.0.1',

View File

@ -36,3 +36,16 @@ export const innerRoutes: FG_Plugin.MenuRoute[] = [
], ],
}, },
]; ];
export const outerRoutes: FG_Plugin.MenuRoute[] = [
{
title: 'Preisliste',
icon: 'mdi-glass-mug-variant',
shortcut: true,
route: {
path: 'pricelist',
name: 'outter-pricelist',
component: () => import('../pages/OuterPricelist.vue')
}
}
]