52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import {
|
|
classFilter,
|
|
fetchSubstitutions,
|
|
fetchHistory,
|
|
loading,
|
|
selectedDate,
|
|
} from "./store";
|
|
import dayjs from "dayjs";
|
|
|
|
export function getSubstitutionText(substitution) {
|
|
const includeClass = !classFilter.value || classFilter.value == "none";
|
|
const includeClassValue = includeClass ? "withClass" : "withoutClass";
|
|
|
|
// TODO: implement more texts
|
|
if (substitution.type == "change") {
|
|
return `substitution.text.${includeClassValue}.subjectChange`;
|
|
} else if (substitution.type == "cancellation") {
|
|
return `substitution.text.${includeClassValue}.cancellation`;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
export function getSubstitutionColor(substitution) {
|
|
if (!substitution) return;
|
|
switch (substitution.type) {
|
|
case "change":
|
|
return "background-color: var(--substitution-background-change);";
|
|
case "cancellation":
|
|
return "background-color: var(--substitution-background-cancellation);";
|
|
}
|
|
}
|
|
|
|
export function nextDay() {
|
|
var newDate = dayjs(selectedDate.value).add(1, "day");
|
|
// Skip weekend
|
|
if (newDate.day() == 6) newDate = newDate.add(2, "day");
|
|
changeDate(newDate);
|
|
}
|
|
export function previousDay() {
|
|
var newDate = dayjs(selectedDate.value).subtract(1, "day");
|
|
// Skip weekend
|
|
if (newDate.day() == 0) newDate = newDate.subtract(2, "day");
|
|
changeDate(newDate);
|
|
}
|
|
export async function changeDate(newDate) {
|
|
selectedDate.value = new Date(newDate.toDate().setUTCHours(0, 0, 0, 0));
|
|
loading.value = true;
|
|
await fetchSubstitutions();
|
|
await fetchHistory();
|
|
loading.value = false;
|
|
}
|