Calendar/src/factories/ManagerFactory.ts
Janus Knudsen 7d513600d8 Refactors date handling for ISO week compatibility
Centralizes all date calculations into a new `DateCalculator` class for better maintainability and consistency.

Ensures correct ISO week handling (Monday as the first day) throughout the calendar.

Updates `CalendarConfig` to use ISO day numbering (1-7 for Mon-Sun) for work week definitions.

Fixes issue where date calculations were inconsistent.
Enhances event rendering and navigation.
Updates navigation logic to use pre-rendered events.
Removes the need for `CONTAINER_READY_FOR_EVENTS` event.
2025-08-20 00:39:31 +02:00

88 lines
No EOL
2.8 KiB
TypeScript

import { IEventBus } from '../types/CalendarTypes';
import { CalendarConfig } from '../core/CalendarConfig';
import { EventManager } from '../managers/EventManager';
import { EventRenderingService } from '../renderers/EventRendererManager';
import { GridManager } from '../managers/GridManager';
import { ScrollManager } from '../managers/ScrollManager';
import { NavigationManager } from '../managers/NavigationManager';
import { ViewManager } from '../managers/ViewManager';
import { CalendarManager } from '../managers/CalendarManager';
/**
* Factory for creating and managing calendar managers with proper dependency injection
*/
export class ManagerFactory {
private static instance: ManagerFactory;
private constructor() {}
public static getInstance(): ManagerFactory {
if (!ManagerFactory.instance) {
ManagerFactory.instance = new ManagerFactory();
}
return ManagerFactory.instance;
}
/**
* Create all managers with proper dependency injection
*/
public createManagers(eventBus: IEventBus, config: CalendarConfig): {
eventManager: EventManager;
eventRenderer: EventRenderingService;
gridManager: GridManager;
scrollManager: ScrollManager;
navigationManager: NavigationManager;
viewManager: ViewManager;
calendarManager: CalendarManager;
} {
console.log('🏭 ManagerFactory: Creating managers with proper DI...');
// Create managers in dependency order
const eventManager = new EventManager(eventBus);
const eventRenderer = new EventRenderingService(eventBus, eventManager);
const gridManager = new GridManager();
const scrollManager = new ScrollManager();
const navigationManager = new NavigationManager(eventBus, eventRenderer);
const viewManager = new ViewManager(eventBus);
// CalendarManager depends on all other managers
const calendarManager = new CalendarManager(
eventBus,
config,
eventManager,
gridManager,
eventRenderer,
scrollManager
);
console.log('✅ ManagerFactory: All managers created successfully');
return {
eventManager,
eventRenderer,
gridManager,
scrollManager,
navigationManager,
viewManager,
calendarManager
};
}
/**
* Initialize all managers in the correct order
*/
public async initializeManagers(managers: {
calendarManager: CalendarManager;
[key: string]: any;
}): Promise<void> {
console.log('🚀 ManagerFactory: Initializing managers...');
try {
await managers.calendarManager.initialize();
console.log('✅ ManagerFactory: All managers initialized successfully');
} catch (error) {
console.error('❌ ManagerFactory: Manager initialization failed:', error);
throw error;
}
}
}