Refactors calendar configuration and event handling

Streamlines calendar configuration by adopting a singleton pattern for consistent access and simplifies event handling.

- Removes direct `CalendarConfig` dependency injection in favor of the `calendarConfig` singleton, reducing code complexity.
- Replaces specific event emissions for grid, date, and resource settings updates with a general `REFRESH_REQUESTED` event.
- Updates event names to be more descriptive and consistent ("NAVIGATION_COMPLETED", "PERIOD_INFO_UPDATE").
- Removes the need to pass the calendar config to renderers since it is now a singleton.

This improves code maintainability and simplifies the event emission process.
This commit is contained in:
Janus Knudsen 2025-09-03 20:04:47 +02:00
parent d0936d1838
commit 2083c6921e
19 changed files with 139 additions and 173 deletions

View file

@ -1,4 +1,4 @@
import { CalendarConfig } from '../core/CalendarConfig';
import { calendarConfig } from '../core/CalendarConfig';
import { ResourceCalendarData } from '../types/CalendarTypes';
/**
@ -6,10 +6,7 @@ import { ResourceCalendarData } from '../types/CalendarTypes';
* Separated from GridManager to follow Single Responsibility Principle
*/
export class GridStyleManager {
private config: CalendarConfig;
constructor(config: CalendarConfig) {
this.config = config;
constructor() {
}
/**
@ -17,9 +14,9 @@ export class GridStyleManager {
*/
public updateGridStyles(resourceData: ResourceCalendarData | null = null): void {
const root = document.documentElement;
const gridSettings = this.config.getGridSettings();
const gridSettings = calendarConfig.getGridSettings();
const calendar = document.querySelector('swp-calendar') as HTMLElement;
const calendarType = this.config.getCalendarMode();
const calendarType = calendarConfig.getCalendarMode();
// Set CSS variables for time and grid measurements
this.setTimeVariables(root, gridSettings);
@ -58,8 +55,8 @@ export class GridStyleManager {
if (calendarType === 'resource' && resourceData) {
return resourceData.resources.length;
} else if (calendarType === 'date') {
const dateSettings = this.config.getDateViewSettings();
const workWeekSettings = this.config.getWorkWeekSettings();
const dateSettings = calendarConfig.getDateViewSettings();
const workWeekSettings = calendarConfig.getWorkWeekSettings();
switch (dateSettings.period) {
case 'day':
@ -73,7 +70,7 @@ export class GridStyleManager {
}
}
return this.config.getWorkWeekSettings().totalDays; // Default to work week
return calendarConfig.getWorkWeekSettings().totalDays; // Default to work week
}
/**