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:
parent
d0936d1838
commit
2083c6921e
19 changed files with 139 additions and 173 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { EventBus } from '../core/EventBus.js';
|
||||
import { CoreEvents } from '../constants/CoreEvents.js';
|
||||
import { CalendarConfig } from '../core/CalendarConfig.js';
|
||||
import { calendarConfig } from '../core/CalendarConfig.js';
|
||||
import { CalendarEvent, CalendarView, IEventBus } from '../types/CalendarTypes.js';
|
||||
import { EventManager } from './EventManager.js';
|
||||
import { GridManager } from './GridManager.js';
|
||||
|
|
@ -11,11 +11,10 @@ import { EventFilterManager } from './EventFilterManager.js';
|
|||
|
||||
/**
|
||||
* CalendarManager - Main coordinator for all calendar managers
|
||||
* Uses simple direct method calls instead of complex state management
|
||||
* Uses singleton calendarConfig for consistent configuration access
|
||||
*/
|
||||
export class CalendarManager {
|
||||
private eventBus: IEventBus;
|
||||
private config: CalendarConfig;
|
||||
private eventManager: EventManager;
|
||||
private gridManager: GridManager;
|
||||
private eventRenderer: EventRenderingService;
|
||||
|
|
@ -28,20 +27,18 @@ export class CalendarManager {
|
|||
|
||||
constructor(
|
||||
eventBus: IEventBus,
|
||||
config: CalendarConfig,
|
||||
eventManager: EventManager,
|
||||
gridManager: GridManager,
|
||||
eventRenderer: EventRenderingService,
|
||||
scrollManager: ScrollManager
|
||||
) {
|
||||
this.eventBus = eventBus;
|
||||
this.config = config;
|
||||
this.eventManager = eventManager;
|
||||
this.gridManager = gridManager;
|
||||
this.eventRenderer = eventRenderer;
|
||||
this.scrollManager = scrollManager;
|
||||
this.eventFilterManager = new EventFilterManager();
|
||||
DateCalculator.initialize(config);
|
||||
DateCalculator.initialize(calendarConfig);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
|
@ -57,7 +54,7 @@ export class CalendarManager {
|
|||
|
||||
try {
|
||||
// Debug: Check calendar type
|
||||
const calendarType = this.config.getCalendarMode();
|
||||
const calendarType = calendarConfig.getCalendarMode();
|
||||
|
||||
// Step 1: Load data
|
||||
await this.eventManager.loadData();
|
||||
|
|
@ -194,8 +191,8 @@ export class CalendarManager {
|
|||
/**
|
||||
* Hent calendar konfiguration
|
||||
*/
|
||||
public getConfig(): CalendarConfig {
|
||||
return this.config;
|
||||
public getConfig() {
|
||||
return calendarConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -267,7 +264,7 @@ export class CalendarManager {
|
|||
nextDate.setDate(nextDate.getDate() + 1);
|
||||
break;
|
||||
case 'week':
|
||||
const workWeekSettings = this.config.getWorkWeekSettings();
|
||||
const workWeekSettings = calendarConfig.getWorkWeekSettings();
|
||||
nextDate.setDate(nextDate.getDate() + 7); // Move to next calendar week regardless of work days
|
||||
break;
|
||||
case 'month':
|
||||
|
|
@ -289,7 +286,7 @@ export class CalendarManager {
|
|||
previousDate.setDate(previousDate.getDate() - 1);
|
||||
break;
|
||||
case 'week':
|
||||
const workWeekSettings = this.config.getWorkWeekSettings();
|
||||
const workWeekSettings = calendarConfig.getWorkWeekSettings();
|
||||
previousDate.setDate(previousDate.getDate() - 7); // Move to previous calendar week regardless of work days
|
||||
break;
|
||||
case 'month':
|
||||
|
|
@ -441,7 +438,7 @@ export class CalendarManager {
|
|||
const dateRange = DateCalculator.formatDateRange(firstDate, lastDate);
|
||||
|
||||
// Emit week info update
|
||||
this.eventBus.emit(CoreEvents.WEEK_CHANGED, {
|
||||
this.eventBus.emit(CoreEvents.PERIOD_INFO_UPDATE, {
|
||||
weekNumber,
|
||||
dateRange,
|
||||
weekStart: firstDate,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue