mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-07-16 09:38:51 +02:00
feat:#22 added static switch between semesters
This commit is contained in:
@ -22,6 +22,11 @@ import { formatYearMonthDay } from "@/helpers/dates";
|
|||||||
const END_OF_SUMMER_SEMESTER = "0930";
|
const END_OF_SUMMER_SEMESTER = "0930";
|
||||||
const END_OF_WINTER_SEMESTER = "0331";
|
const END_OF_WINTER_SEMESTER = "0331";
|
||||||
|
|
||||||
|
export function isSummerSemester(date: Date): boolean {
|
||||||
|
const formattedDate = formatYearMonthDay(date).slice(4);
|
||||||
|
return formattedDate > END_OF_WINTER_SEMESTER && formattedDate <= END_OF_SUMMER_SEMESTER;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if date is in winter semester before summer semester
|
* check if date is in winter semester before summer semester
|
||||||
* @param date - The date to check
|
* @param date - The date to check
|
||||||
@ -68,15 +73,24 @@ export async function fetchRoomOccupancy(
|
|||||||
from_date?: string,
|
from_date?: string,
|
||||||
to_date?: string,
|
to_date?: string,
|
||||||
): Promise<RoomOccupancyList> {
|
): Promise<RoomOccupancyList> {
|
||||||
|
let new_from_date: Date | string
|
||||||
|
let new_to_date = to_date
|
||||||
|
|
||||||
|
console.debug("from_date: " + from_date);
|
||||||
|
|
||||||
if (from_date == undefined) {
|
if (from_date == undefined) {
|
||||||
const new_from_date = getSemesterStart(new Date());
|
new_from_date = getSemesterStart(new Date());
|
||||||
from_date = new_from_date.toISOString();
|
new_from_date = new_from_date.toISOString();
|
||||||
|
} else {
|
||||||
|
new_from_date = getSemesterStart(new Date(from_date)).toISOString();
|
||||||
|
new_to_date = getSemesterStart(addMonths(new Date(from_date), 6)).toISOString();
|
||||||
}
|
}
|
||||||
if (to_date == undefined) {
|
|
||||||
const new_to_date = getSemesterStart(addMonths(new Date(), 6));
|
if (to_date == undefined && new_to_date == undefined) {
|
||||||
to_date = new_to_date.toISOString();
|
new_to_date = getSemesterStart(addMonths(new Date(), 6)).toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let roomOccupancyList: RoomOccupancyList = new RoomOccupancyList(
|
let roomOccupancyList: RoomOccupancyList = new RoomOccupancyList(
|
||||||
new Date(),
|
new Date(),
|
||||||
0,
|
0,
|
||||||
@ -84,7 +98,7 @@ export async function fetchRoomOccupancy(
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
await fetch("/api/schedule/rooms?from=" + from_date + "&to=" + to_date)
|
await fetch("/api/schedule/rooms?from=" + new_from_date + "&to=" + new_to_date)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response.arrayBuffer();
|
return response.arrayBuffer();
|
||||||
})
|
})
|
||||||
|
@ -28,7 +28,7 @@ import allLocales from "@fullcalendar/core/locales-all";
|
|||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import { formatYearMonthDay } from "@/helpers/dates";
|
import { formatYearMonthDay } from "@/helpers/dates";
|
||||||
import { useQuery } from "@tanstack/vue-query";
|
import { useQuery } from "@tanstack/vue-query";
|
||||||
import { fetchRoomOccupancy } from "@/api/fetchRoomOccupancy";
|
import { fetchRoomOccupancy, isSummerSemester } from "@/api/fetchRoomOccupancy";
|
||||||
import { isValid } from "date-fns";
|
import { isValid } from "date-fns";
|
||||||
import { RoomOccupancyList } from "@/model/roomOccupancyList";
|
import { RoomOccupancyList } from "@/model/roomOccupancyList";
|
||||||
|
|
||||||
@ -89,9 +89,9 @@ function transformData(data: RoomOccupancyList) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: occupancy } = useQuery({
|
const { data: occupancy, refetch } = useQuery({
|
||||||
queryKey: ["roomOccupancy"], //, selectedRoom, currentDateFrom, currentDateTo],
|
queryKey: ["roomOccupancy"], //, selectedRoom, currentDateFrom, currentDateTo],
|
||||||
queryFn: () => fetchRoomOccupancy(),
|
queryFn: () => fetchRoomOccupancy(date.value.toISOString()),
|
||||||
staleTime: 12 * 3600000, // 12 hours
|
staleTime: 12 * 3600000, // 12 hours
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -102,6 +102,32 @@ const occupations = computed(() => {
|
|||||||
|
|
||||||
watch(occupations, () => fullCalendar.value?.getApi().refetchEvents());
|
watch(occupations, () => fullCalendar.value?.getApi().refetchEvents());
|
||||||
|
|
||||||
|
|
||||||
|
const fetchedSemesterSummer: Ref<boolean> = ref(isSummerSemester(date.value));
|
||||||
|
// refetch occupancy data when date changes the month from march to april or september to october
|
||||||
|
watch(currentDateTo, () => {
|
||||||
|
//if preselected date is not in range from april to september, update occupancy data
|
||||||
|
|
||||||
|
console.debug("currentDateTo", currentDateTo.value, isSummerSemester(new Date(currentDateTo.value)));
|
||||||
|
console.debug("currentDateFrom", currentDateFrom.value, isSummerSemester(new Date(currentDateFrom.value)));
|
||||||
|
console.debug("fetchedSemesterSummer", fetchedSemesterSummer.value);
|
||||||
|
|
||||||
|
if (isSummerSemester(new Date(currentDateTo.value)) != fetchedSemesterSummer.value) {
|
||||||
|
fetchedSemesterSummer.value = !fetchedSemesterSummer.value;
|
||||||
|
date.value = new Date(currentDateTo.value);
|
||||||
|
refetch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSummerSemester(new Date(currentDateFrom.value)) != fetchedSemesterSummer.value) {
|
||||||
|
fetchedSemesterSummer.value = !fetchedSemesterSummer.value;
|
||||||
|
date.value = new Date(currentDateFrom.value);
|
||||||
|
refetch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
const fullCalendar = ref<InstanceType<typeof FullCalendar>>();
|
const fullCalendar = ref<InstanceType<typeof FullCalendar>>();
|
||||||
|
|
||||||
const calendarOptions: ComputedRef<CalendarOptions> = computed(() => ({
|
const calendarOptions: ComputedRef<CalendarOptions> = computed(() => ({
|
||||||
|
Reference in New Issue
Block a user