From 6e118221b921c40bc309f4d48f62949bd99a3283 Mon Sep 17 00:00:00 2001 From: minie4 Date: Sat, 30 Apr 2022 18:21:45 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20history=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 6 ++ src/store.js | 13 +++- src/util.js | 26 +++++++ src/views/HistoryView.vue | 120 +++++++++++++++++++++++++++++++++ src/views/SubstitutionView.vue | 30 +-------- 5 files changed, 166 insertions(+), 29 deletions(-) create mode 100644 src/util.js create mode 100644 src/views/HistoryView.vue diff --git a/src/router/index.js b/src/router/index.js index 68257a6..e484db6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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, + }, ], }); diff --git a/src/store.js b/src/store.js index d207f82..04d8487 100644 --- a/src/store.js +++ b/src/store.js @@ -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 = {}; diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..1642924 --- /dev/null +++ b/src/util.js @@ -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; +} diff --git a/src/views/HistoryView.vue b/src/views/HistoryView.vue new file mode 100644 index 0000000..2fb7b86 --- /dev/null +++ b/src/views/HistoryView.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/src/views/SubstitutionView.vue b/src/views/SubstitutionView.vue index ab78686..e13eb58 100644 --- a/src/views/SubstitutionView.vue +++ b/src/views/SubstitutionView.vue @@ -1,32 +1,8 @@