2021-05-25 15:11:44 +00:00
|
|
|
<template>
|
|
|
|
<q-dialog
|
|
|
|
:model-value="editor !== undefined"
|
|
|
|
persistent
|
|
|
|
transition-show="scale"
|
|
|
|
transition-hide="scale"
|
|
|
|
>
|
|
|
|
<q-card>
|
|
|
|
<div class="column">
|
|
|
|
<div class="col" align="right" style="position: sticky; top: 0; z-index: 999">
|
2021-11-21 11:36:17 +00:00
|
|
|
<q-btn round color="negative" icon="mdi-close" dense rounded @click="editDone(false)" />
|
2021-05-25 15:11:44 +00:00
|
|
|
</div>
|
|
|
|
<div class="col" style="margin: 0; padding: 0; margin-top: -2.4em">
|
|
|
|
<edit-event v-model="editor" @done="editDone" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</q-card>
|
|
|
|
</q-dialog>
|
2021-11-22 11:24:25 +00:00
|
|
|
<q-card>
|
|
|
|
<div style="max-width: 1800px; width: 100%">
|
|
|
|
<div class="bg-primary text-white q-my-sm shadow-2 row justify-center">
|
|
|
|
<div class="col-xs-12 col-sm-9 row justify-center items-center">
|
|
|
|
<q-btn flat dense icon="mdi-chevron-left" title="previous" @click="calendarPrev" />
|
|
|
|
<q-separator vertical />
|
|
|
|
<q-btn flat dense
|
|
|
|
>{{ asMonth(selectedDate) }} {{ asYear(selectedDate) }}
|
2021-11-22 12:01:22 +00:00
|
|
|
<q-popup-proxy ref="proxy" transition-show="scale" transition-hide="scale">
|
2021-11-22 11:24:25 +00:00
|
|
|
<q-date
|
|
|
|
ref="datepicker"
|
2021-11-22 12:01:22 +00:00
|
|
|
:model-value="selectedDate"
|
2021-11-22 11:24:25 +00:00
|
|
|
mask="YYYY-MM-DD"
|
|
|
|
no-unset
|
2021-11-22 12:01:22 +00:00
|
|
|
@update:model-value="updateDate"
|
2021-11-22 11:24:25 +00:00
|
|
|
><q-btn v-close-popup label="jetzt" dense flat @click="datepicker?.setToday()"
|
|
|
|
/></q-date>
|
|
|
|
</q-popup-proxy>
|
|
|
|
</q-btn>
|
|
|
|
<q-separator vertical />
|
|
|
|
<q-btn flat dense icon="mdi-chevron-right" title="next" @click="calendarNext" />
|
|
|
|
</div>
|
|
|
|
<div class="col-xs-12 col-sm-3 text-center">
|
|
|
|
<q-btn-toggle
|
|
|
|
v-if="$q.screen.gt.xs"
|
|
|
|
v-model="calendarView"
|
|
|
|
flat
|
|
|
|
stretch
|
|
|
|
toggle-color="black"
|
|
|
|
:options="[
|
|
|
|
{ label: 'Tag', value: 'day' },
|
|
|
|
{ label: 'Woche', value: 'week' },
|
|
|
|
]"
|
|
|
|
/>
|
2021-11-11 14:25:11 +00:00
|
|
|
</div>
|
2021-05-25 15:11:44 +00:00
|
|
|
</div>
|
2021-11-22 11:24:25 +00:00
|
|
|
<q-calendar-agenda
|
|
|
|
v-model="selectedDate"
|
|
|
|
:view="calendarRealView"
|
|
|
|
:max-days="calendarDays"
|
|
|
|
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
|
|
|
|
locale="de-de"
|
|
|
|
style="height: 100%; min-height: 400px"
|
|
|
|
>
|
|
|
|
<template #head-day-label="{ scope: { timestamp } }">
|
|
|
|
{{ timestamp.day }}
|
|
|
|
<q-menu>
|
|
|
|
<q-list style="min-width: 100px">
|
2021-11-25 14:32:58 +00:00
|
|
|
<q-item exact clickable @click="create(timestamp.date)">
|
2021-11-22 11:24:25 +00:00
|
|
|
<q-item-section>Neue Veranstaltung</q-item-section>
|
|
|
|
</q-item>
|
|
|
|
</q-list>
|
|
|
|
</q-menu>
|
|
|
|
</template>
|
|
|
|
<template #day="{ scope: { timestamp } }">
|
|
|
|
<div itemref="" class="q-pa-sm" style="min-height: 200px">
|
|
|
|
<event-slot
|
|
|
|
v-for="(agenda, index) in events[timestamp.weekday]"
|
|
|
|
:key="index"
|
|
|
|
v-model="events[timestamp.weekday][index]"
|
|
|
|
class="q-mb-sm"
|
|
|
|
@remove-event="remove"
|
|
|
|
@edit-event="edit"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</q-calendar-agenda>
|
|
|
|
</div>
|
|
|
|
</q-card>
|
2021-05-25 15:11:44 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-05-25 15:27:38 +00:00
|
|
|
import { ComponentPublicInstance, computed, defineComponent, onBeforeMount, ref } from 'vue';
|
2021-11-21 11:39:02 +00:00
|
|
|
import { useEventStore } from '../../store';
|
2021-11-16 22:30:21 +00:00
|
|
|
import EventSlot from './slots/EventSlot.vue';
|
2021-11-22 12:01:22 +00:00
|
|
|
import { date, QDate, QPopupProxy, useQuasar } from 'quasar';
|
2021-05-25 15:11:44 +00:00
|
|
|
import { startOfWeek } from '@flaschengeist/api';
|
|
|
|
import EditEvent from '../management/EditEvent.vue';
|
2021-11-15 09:25:21 +00:00
|
|
|
import { QCalendarAgenda } from '@quasar/quasar-ui-qcalendar';
|
2021-11-25 14:32:58 +00:00
|
|
|
import { EditableEvent, emptyEvent } from '../../store/models';
|
2021-05-25 15:11:44 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'AgendaView',
|
2021-11-16 22:30:21 +00:00
|
|
|
components: { EventSlot, EditEvent, QCalendarAgenda: <ComponentPublicInstance>QCalendarAgenda },
|
2021-05-25 15:11:44 +00:00
|
|
|
|
|
|
|
setup() {
|
2021-11-21 11:39:02 +00:00
|
|
|
const store = useEventStore();
|
2021-11-16 22:30:21 +00:00
|
|
|
const quasar = useQuasar();
|
|
|
|
|
2021-11-22 11:24:25 +00:00
|
|
|
const datepicker = ref<QDate>();
|
2021-11-22 12:01:22 +00:00
|
|
|
const proxy = ref<QPopupProxy>();
|
2021-11-22 11:24:25 +00:00
|
|
|
|
2021-05-25 15:11:44 +00:00
|
|
|
const selectedDate = ref(date.formatDate(new Date(), 'YYYY-MM-DD'));
|
|
|
|
const calendarView = ref('week');
|
|
|
|
|
|
|
|
const calendarRealView = computed(() => (calendarDays.value != 7 ? 'day' : 'week'));
|
|
|
|
const calendarDays = computed(() =>
|
2021-11-22 11:24:25 +00:00
|
|
|
calendarView.value == 'day' || quasar.screen.xs ? 1 : quasar.screen.sm ? 3 : 7
|
2021-05-25 15:11:44 +00:00
|
|
|
);
|
|
|
|
const events = ref<Agendas>({});
|
2021-11-25 14:32:58 +00:00
|
|
|
const editor = ref<EditableEvent>();
|
2021-05-25 15:11:44 +00:00
|
|
|
|
|
|
|
interface Agendas {
|
|
|
|
[index: number]: FG.Event[];
|
|
|
|
}
|
|
|
|
|
|
|
|
onBeforeMount(async () => {
|
|
|
|
await loadAgendas();
|
|
|
|
});
|
|
|
|
|
2021-11-25 14:32:58 +00:00
|
|
|
function create(ds: string) {
|
|
|
|
editor.value = emptyEvent(date.extractDate(ds, 'YYYY-MM-DD'));
|
|
|
|
}
|
2021-05-25 15:11:44 +00:00
|
|
|
async function edit(id: number) {
|
|
|
|
editor.value = await store.getEvent(id);
|
|
|
|
}
|
|
|
|
function editDone(changed: boolean) {
|
|
|
|
if (changed) void loadAgendas();
|
|
|
|
editor.value = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function remove(id: number) {
|
|
|
|
if (await store.removeEvent(id)) {
|
|
|
|
// Successfull removed
|
|
|
|
for (const idx in events.value) {
|
|
|
|
const i = events.value[idx].findIndex((event) => event.id === id);
|
|
|
|
if (i !== -1) {
|
|
|
|
events.value[idx].splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Not found, this means our eventa are outdated
|
|
|
|
await loadAgendas();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadAgendas() {
|
2021-11-22 11:24:25 +00:00
|
|
|
const selected = date.adjustDate(selectedDate.value, {
|
|
|
|
milliseconds: 0,
|
|
|
|
seconds: 0,
|
|
|
|
minutes: 0,
|
|
|
|
hours: 0,
|
|
|
|
});
|
2021-05-25 15:11:44 +00:00
|
|
|
const start = calendarRealView.value === 'day' ? selected : startOfWeek(selected);
|
|
|
|
const end = date.addToDate(start, { days: calendarDays.value });
|
|
|
|
|
|
|
|
events.value = {};
|
|
|
|
const list = await store.getEvents({ from: start, to: end });
|
|
|
|
list.forEach((event) => {
|
|
|
|
const day = event.start.getDay();
|
|
|
|
|
|
|
|
if (!events.value[day]) {
|
|
|
|
events.value[day] = [];
|
|
|
|
}
|
|
|
|
events.value[day].push(event);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function calendarNext() {
|
|
|
|
selectedDate.value = date.formatDate(
|
|
|
|
date.addToDate(selectedDate.value, { days: calendarDays.value }),
|
|
|
|
'YYYY-MM-DD'
|
|
|
|
);
|
|
|
|
void loadAgendas();
|
|
|
|
}
|
|
|
|
|
|
|
|
function calendarPrev() {
|
|
|
|
selectedDate.value = date.formatDate(
|
|
|
|
date.subtractFromDate(selectedDate.value, { days: calendarDays.value }),
|
|
|
|
'YYYY-MM-DD'
|
|
|
|
);
|
|
|
|
void loadAgendas();
|
|
|
|
}
|
|
|
|
|
|
|
|
function asMonth(value: string) {
|
|
|
|
if (value) {
|
|
|
|
return date.formatDate(new Date(value), 'MMMM', {
|
|
|
|
months: [
|
|
|
|
'Januar',
|
|
|
|
'Februar',
|
|
|
|
'März',
|
|
|
|
'April',
|
|
|
|
'Mai',
|
|
|
|
'Juni',
|
|
|
|
'Juli',
|
|
|
|
'August',
|
|
|
|
'September',
|
|
|
|
'Oktober',
|
|
|
|
'November',
|
|
|
|
'Dezember',
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function asYear(value: string) {
|
|
|
|
if (value) {
|
|
|
|
return date.formatDate(new Date(value), 'YYYY');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
asYear,
|
|
|
|
asMonth,
|
2021-11-22 11:24:25 +00:00
|
|
|
calendarDays,
|
|
|
|
calendarNext,
|
|
|
|
calendarPrev,
|
|
|
|
calendarRealView,
|
|
|
|
calendarView,
|
2021-11-25 14:32:58 +00:00
|
|
|
create,
|
2021-05-25 15:11:44 +00:00
|
|
|
edit,
|
|
|
|
editor,
|
|
|
|
editDone,
|
|
|
|
events,
|
2021-11-22 11:24:25 +00:00
|
|
|
datepicker,
|
2021-11-22 12:01:22 +00:00
|
|
|
proxy,
|
2021-05-25 15:11:44 +00:00
|
|
|
remove,
|
2021-11-22 11:24:25 +00:00
|
|
|
selectedDate,
|
2021-11-22 12:01:22 +00:00
|
|
|
updateDate: (ds: string) => {
|
|
|
|
selectedDate.value = ds;
|
|
|
|
proxy.value?.hide();
|
|
|
|
},
|
2021-05-25 15:11:44 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2021-05-25 15:36:34 +00:00
|
|
|
<style>
|
|
|
|
@import '@quasar/quasar-ui-qcalendar/dist/index.css';
|
2021-05-25 17:00:36 +00:00
|
|
|
|
2021-11-11 14:25:11 +00:00
|
|
|
/* Fill full height of card */
|
2021-05-25 17:00:36 +00:00
|
|
|
.q-calendar-agenda__pane {
|
|
|
|
height: 100%;
|
|
|
|
}
|
2021-11-11 14:25:11 +00:00
|
|
|
|
|
|
|
/* Same as Qcard */
|
|
|
|
.q-calendar {
|
|
|
|
--calendar-background-dark: --q-dark;
|
|
|
|
}
|
2021-05-25 15:36:34 +00:00
|
|
|
</style>
|