wip
This commit is contained in:
parent
59b3c64c55
commit
b111f121ba
9 changed files with 200 additions and 694 deletions
|
|
@ -2,17 +2,22 @@ import { EventBus } from '../core/EventBus.js';
|
|||
import { EventTypes } from '../constants/EventTypes.js';
|
||||
import { CalendarConfig } from '../core/CalendarConfig.js';
|
||||
import { CalendarEvent, CalendarView, IEventBus } from '../types/CalendarTypes.js';
|
||||
import { CalendarStateManager } from './CalendarStateManager.js';
|
||||
import { StateEvents } from '../types/CalendarState.js';
|
||||
import { EventManager } from './EventManager.js';
|
||||
import { GridManager } from './GridManager.js';
|
||||
import { EventRenderer } from './EventRenderer.js';
|
||||
import { ScrollManager } from './ScrollManager.js';
|
||||
|
||||
/**
|
||||
* CalendarManager - Main coordinator for all calendar managers
|
||||
* Now delegates initialization to CalendarStateManager for better coordination
|
||||
* Uses simple direct method calls instead of complex state management
|
||||
*/
|
||||
export class CalendarManager {
|
||||
private eventBus: IEventBus;
|
||||
private config: CalendarConfig;
|
||||
private stateManager: CalendarStateManager;
|
||||
private eventManager: EventManager;
|
||||
private gridManager: GridManager;
|
||||
private eventRenderer: EventRenderer;
|
||||
private scrollManager: ScrollManager;
|
||||
private currentView: CalendarView = 'week';
|
||||
private currentDate: Date = new Date();
|
||||
private isInitialized: boolean = false;
|
||||
|
|
@ -20,13 +25,22 @@ export class CalendarManager {
|
|||
constructor(eventBus: IEventBus, config: CalendarConfig) {
|
||||
this.eventBus = eventBus;
|
||||
this.config = config;
|
||||
this.stateManager = new CalendarStateManager();
|
||||
this.setupEventListeners();
|
||||
console.log('📋 CalendarManager: Created with state management');
|
||||
console.log('📋 CalendarManager: Created with direct coordination');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize calendar system using state-driven approach
|
||||
* Set manager references (called from index.ts)
|
||||
*/
|
||||
public setManagers(eventManager: EventManager, gridManager: GridManager, eventRenderer: EventRenderer, scrollManager: ScrollManager): void {
|
||||
this.eventManager = eventManager;
|
||||
this.gridManager = gridManager;
|
||||
this.eventRenderer = eventRenderer;
|
||||
this.scrollManager = scrollManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize calendar system using simple direct calls
|
||||
*/
|
||||
public async initialize(): Promise<void> {
|
||||
if (this.isInitialized) {
|
||||
|
|
@ -34,22 +48,37 @@ export class CalendarManager {
|
|||
return;
|
||||
}
|
||||
|
||||
console.log('🚀 CalendarManager: Starting state-driven initialization');
|
||||
console.log('🚀 CalendarManager: Starting simple initialization');
|
||||
|
||||
try {
|
||||
// Delegate to StateManager for coordinated initialization
|
||||
await this.stateManager.initialize();
|
||||
// Step 1: Load data
|
||||
console.log('📊 Loading event data...');
|
||||
await this.eventManager.loadData();
|
||||
|
||||
// Set initial view and date after successful initialization
|
||||
// Step 2: Render grid structure
|
||||
console.log('🏗️ Rendering grid...');
|
||||
await this.gridManager.render();
|
||||
|
||||
// Step 3: Initialize scroll synchronization
|
||||
console.log('📜 Setting up scroll synchronization...');
|
||||
this.scrollManager.initialize();
|
||||
|
||||
// Step 4: Set initial view and date BEFORE event rendering
|
||||
console.log('⚙️ Setting initial view and date...');
|
||||
this.setView(this.currentView);
|
||||
this.setCurrentDate(this.currentDate);
|
||||
|
||||
// Step 5: Render events (after view is set)
|
||||
console.log('🎨 Rendering events...');
|
||||
const events = this.eventManager.getEvents();
|
||||
await this.eventRenderer.renderEvents(events);
|
||||
|
||||
this.isInitialized = true;
|
||||
console.log('✅ CalendarManager: Initialization complete');
|
||||
console.log('✅ CalendarManager: Simple initialization complete');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ CalendarManager initialization failed:', error);
|
||||
throw error; // Let the caller handle the error
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,28 +168,19 @@ export class CalendarManager {
|
|||
* Check om calendar er initialiseret
|
||||
*/
|
||||
public isCalendarInitialized(): boolean {
|
||||
return this.isInitialized && this.stateManager.isReady();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current calendar state
|
||||
*/
|
||||
public getCurrentState(): string {
|
||||
return this.stateManager.getCurrentState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get state manager for advanced operations
|
||||
*/
|
||||
public getStateManager(): CalendarStateManager {
|
||||
return this.stateManager;
|
||||
return this.isInitialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get initialization report for debugging
|
||||
*/
|
||||
public getInitializationReport(): any {
|
||||
return this.stateManager.getInitializationReport();
|
||||
return {
|
||||
isInitialized: this.isInitialized,
|
||||
currentView: this.currentView,
|
||||
currentDate: this.currentDate,
|
||||
initializationTime: 'N/A - simple initialization'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue