Add history view

This commit is contained in:
2022-04-30 18:21:45 +02:00
parent 63d335d04a
commit 6e118221b9
5 changed files with 166 additions and 29 deletions

View File

@ -1,6 +1,7 @@
import { createRouter, createWebHistory } from "vue-router";
import TimetableView from "../views/TimetableView.vue";
import SubstitutionView from "../views/SubstitutionView.vue";
import HistoryView from "../views/HistoryView.vue";
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -19,6 +20,11 @@ const router = createRouter({
name: "Substitutions",
component: SubstitutionView,
},
{
path: "/history",
name: "History",
component: HistoryView,
},
],
});

View File

@ -1,8 +1,17 @@
import { computed } from "@vue/reactivity";
import { ref } from "vue";
export const timetable = ref([]);
export const substitutions = ref([]);
export const history = ref([]);
export const historyOfDate = computed(() => {
const dates = {};
for (const entry of history.value) {
const date = entry.date;
if (!dates[date]) dates[date] = [];
dates[entry.date].push(entry);
}
return dates;
});
export const substitutionsForDate = computed(() => {
const dates = {};

26
src/util.js Normal file
View File

@ -0,0 +1,26 @@
import { substitutionTexts } from "./definitions";
export function getSubstitutionText(substitution) {
var text = "";
if (substitution.type == "change") {
const change = substitution.change;
if (change.subject) {
text += substitutionTexts.subjectChange + " " + change.subject;
}
if (change.teacher && text == "") {
text += substitutionTexts.teacherChange + " " + change.teacher;
} else if (change.teacher) {
text += " " + substitutionTexts.teacherChangePartial;
text += " " + change.teacher;
}
if (change.room && text == "") {
text += substitutionTexts.roomChange + " " + change.room;
} else if (change.room) {
text += " " + substitutionTexts.roomChangePartial;
text += " " + change.room;
}
} else if (substitution.type == "cancellation") {
text += substitutionTexts.cancellation;
}
return text;
}

120
src/views/HistoryView.vue Normal file
View File

@ -0,0 +1,120 @@
<script setup>
import { historyOfDate } from "../store";
import { dayNames, uiTexts } from "../definitions";
import { getSubstitutionText } from "../util";
import dayjs from "dayjs";
function getChar(type) {
switch (type) {
case "change":
return "~";
case "addition":
return "+";
case "deletion":
return "-";
}
}
function getColor(type) {
switch (type) {
case "change":
return "background-color: #14587E;";
case "addition":
return "background-color: #476331;";
case "deletion":
return "background-color: #7D2B2D;";
}
}
</script>
<template>
<div class="history">
<template v-for="(events, date) of historyOfDate" :key="date">
<div class="title">
<span class="day">
{{ dayNames[new Date(parseInt(date)).getDay() - 1] }},
{{ dayjs(parseInt(date)).format("DD.MM.YYYY") }}
</span>
</div>
<template v-for="(event, index) in events" :key="index">
<div class="change" :style="getColor(event.type)">
<span class="hour">{{ event.lesson }}{{ getChar(event.type) }}</span>
<div class="infos">
<span class="text" v-if="event.type == 'change'">
<template v-for="(change, key) in event.change" :key="key">
<p>
{{ key }}:&nbsp;
<s>{{ change.before }}</s>
&nbsp;{{ change.after }}
</p>
</template>
</span>
<span class="text" v-else>
{{ getSubstitutionText(event.data) }}
<span class="notes">
{{ event.data.notes ? uiTexts.substitutionNotes + ": " : "" }}
{{ event.data.notes }}
</span>
</span>
<span class="notes">
{{ dayjs(event.changedAt).format("DD.MM.YYYY, HH:mm") }}
</span>
</div>
</div>
</template>
</template>
</div>
</template>
<style scoped>
.history {
padding: 65px 10px 80px 10px;
}
.title {
font-size: 18px;
}
.change {
display: grid;
background-color: #26272a;
min-height: 35px;
border-radius: 11px;
margin: 10px 0px;
padding: 10px 10px;
grid-template-columns: 40px auto;
gap: 5px;
}
.hour {
font-size: 30px;
display: flex;
align-items: center;
letter-spacing: 5px;
}
.infos {
display: flex;
justify-content: center;
flex-direction: column;
}
.text {
font-size: 18px;
display: flex;
align-items: center;
word-wrap: break-word;
flex-direction: column;
align-items: flex-start;
}
p {
margin: 0px;
}
.notes {
font-size: 13px;
font-weight: 100;
}
</style>

View File

@ -1,32 +1,8 @@
<script setup>
import { substitutionsForDate } from "../store";
import dayjs from "dayjs";
import { dayNames, substitutionTexts, uiTexts } from "../definitions";
function getText(substitution) {
var text = "";
if (substitution.type == "change") {
const change = substitution.change;
if (change.subject) {
text += substitutionTexts.subjectChange + " " + change.subject;
}
if (change.teacher && text == "") {
text += substitutionTexts.teacherChange + " " + change.teacher;
} else if (change.teacher) {
text += " " + substitutionTexts.teacherChangePartial;
text += " " + change.teacher;
}
if (change.room && text == "") {
text += substitutionTexts.roomChange + " " + change.room;
} else if (change.room) {
text += " " + substitutionTexts.roomChangePartial;
text += " " + change.room;
}
} else if (substitution.type == "cancellation") {
text += substitutionTexts.cancellation;
}
return text;
}
import { dayNames, uiTexts } from "../definitions";
import { getSubstitutionText } from "../util";
</script>
<template>
@ -43,7 +19,7 @@ function getText(substitution) {
<div class="substitution">
<span class="hour">{{ substitution.lesson }}</span>
<div class="infos">
<span class="text">{{ getText(substitution) }}</span>
<span class="text">{{ getSubstitutionText(substitution) }}</span>
<span class="notes">
{{ substitution.notes ? uiTexts.substitutionNotes + ": " : "" }}
{{ substitution.notes }}