From 1b8ab88820d3b71d6cc7f1952ccd7c4a878cf8bd Mon Sep 17 00:00:00 2001 From: chfhtw Date: Fri, 25 Jul 2025 13:31:56 +0200 Subject: [PATCH] Fix: Browser back --- public/js/components/Calendar/Base.js | 39 +++++++++++++------ public/js/components/Cis/LvPlan/LvPlan.js | 18 ++++----- .../js/components/Cis/Mylv/RoomInformation.js | 20 +++++----- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/public/js/components/Calendar/Base.js b/public/js/components/Calendar/Base.js index 520948ecb..94ad3ef05 100644 --- a/public/js/components/Calendar/Base.js +++ b/public/js/components/Calendar/Base.js @@ -152,28 +152,33 @@ export default { return res; }); }, + sDate() { + if (this.date instanceof luxon.DateTime) + return this.date; + return luxon.DateTime.fromJSDate(new Date(this.date)).setZone(this.timezone); + }, cDate: { get() { - if (this.internalDate) { - return this.internalDate.setLocale(this.locale); - } - return luxon.DateTime.fromJSDate(new Date(this.date)).setZone(this.timezone).setLocale(this.locale); + const date = this.internalDate ? this.internalDate : this.sDate; + return date.setLocale(this.locale); }, set(value) { this.internalDate = value; this.$emit('update:date', value); } }, + sMode() { + // choose default mode + let mode = this.mode; + if (mode) + mode = mode.toLowerCase(); + if (!mode || !this.modes[mode]) + mode = Object.keys(this.modes).find(Boolean); // start with first entry as active mode + return mode || ''; + }, cMode: { get() { - if (!this.internalView) { - // choose default mode - let mode = this.mode; - if (!mode || !this.modes[mode]) - mode = Object.keys(this.modes).find(Boolean); // start with first entry as active mode - return mode || ''; - } - return this.internalView; + return this.internalView ? this.internalView : this.sMode; }, set(value) { this.internalView = value; @@ -181,6 +186,16 @@ export default { } } }, + watch: { + sDate(n, o) { + if (this.sDate.isValid && !this.sDate.hasSame(this.internalDate, 'day')) + this.internalDate = this.sDate; + }, + sMode() { + if (this.sMode) + this.internalView = this.sMode; + } + }, methods: { clickPrev() { const evt = new Event('click:prev', {cancelable: true}); diff --git a/public/js/components/Cis/LvPlan/LvPlan.js b/public/js/components/Cis/LvPlan/LvPlan.js index 4fbb7c871..cf190d1c5 100644 --- a/public/js/components/Cis/LvPlan/LvPlan.js +++ b/public/js/components/Cis/LvPlan/LvPlan.js @@ -40,8 +40,6 @@ export default { collapseEmptyDays: false } }, - currentDay: this.propsViewData?.focus_date, - calendarMode: this.propsViewData?.mode ?? DEFAULT_MODE_LVPLAN, studiensemester_kurzbz: null, studiensemester_start: null, studiensemester_ende: null, @@ -49,10 +47,16 @@ export default { }; }, computed:{ + currentDay() { + return this.propsViewData?.focus_date || luxon.DateTime.now().setZone(this.viewData.timezone).toISODate(); + }, + currentMode() { + return this.propsViewData?.mode || DEFAULT_MODE_LVPLAN; + }, backgrounds() { let now = luxon.DateTime.now().setZone(this.viewData.timezone); - if (this.calendarMode == 'Month') + if (this.currentMode == 'Month') return [ { class: 'background-past', @@ -103,7 +107,7 @@ export default { }, handleChangeDate(day) { const focus_date = day.toISODate(); - const mode = this.calendarMode[0].toUpperCase() + this.calendarMode.slice(1); + const mode = this.currentMode; this.$router.push({ name: "LvPlan", @@ -113,8 +117,6 @@ export default { lv_id: this.propsViewData?.lv_id || null } }) - - this.currentDay = day; }, handleChangeMode(newMode) { const mode = newMode[0].toUpperCase() + newMode.slice(1) @@ -130,8 +132,6 @@ export default { lv_id: this.propsViewData?.lv_id ?? null } }); - - this.calendarMode = mode; }, updateRange(rangeInterval) { this.rangeInterval = rangeInterval; @@ -188,7 +188,7 @@ export default { :date="currentDay" :modes="modes" :mode-options="modeOptions" - :mode="propsViewData.mode.toLowerCase()" + :mode="currentMode" @update:date="handleChangeDate" @update:mode="handleChangeMode" @update:range="updateRange" diff --git a/public/js/components/Cis/Mylv/RoomInformation.js b/public/js/components/Cis/Mylv/RoomInformation.js index 0f4fa0603..d8d2ff074 100644 --- a/public/js/components/Cis/Mylv/RoomInformation.js +++ b/public/js/components/Cis/Mylv/RoomInformation.js @@ -37,16 +37,20 @@ export default { week: { collapseEmptyDays: false } - }, - currentDay: this.propsViewData?.focus_date, - calendarMode: this.propsViewData?.mode ?? DEFAULT_MODE_RAUMINFO + } } }, computed: { + currentDay() { + return this.propsViewData?.focus_date || luxon.DateTime.now().setZone(this.viewData.timezone).toISODate(); + }, + currentMode() { + return this.propsViewData?.mode || DEFAULT_MODE_RAUMINFO; + }, backgrounds() { let now = luxon.DateTime.now().setZone(this.viewData.timezone); - if (this.calendarMode == 'Month') + if (this.currentMode == 'Month') return [ { class: 'background-past', @@ -71,7 +75,7 @@ export default { }, handleChangeDate(day) { const focus_date = day.toISODate(); - const mode = this.calendarMode[0].toUpperCase() + this.calendarMode.slice(1); + const mode = this.currentMode; this.$router.push({ name: "RoomInformation", @@ -81,8 +85,6 @@ export default { ort_kurzbz: this.propsViewData.ort_kurzbz } }) - - this.currentDay = day; }, handleChangeMode(newMode) { const mode = newMode[0].toUpperCase() + newMode.slice(1) @@ -98,8 +100,6 @@ export default { ort_kurzbz: this.propsViewData.ort_kurzbz } }) - - this.calendarMode = mode }, updateRange(rangeInterval) { this.rangeInterval = rangeInterval; @@ -131,7 +131,7 @@ export default { :date="currentDay" :modes="modes" :mode-options="modeOptions" - :mode="propsViewData.mode.toLowerCase()" + :mode="currentMode" @update:date="handleChangeDate" @update:mode="handleChangeMode" @update:range="updateRange"