Merge branch 'develop' into feature/pricelist

This commit is contained in:
Tim Gröger 2021-03-30 20:43:54 +02:00
commit aadfca2d31
6 changed files with 49 additions and 32 deletions

View File

@ -5,7 +5,6 @@ import { api } from 'boot/axios';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { RouteRecordRaw } from 'vue-router'; import { RouteRecordRaw } from 'vue-router';
import { Notify } from 'quasar'; import { Notify } from 'quasar';
import { notEmpty } from 'src/utils/validators';
const config: { [key: string]: Array<string> } = { const config: { [key: string]: Array<string> } = {
// Do not change required Modules !! // Do not change required Modules !!

View File

@ -1,9 +1,13 @@
import { createPinia } from 'pinia'; import { createPinia, Pinia } from 'pinia';
import { boot } from 'quasar/wrappers'; import { boot } from 'quasar/wrappers';
import { useMainStore } from 'src/stores'; import { useMainStore } from 'src/stores';
import { ref } from 'vue';
export const pinia = ref<Pinia>();
export default boot(({ app }) => { export default boot(({ app }) => {
app.use(createPinia()); pinia.value = createPinia();
app.use(pinia.value);
const store = useMainStore(); const store = useMainStore();
void store.init(); void store.init();

View File

@ -1,7 +1,13 @@
<template> <template>
<q-card bordered class="row q-ma-xs q-pa-xs" style="position: relative"> <q-card
bordered
class="row q-ma-xs q-pa-xs"
style="position: relative; min-height: 3em"
:class="{ 'cursor-pointer': modelValue.link }"
@click="click"
>
<div class="col-12 text-weight-light">{{ dateString }}</div> <div class="col-12 text-weight-light">{{ dateString }}</div>
<div :id="`ntfctn-${modelValue.id}`" class="col-12" @click="click">{{ modelValue.text }}</div> <div :id="`ntfctn-${modelValue.id}`" class="col-12">{{ modelValue.text }}</div>
<q-btn <q-btn
round round
dense dense
@ -16,11 +22,11 @@
v-if="modelValue.accept !== undefined" v-if="modelValue.accept !== undefined"
round round
dense dense
icon="close" icon="check"
size="sm" size="sm"
color="positive" color="positive"
class="q-ma-xs" class="q-ma-xs"
style="position: absolute; top: 50px; right: 0" style="position: absolute; top: 0; right: 3em"
@click="accept" @click="accept"
/> />
</q-card> </q-card>
@ -52,15 +58,15 @@ export default defineComponent({
} }
function accept() { function accept() {
if (props.modelValue.accept) if (typeof props.modelValue.accept === 'function')
void props.modelValue.accept().then(() => emit('remove', props.modelValue.id)); void props.modelValue.accept().finally(() => emit('remove', props.modelValue.id));
else emit('remove', props.modelValue.id); else emit('remove', props.modelValue.id);
} }
function remove() { function remove() {
if (props.modelValue.reject) if (typeof props.modelValue.reject === 'function')
void props.modelValue.reject().then(() => emit('remove', props.modelValue.id)); void props.modelValue.reject().finally(() => emit('remove', props.modelValue.id));
emit('remove', props.modelValue.id); else emit('remove', props.modelValue.id);
} }
return { accept, click, dateString, remove }; return { accept, click, dateString, remove };

View File

@ -1,5 +1,6 @@
const config = { const config = {
baseURL: '/api', baseURL: '/api',
pollingInterval: 30000,
}; };
export default config; export default config;

View File

@ -104,11 +104,12 @@
import EssentialLink from 'src/components/navigation/EssentialLink.vue'; import EssentialLink from 'src/components/navigation/EssentialLink.vue';
import ShortcutLink from 'src/components/navigation/ShortcutLink.vue'; import ShortcutLink from 'src/components/navigation/ShortcutLink.vue';
import Notification from 'src/components/Notification.vue'; import Notification from 'src/components/Notification.vue';
import { Screen } from 'quasar'; import { defineComponent, ref, inject, computed, onBeforeMount, onBeforeUnmount } from 'vue';
import { defineComponent, ref, inject, computed, onBeforeMount } from 'vue';
import { useMainStore } from 'src/stores'; import { useMainStore } from 'src/stores';
import { FG_Plugin } from 'src/plugins'; import { FG_Plugin } from 'src/plugins';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { Screen } from 'quasar';
import config from 'src/config';
const essentials: FG_Plugin.MenuLink[] = [ const essentials: FG_Plugin.MenuLink[] = [
{ {
@ -126,24 +127,25 @@ export default defineComponent({
const mainStore = useMainStore(); const mainStore = useMainStore();
const flaschengeist = inject<FG_Plugin.Flaschengeist>('flaschengeist'); const flaschengeist = inject<FG_Plugin.Flaschengeist>('flaschengeist');
const leftDrawer = ref(false); const leftDrawer = ref(false);
const shortcuts = flaschengeist?.shortcuts; const leftDrawerMini = ref(false);
const mainLinks = flaschengeist?.menuLinks; const shortcuts = flaschengeist?.shortcuts || [];
const mainLinks = flaschengeist?.menuLinks || [];
const notifications = computed(() => mainStore.notifications.slice().reverse()); const notifications = computed(() => mainStore.notifications.slice().reverse());
const noPermission = ref(window.Notification.permission !== 'granted'); const noPermission = ref(window.Notification.permission !== 'granted');
const polling = ref(NaN);
function requestPermission() { onBeforeMount(() => pollNotification());
void window.Notification.requestPermission().then( onBeforeUnmount(() => window.clearInterval(polling.value));
(p) => (noPermission.value = p !== 'granted')
);
}
onBeforeMount(() => window.setInterval(() => void mainStore.loadNotifications(), 30000));
const leftDrawerOpen = computed({ const leftDrawerOpen = computed({
get: () => (leftDrawer.value || Screen.gt.sm ? true : false), get: () => (leftDrawer.value || Screen.gt.sm ? true : false),
set: (val: boolean) => (leftDrawer.value = val), set: (val: boolean) => (leftDrawer.value = val),
}); });
const leftDrawerMini = ref(false);
const subLinks = computed(() => {
const matched = router.currentRoute.value.matched[1];
return flaschengeist?.menuLinks.find((link) => matched.name == link.link)?.children;
});
function leftDrawerClicker() { function leftDrawerClicker() {
if (leftDrawerMini.value) { if (leftDrawerMini.value) {
@ -151,11 +153,6 @@ export default defineComponent({
} }
} }
const subLinks = computed(() => {
const matched = router.currentRoute.value.matched[1];
return flaschengeist?.menuLinks.find((link) => matched.name == link.link)?.children;
});
function logout() { function logout() {
void router.push({ name: 'login', params: { logout: 'logout' } }); void router.push({ name: 'login', params: { logout: 'logout' } });
void mainStore.logout(); void mainStore.logout();
@ -165,6 +162,18 @@ export default defineComponent({
await mainStore.removeNotification(id); await mainStore.removeNotification(id);
} }
function requestPermission() {
void window.Notification.requestPermission().then(
(p) => (noPermission.value = p !== 'granted')
);
}
function pollNotification() {
polling.value = window.setInterval(() => {
void mainStore.loadNotifications(<FG_Plugin.Flaschengeist>flaschengeist);
}, config.pollingInterval);
}
return { return {
essentials, essentials,
leftDrawerOpen, leftDrawerOpen,

View File

@ -5,7 +5,6 @@ import { FG_Plugin } from 'src/plugins';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { api } from 'src/boot/axios'; import { api } from 'src/boot/axios';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { inject } from 'vue';
function loadCurrentSession() { function loadCurrentSession() {
const session = LocalStorage.getItem<FG.Session>('session'); const session = LocalStorage.getItem<FG.Session>('session');
@ -109,8 +108,7 @@ export const useMainStore = defineStore({
); );
}, },
async loadNotifications() { async loadNotifications(flaschengeist: FG_Plugin.Flaschengeist) {
const flaschengeist = inject<FG_Plugin.Flaschengeist>('flaschengeist');
const params = const params =
this.notifications.length > 0 this.notifications.length > 0
? { from: this.notifications[this.notifications.length - 1].time } ? { from: this.notifications[this.notifications.length - 1].time }