diff --git a/public/js/apps/Dashboard/Fhc.js b/public/js/apps/Dashboard/Fhc.js index 5442a7a86..a4cbb421d 100644 --- a/public/js/apps/Dashboard/Fhc.js +++ b/public/js/apps/Dashboard/Fhc.js @@ -9,7 +9,7 @@ import Profil from "../../components/Cis/Profil/Profil"; import CmsNews from "../../components/Cis/Cms/News"; import CmsContent from "../../components/Cis/Cms/Content"; import Info from "../../components/Cis/Mylv/Semester/Studiengang/Lv/Info"; -import RoomInformation from "../../components/Cis/Mylv/RoomInformation"; +import RoomInformation, {DEFAULT_MODE_RAUMINFO} from "../../components/Cis/Mylv/RoomInformation"; const ciPath = FHC_JS_DATA_STORAGE_OBJECT.app_root.replace(/(https:|)(^|\/\/)(.*?\/)/g, '') + FHC_JS_DATA_STORAGE_OBJECT.ci_router; @@ -28,11 +28,62 @@ const router = VueRouter.createRouter({ component: Profil, props: true }, + + // Redirect old links to new format { - path: `/CisVue/Cms/getRoomInformation/:ort_kurzbz`, + path: "/CisVue/Cms/getRoomInformation/:ort_kurzbz", + name: "RoomInformationOld", + component: RoomInformation, + redirect: (to) => { + return { // redirect to longer Rauminfo url and map params + name: "RoomInformation", + params: { + ort_kurzbz: to.params.ort_kurzbz + }, + }; + }, + }, + { + path: `/CisVue/Cms/getRoomInformation/:mode/:focus_date/:ort_kurzbz`, name: 'RoomInformation', component: RoomInformation, - props: true + props: (route) => { // validate and set mode/focus date if for some reason missing + const validModes = ["Month", "Week", "Day"]; + + // check mode string + const mode = route.params.mode && + validModes.includes(route.params.mode.charAt(0).toUpperCase() + route.params.mode.slice(1).toLowerCase()) + ? route.params.mode.charAt(0).toUpperCase() + route.params.mode.slice(1).toLowerCase() + : DEFAULT_MODE_RAUMINFO; + + // default to today date if not provided + const focus_date = route.params.focus_date || new Date().toISOString().split("T")[0]; + + // for consistency reasons format the props into one object but actually use a new name to we dont collide with + // existing viewData declaration written from codeigniter 3 into routerview tag + return { + propsViewData: { + mode, + focus_date, + ort_kurzbz: route.params.ort_kurzbz + } + }; + }, + beforeEnter: (to, from, next) => { + // missing mode or focus_date -> set defaults + if (!to.params.mode || !to.params.focus_date) { + next({ + name: "RoomInformation", + params: { + mode: to.params.mode || DEFAULT_MODE_RAUMINFO, + focus_date: to.params.focus_date || new Date().toISOString().split("T")[0], + ort_kurzbz: route.params.ort_kurzbz + } + }); + } else { + next(); + } + } }, { path: `/CisVue/Cms/Content/:content_id`, @@ -81,20 +132,19 @@ const router = VueRouter.createRouter({ const validModes = ["Month", "Week", "Day"]; // check mode string - let mode = route.params.mode && + const mode = route.params.mode && validModes.includes(route.params.mode.charAt(0).toUpperCase() + route.params.mode.slice(1).toLowerCase()) ? route.params.mode.charAt(0).toUpperCase() + route.params.mode.slice(1).toLowerCase() : DEFAULT_MODE_STUNDENPLAN; // default to today date if not provided - let focusDate = route.params.focus_date || new Date().toISOString().split("T")[0]; - + const focus_date = route.params.focus_date || new Date().toISOString().split("T")[0]; // for consistency reasons format the props into one object but actually use a new name to we dont collide with // existing viewData declaration written from codeigniter 3 into routerview tag return { propsViewData: { mode, - focusDate, + focus_date, lv_id: route.params.lv_id } }; @@ -115,6 +165,12 @@ const router = VueRouter.createRouter({ } } }, + { + path: `/Cis4`, + name: 'Cis4', + component: FhcDashboard, + props: {dashboard: 'CIS'}, + }, { path: `/`, name: 'FhcDashboard', @@ -122,11 +178,19 @@ const router = VueRouter.createRouter({ props: {dashboard: 'CIS'}, }, { - path: `/Cis4`, - name: 'Cis4', + path: '/:pathMatch(.*)*', + name: 'Fallback', component: FhcDashboard, props: {dashboard: 'CIS'}, - } + redirect: () => { + return { + name: "Cis4", + params: { + dashboard: 'CIS' + }, + }; + }, + }, ] }) diff --git a/public/js/components/Cis/Mylv/RoomInformation.js b/public/js/components/Cis/Mylv/RoomInformation.js index 889651261..f143cda35 100644 --- a/public/js/components/Cis/Mylv/RoomInformation.js +++ b/public/js/components/Cis/Mylv/RoomInformation.js @@ -3,15 +3,14 @@ import CalendarDate from "../../../composables/CalendarDate.js"; import LvModal from "../../../components/Cis/Mylv/LvModal.js"; import LvInfo from "../../../components/Cis/Mylv/LvInfo.js" -export const DEFAULT_MODE = 'Week' +export const DEFAULT_MODE_RAUMINFO = 'Week' const RoomInformation = { name: "RoomInformation", props:{ - ort_kurzbz: { - type: String, - required: true, - } + propsViewData: { + type: Object + } }, components: { FhcCalendar, @@ -21,9 +20,10 @@ const RoomInformation = { data() { return { events: null, + calendarMode: DEFAULT_MODE_RAUMINFO, calendarDate: new CalendarDate(new Date()), currentlySelectedEvent: null, - currentDay: new Date(), + currentDay: this.propsViewData?.focus_date ? new Date(this.propsViewData.focus_date) : new Date(), minimized: false, } @@ -45,6 +45,17 @@ const RoomInformation = { return this.calendarDateToString(this.calendarDate.cdLastDayOfCalendarMonth); }, }, + watch: { + 'propsViewData.ort_kurzbz'(newVal) { + // relevant if ort_kurzbz can be changed from within this component + }, + 'propsViewData.mode'(newVal) { + if(this.$refs.calendar) this.$refs.calendar.setMode(newVal) + }, + 'propsViewData.focus_date'(newVal) { + this.currentDate = new Date(newVal) + } + }, methods:{ setSelectedEvent: function(event){ this.currentlySelectedEvent = event; @@ -52,9 +63,38 @@ const RoomInformation = { getLvID: function () { this.lv_id = window.location.pathname }, - selectDay: function (day) { + selectDay: function(day){ + debugger + const date = day.getFullYear() + "-" + + String(day.getMonth() + 1).padStart(2, "0") + "-" + + String(day.getDate()).padStart(2, "0"); + + this.$router.push({ + name: "RoomInformation", + params: { + mode: this.calendarMode, + focus_date: date, + ort_kurzbz: this.propsViewData.ort_kurzbz + } + }) + this.currentDay = day; }, + handleChangeMode(mode) { + debugger + const modeCapitalized = mode.charAt(0).toUpperCase() + mode.slice(1) + + this.$router.push({ + name: "RoomInformation", + params: { + mode: modeCapitalized, + focus_date: this.currentDay.toISOString().split("T")[0], + ort_kurzbz: this.propsViewData.ort_kurzbz + } + }) + + this.calendarMode = mode + }, showModal: function (event) { this.currentlySelectedEvent = event; Vue.nextTick(() => { @@ -88,8 +128,8 @@ const RoomInformation = { // bundles the room_events and the reservierungen together into the this.events array Promise.allSettled([ - this.$fhcApi.factory.stundenplan.getRoomInfo(this.ort_kurzbz, this.monthFirstDay, this.monthLastDay), - this.$fhcApi.factory.stundenplan.getOrtReservierungen(this.ort_kurzbz, this.monthFirstDay, this.monthLastDay) + this.$fhcApi.factory.stundenplan.getRoomInfo(this.propsViewData.ort_kurzbz, this.monthFirstDay, this.monthLastDay), + this.$fhcApi.factory.stundenplan.getOrtReservierungen(this.propsViewData.ort_kurzbz, this.monthFirstDay, this.monthLastDay) ]).then((result) => { let promise_events = []; result.forEach((promise_result) => { @@ -122,10 +162,21 @@ const RoomInformation = { this.loadEvents(); }, template: /*html*/` -
Lehrveranstaltung:
+{{ $p.t('lehre/lehrveranstaltung') }}:
{{event?.orig.topic}}
Lektor:
+{{ $p.t('lehre/lektor') }}:
{{lektor.kurzbz}}
Ort:
+{{ $p.t('profil/Ort') }}:
{{event?.orig.ort_kurzbz}}