From ecd5e95f2d341b7dc1dcac89bf7f9e0f46914f62 Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Wed, 26 Feb 2025 11:42:32 +0100 Subject: [PATCH] access computed grade phrase defensive; avoid pushing redundant mode changes; replace current state with new params when a different day is selected in the current month -> beforeEnter guard creates redundant navigation history entry which is currently being blocked but produces the possibility to infinitely "rego forward"; --- public/js/apps/Dashboard/Fhc.js | 10 +++++++ .../Cis/Mylv/Semester/Studiengang/Lv.js | 8 +++++- .../components/Cis/Stundenplan/Stundenplan.js | 27 ++++++++++++++----- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/public/js/apps/Dashboard/Fhc.js b/public/js/apps/Dashboard/Fhc.js index e3ba786f1..b4d410344 100644 --- a/public/js/apps/Dashboard/Fhc.js +++ b/public/js/apps/Dashboard/Fhc.js @@ -198,6 +198,16 @@ const router = VueRouter.createRouter({ ] }) +router.beforeEach((to, from) => { + // this avoids redundant routing navigation in place due to router.replace on a route with param function and + // beforeEnter navigation guard + + // TODO: manage the infinite forward navigation issue somehow + if (to.fullPath === from.fullPath) { + return false + } +}) + const app = Vue.createApp({ name: 'FhcApp', data: () => ({ diff --git a/public/js/components/Cis/Mylv/Semester/Studiengang/Lv.js b/public/js/components/Cis/Mylv/Semester/Studiengang/Lv.js index d0dd99f68..0543d8fae 100644 --- a/public/js/components/Cis/Mylv/Semester/Studiengang/Lv.js +++ b/public/js/components/Cis/Mylv/Semester/Studiengang/Lv.js @@ -21,7 +21,9 @@ export default { lvinfo: Boolean, benotung: Boolean, lvnote: String, + lvnotebez: Array, znote: String, + znotebez: Array, studiengang_kuerzel: String, semester: [String, Number], orgform_kurzbz: String, @@ -67,7 +69,11 @@ export default { }, grade() { const languageIndex = this.$p.user_language.value === 'English' ? 1 : 0 - return this.benotung ? this.znotebez[languageIndex] || this.lvnotebez[languageIndex] || null : null; + if(this.benotung && this.znotebez?.length) { + return this.znotebez[languageIndex] + } else if(this.benotung && this.lvnotebez?.length) { + return this.lvnotebez[languageIndex] + } else return null }, LvHasPruefungenInformation(){ return this.pruefungenData && this.pruefungenData.length > 0; diff --git a/public/js/components/Cis/Stundenplan/Stundenplan.js b/public/js/components/Cis/Stundenplan/Stundenplan.js index ba26e25db..b24cb1037 100644 --- a/public/js/components/Cis/Stundenplan/Stundenplan.js +++ b/public/js/components/Cis/Stundenplan/Stundenplan.js @@ -11,7 +11,7 @@ const Stundenplan = { data() { return { events: null, - calendarMode: DEFAULT_MODE_STUNDENPLAN, + calendarMode: this.propsViewData?.mode ?? DEFAULT_MODE_STUNDENPLAN, calendarDate: new CalendarDate(new Date()), eventCalendarDate: new CalendarDate(new Date()), currentlySelectedEvent: null, @@ -60,6 +60,7 @@ const Stundenplan = { if(this.$refs.calendar) this.$refs.calendar.setMode(newVal) }, 'propsViewData.focus_date'(newVal) { + // todo: navigate around with date in current mode this.currentDate = new Date(newVal) } }, @@ -119,8 +120,11 @@ const Stundenplan = { String(day.getMonth() + 1).padStart(2, "0") + "-" + String(day.getDate()).padStart(2, "0"); const capitalizedMode = this.calendarMode[0].toUpperCase() + this.calendarMode.slice(1); + const isMonthMode = capitalizedMode === 'Month' + const isInCurrentMonth = day.getMonth() == this.currentDay.getMonth() - this.$router.push({ + if(isMonthMode && isInCurrentMonth) { + this.$router.replace({ name: "Stundenplan", params: { mode: capitalizedMode, @@ -128,6 +132,16 @@ const Stundenplan = { lv_id: this.propsViewData?.lv_id || null } }) + } else { + this.$router.push({ + name: "Stundenplan", + params: { + mode: capitalizedMode, + focus_date: date, + lv_id: this.propsViewData?.lv_id || null + } + }) + } this.currentDay = day; }, @@ -141,7 +155,7 @@ const Stundenplan = { const date = this.currentDay.getFullYear() + "-" + String(this.currentDay.getMonth() + 1).padStart(2, "0") + "-" + String(this.currentDay.getDate()).padStart(2, "0"); - + this.$router.push({ name: "Stundenplan", params: { @@ -153,10 +167,11 @@ const Stundenplan = { }, handleChangeMode(mode) { let m = mode[0].toUpperCase() + mode.slice(1) + if(m === this.calendarMode) return const date = this.currentDay.getFullYear() + "-" + String(this.currentDay.getMonth() + 1).padStart(2, "0") + "-" + String(this.currentDay.getDate()).padStart(2, "0"); - + this.$router.push({ name: "Stundenplan", params: { @@ -238,7 +253,7 @@ const Stundenplan = { .then(data=>{ this.uid = data.uid; }) - + }, beforeUnmount() { if(this.$refs.lvmodal) this.$refs.lvmodal.hide() @@ -275,7 +290,7 @@ const Stundenplan = {