Add "trusted" and "source" to Timetable

This commit is contained in:
2022-08-21 00:50:06 +02:00
parent b879f48c61
commit 5fd7ae44fd
4 changed files with 35 additions and 6 deletions

View File

@ -29,7 +29,11 @@ export async function getTimetable(req, res) {
});
return;
}
res.send(timetable.data);
res.send({
trusted: timetable.trused,
source: timetable.source,
data: timetable.data,
});
}
// Helper function for converting a date string

View File

@ -15,6 +15,8 @@ model Timetable {
validFrom DateTime @default(now())
validUntil DateTime?
data Json
source String?
trused Boolean @default(true)
}
model Substitution {

View File

@ -22,7 +22,7 @@ watch(timetableGroups, (newValue) => {
export const selectedDate = ref(new Date(new Date().setUTCHours(0, 0, 0, 0)));
export const selectedDay = computed(() => selectedDate.value.getDay() - 1);
export const timetable = ref([]);
export const timetable = ref({ trusted: true });
export const substitutions = ref([]);
export const history = ref([]);
export const classList = ref([]);
@ -48,7 +48,8 @@ export const substitutionsForDate = computed(() => {
});
export const parsedTimetable = computed(() => {
return timetable.value.map((day) => {
if (!timetable.value.data) return [];
return timetable.value.data.map((day) => {
const newDay = [];
for (const lesson of day) {
var usedLesson = lesson;
@ -76,7 +77,8 @@ export const parsedTimetable = computed(() => {
export const possibleTimetableGroups = computed(() => {
const foundTimetableGroups = [];
for (const day of timetable.value) {
if (!timetable.value.data) return [];
for (const day of timetable.value.data) {
for (const lesson of day) {
if (Array.isArray(lesson)) {
for (const group of lesson) {

View File

@ -1,5 +1,6 @@
<script setup>
import {
timetable,
parsedTimetable,
classFilter,
classList,
@ -11,7 +12,7 @@ import { getSubstitutionColor } from "../util";
import { computed } from "vue";
import TimetableSetup from "../components/initial-setup.vue";
const timetable = computed(() => {
const linkedTimetable = computed(() => {
const currentDay = parsedTimetable.value[selectedDay.value];
if (!currentDay) return [];
const newDay = currentDay.map((e, index) => {
@ -59,7 +60,14 @@ function isCancelled(substitution) {
v-model="classFilter"
/>
<div class="timetable">
<template v-for="(lesson, index) in timetable" :key="index">
<div class="container">
<div class="trust-warning" v-if="!timetable.trusted">
<b>Warning:</b> The Data source of the Timetable data
<b>({{ timetable.source }})</b> is not trustworthy, which means the
timetable may be incorrect!
</div>
</div>
<template v-for="(lesson, index) in linkedTimetable" :key="index">
<div class="lesson" :style="getSubstitutionColor(lesson.substitution)">
<span class="hour">{{ index + 1 }}</span>
<div class="infos">
@ -104,6 +112,19 @@ function isCancelled(substitution) {
padding: 0px 10px 80px 10px;
}
.container {
display: flex;
justify-content: center;
}
.trust-warning {
border: 1px solid #b71c1c;
background-color: #412727;
border-radius: 4px;
padding: 3px 10px;
margin-top: 10px;
width: max-content;
}
.lesson {
display: grid;
background-color: var(--substitution-background-unchanged);