ff-admin/src/views/admin/club/calendar/Calendar.vue

154 lines
4.7 KiB
Vue
Raw Normal View History

2024-10-06 12:02:39 +02:00
<template>
<MainTemplate>
<template #topBar>
<div class="flex flex-row items-center justify-between pt-5 pb-3 px-7">
<h1 class="font-bold text-xl h-8">Kalender</h1>
2025-02-12 18:02:09 +01:00
<div class="flex flex-row gap-2">
<PlusIcon class="text-gray-500 h-5 w-5 cursor-pointer" @click="select" />
<LinkIcon class="text-gray-500 h-5 w-5 cursor-pointer" @click="openLinkModal" />
</div>
2024-10-06 12:02:39 +02:00
</div>
</template>
<template #diffMain>
<div class="flex flex-col w-full h-full gap-2 justify-between px-7 overflow-hidden">
<FullCalendar :options="calendarOptions" class="max-h-full h-full" />
</div>
</template>
</MainTemplate>
</template>
<script setup lang="ts">
2024-10-28 16:02:41 +01:00
import { defineComponent, markRaw, defineAsyncComponent } from "vue";
2024-10-06 12:02:39 +02:00
import { mapActions, mapState } from "pinia";
2024-10-28 16:02:41 +01:00
import { useModalStore } from "@/stores/modal";
2024-10-06 12:02:39 +02:00
import MainTemplate from "@/templates/Main.vue";
import FullCalendar from "@fullcalendar/vue3";
import deLocale from "@fullcalendar/core/locales/de";
import dayGridPlugin from "@fullcalendar/daygrid";
2024-10-25 17:21:09 +02:00
import timeGridPlugin from "@fullcalendar/timegrid";
2024-10-06 12:02:39 +02:00
import interactionPlugin from "@fullcalendar/interaction";
2025-01-02 18:28:13 +01:00
import { useCalendarStore } from "@/stores/admin/club/calendar";
2024-11-24 15:31:08 +01:00
import { useAbilityStore } from "@/stores/ability";
2025-02-12 18:02:09 +01:00
import { LinkIcon, PlusIcon } from "@heroicons/vue/24/outline";
2024-10-06 12:02:39 +02:00
</script>
<script lang="ts">
export default defineComponent({
data() {
2024-10-28 16:02:41 +01:00
return {};
},
computed: {
...mapState(useCalendarStore, ["formattedItems"]),
2024-11-24 15:31:08 +01:00
...mapState(useAbilityStore, ["can"]),
2024-10-28 16:02:41 +01:00
calendarOptions() {
return {
2024-11-07 10:49:50 +01:00
timeZone: "local",
2024-10-06 12:02:39 +02:00
locale: deLocale,
2024-10-25 17:21:09 +02:00
plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
2024-10-06 12:02:39 +02:00
initialView: "dayGridMonth",
headerToolbar: {
2024-10-25 17:21:09 +02:00
left: "dayGridMonth,timeGridWeek",
2024-10-06 12:02:39 +02:00
center: "title",
2024-10-25 17:21:09 +02:00
right: "prev,today,next",
2024-10-06 12:02:39 +02:00
},
eventDisplay: "block",
weekends: true,
editable: true,
selectable: true,
2024-10-25 17:21:09 +02:00
selectMirror: false,
2024-10-06 12:02:39 +02:00
dayMaxEvents: true,
weekNumbers: true,
2024-10-25 17:21:09 +02:00
displayEventTime: true,
nowIndicator: true,
2024-10-06 12:02:39 +02:00
weekText: "KW",
2024-10-28 16:02:41 +01:00
allDaySlot: false,
events: this.formattedItems,
2024-10-25 17:21:09 +02:00
select: this.select,
eventClick: this.eventClick,
2024-10-28 16:02:41 +01:00
};
},
},
mounted() {
this.fetchCalendars();
2024-10-06 12:02:39 +02:00
},
2024-10-25 17:21:09 +02:00
methods: {
2024-10-28 16:02:41 +01:00
...mapActions(useModalStore, ["openModal"]),
...mapActions(useCalendarStore, ["fetchCalendars"]),
2024-10-25 17:21:09 +02:00
select(e: any) {
2024-11-24 15:31:08 +01:00
if (!this.can("create", "club", "calendar")) return;
2024-10-28 16:02:41 +01:00
this.openModal(
markRaw(defineAsyncComponent(() => import("@/components/admin/club/calendar/CreateCalendarModal.vue"))),
{
2025-02-12 18:02:09 +01:00
start: e?.startStr ?? new Date().toISOString(),
end: e?.endStr ?? new Date().toISOString(),
allDay: e?.allDay ?? false,
2024-10-28 16:02:41 +01:00
}
);
2024-10-25 17:21:09 +02:00
},
eventClick(e: any) {
2024-11-24 15:31:08 +01:00
if (!this.can("update", "club", "calendar")) return;
2024-10-28 16:02:41 +01:00
this.openModal(
2024-11-07 09:16:38 +01:00
markRaw(defineAsyncComponent(() => import("@/components/admin/club/calendar/UpdateCalendarModal.vue"))),
2024-10-28 16:02:41 +01:00
e.event.id
);
2024-10-25 17:21:09 +02:00
},
2024-12-05 16:37:10 +01:00
openLinkModal(e: any) {
this.openModal(
markRaw(defineAsyncComponent(() => import("@/components/admin/club/calendar/CalendarLinkModal.vue")))
);
},
2024-10-25 17:21:09 +02:00
},
2024-10-06 12:02:39 +02:00
});
/**
locale: deLocale,
events: this.absencesList.map((x) => ({
id: x.absenceId,
start: x.startDate,
end: x.endDate,
allday: true,
backgroundColor: this.getColorForAbsenceType(x.absenceType),
borderColor: '#ffffff',
title: this.getAbsenceType(x.absenceType) + ' ' + x.fullName,
})),
plugins: [
interactionPlugin,
dayGridPlugin,
timeGridPlugin,
listPlugin,
multiMonthPlugin,
],
initialView: 'dayGridMonth',
eventDisplay: 'block',
weekends: false,
editable: true,
selectable: true,
selectMirror: true,
dayMaxEvents: true,
weekNumbers: true,
displayEventTime: false,
weekText: 'KW',
validRange: { start: '2023-01-01', end: '' },
headerToolbar: {
left: 'today prev,next',
center: 'title',
right: 'listMonth,dayGridMonth,multiMonthYear,customview',
},
views: {
customview: {
type: 'multiMonth',
multiMonthMaxColumns: 1,
duration: { month: 12 },
buttonText: 'grid',
},
},
dateClick: this.handleDateSelect.bind(this),
datesSet: this.handleMonthChange.bind(this),
select: this.handleDateSelect.bind(this),
eventClick: this.handleEventClick.bind(this),
eventsSet: this.handleEvents.bind(this),
};
*/
</script>