From 65de1f4b03578b32dd0c20c75c5a11efec0ca3c8 Mon Sep 17 00:00:00 2001 From: Henriette Darge Date: Wed, 5 Jan 2022 14:30:20 +0100 Subject: [PATCH] Save calendar view (month vs week) in url param --- frontend/src/app/features/calendar/calendar.routes.ts | 4 +++- .../src/app/features/calendar/op-calendar.service.ts | 10 +++++++++- .../calendar/wp-calendar/wp-calendar.component.ts | 6 ------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/features/calendar/calendar.routes.ts b/frontend/src/app/features/calendar/calendar.routes.ts index 5ba021d2a4..165afe392e 100644 --- a/frontend/src/app/features/calendar/calendar.routes.ts +++ b/frontend/src/app/features/calendar/calendar.routes.ts @@ -37,13 +37,15 @@ export const CALENDAR_ROUTES:Ng2StateDeclaration[] = [ { name: 'calendar', parent: 'optional_project', - url: '/calendar?query_id&query_props', + url: '/calendar?query_id&query_props&cdate&cview', redirectTo: 'calendar.page', views: { '!$default': { component: WorkPackagesBaseComponent }, }, params: { query_id: { type: 'query', dynamic: true }, + cdate: { type: 'string', dynamic: true }, + cview: { type: 'string', dynamic: true }, // Use custom encoder/decoder that ensures validity of URL string query_props: { type: 'opQueryString' }, }, diff --git a/frontend/src/app/features/calendar/op-calendar.service.ts b/frontend/src/app/features/calendar/op-calendar.service.ts index b97953cb1e..a5ffeaa65c 100644 --- a/frontend/src/app/features/calendar/op-calendar.service.ts +++ b/frontend/src/app/features/calendar/op-calendar.service.ts @@ -243,6 +243,7 @@ export class OpCalendarService extends UntilDestroyedMixin { right: '', }, initialDate: this.initialDate, + initialView: this.initialView, datesSet: (dates) => this.updateDateParam(dates), // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment eventClick: this.openSplitView.bind(this), @@ -352,10 +353,17 @@ export class OpCalendarService extends UntilDestroyedMixin { return undefined; } + private get initialView():string|undefined { + return this.urlParams.cview as string|undefined; + } + private updateDateParam(dates:DatesSetArg) { void this.$state.go( '.', - { cdate: this.timezoneService.formattedISODate(dates.start) }, + { + cdate: this.timezoneService.formattedISODate(dates.view.currentStart), + cview: dates.view.type, + }, ); } } diff --git a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts index b443fa9e28..28bc625172 100644 --- a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts +++ b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts @@ -127,12 +127,6 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment events: this.calendarEventsFunction.bind(this), plugins: [dayGridPlugin], - initialView: (() => { - if (this.static) { - return 'dayGridWeek'; - } - return undefined; - })(), }), ); });