[widget] Implemented functional widget, show next services

This commit is contained in:
Ferdinand Thiessen 2021-11-25 15:35:14 +01:00
parent f79823531d
commit 7eb0074111
2 changed files with 48 additions and 11 deletions

View File

@ -1,25 +1,53 @@
<template> <template>
<q-card class="row justify-center content-center" style="text-align: center"> <q-card style="text-align: center">
<q-card-section> <q-card-section class="row justify-center items-center content-center">
<div class="text-h6 col-12">Dienste diesen Monat: {{ jobs }}</div> <div class="col-5">
<!--TODO: Filters are deprecated! --> <q-icon :name="jobs == 0 ? 'mdi-calendar-blank' : 'mdi-calendar-alert'" :size="divHeight" />
<!--<div class="text-h6 col-12">Nächster Dienst: {{ nextJob | date }}</div>--> </div>
<div v-if="(jobs || 0) > 0" ref="div" class="col-7">
<div class="text-h6">Anstehende Dienste</div>
<div class="text-body1">{{ jobs }}</div>
<div class="text-h6">Nächster Dienst</div>
<div class="text-body1">{{ formatDate(nextJob) }}</div>
</div>
<div v-else ref="div" class="col-7">
<div class="text-subtitle1">Keine anstehenden Dienste</div>
</div>
</q-card-section> </q-card-section>
</q-card> </q-card>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { date } from 'quasar';
import { computed, defineComponent, onBeforeMount, ref } from 'vue';
import { asHour, formatDateTime } from '@flaschengeist/api';
import { useEventStore } from '../store';
export default defineComponent({ export default defineComponent({
name: 'EventsWidget', name: 'EventsWidget',
setup() { setup() {
function randomNumber(start: number, end: number) { const store = useEventStore();
return start + Math.floor(Math.random() * Math.floor(end));
const jobs = ref<number>();
const nextJob = ref<Date>();
const div = ref<HTMLElement>();
const divHeight = computed(() => `${div.value?.scrollHeight || '100'}px`);
onBeforeMount(() => {
void store.getJobs({ limit: 1, from: new Date() }).then(({ count, result }) => {
jobs.value = count;
nextJob.value = count > 0 ? result[0].start : undefined;
});
});
function formatDate(d?: Date) {
if (d === undefined) return '-';
if (date.isSameDate(d, new Date(), 'day')) return `Heute ${asHour(d)} Uhr`;
return formatDateTime(d, true, true, false, true) + ' Uhr';
} }
const jobs = randomNumber(0, 5);
const nextJob = new Date(2021, randomNumber(1, 12), randomNumber(1, 31)); return { div, divHeight, formatDate, jobs, nextJob };
return { jobs, nextJob };
}, },
}); });
</script> </script>

View File

@ -166,6 +166,15 @@ export const useEventStore = defineStore({
.then(({ data }) => fixJob(data)); .then(({ data }) => fixJob(data));
}, },
async getJobs(filter?: FG.PaginationFilter) {
return api
.get<FG.PaginationResponse<FG.Job>>('/events/jobs', { params: <unknown>filter })
.then(({ data }) => {
data.result.forEach((j) => fixJob(j));
return data;
});
},
/** /**
* Send invite to job or transfer to other user * Send invite to job or transfer to other user
* @param job Job to invite to * @param job Job to invite to