Calendar/wwwroot/js/managers/GridManager.js
2026-02-03 00:02:25 +01:00

77 lines
No EOL
2.9 KiB
JavaScript

/**
* GridManager - Simplified grid manager using centralized GridRenderer
* Delegates DOM rendering to GridRenderer, focuses on coordination
*/
import { eventBus } from '../core/EventBus';
import { CoreEvents } from '../constants/CoreEvents';
import { DateColumnDataSource } from '../datasources/DateColumnDataSource';
/**
* Simplified GridManager focused on coordination, delegates rendering to GridRenderer
*/
export class GridManager {
constructor(gridRenderer, dateService, config, eventManager) {
this.container = null;
this.currentDate = new Date();
this.currentView = 'week';
this.gridRenderer = gridRenderer;
this.dateService = dateService;
this.config = config;
this.eventManager = eventManager;
this.dataSource = new DateColumnDataSource(dateService, config, this.currentDate, this.currentView);
this.init();
}
init() {
this.findElements();
this.subscribeToEvents();
}
findElements() {
this.container = document.querySelector('swp-calendar-container');
}
subscribeToEvents() {
// Listen for view changes
eventBus.on(CoreEvents.VIEW_CHANGED, (e) => {
const detail = e.detail;
this.currentView = detail.currentView;
this.dataSource.setCurrentView(this.currentView);
this.render();
});
// Listen for navigation events from NavigationButtons
eventBus.on(CoreEvents.NAVIGATION_COMPLETED, (e) => {
const detail = e.detail;
this.currentDate = detail.newDate;
this.dataSource.setCurrentDate(this.currentDate);
this.render();
});
// Listen for config changes that affect rendering
eventBus.on(CoreEvents.REFRESH_REQUESTED, (e) => {
this.render();
});
eventBus.on(CoreEvents.WORKWEEK_CHANGED, () => {
this.render();
});
}
/**
* Main render method - delegates to GridRenderer
* Note: CSS variables are automatically updated by ConfigManager when config changes
*/
async render() {
if (!this.container) {
return;
}
// Get dates from datasource - single source of truth
const dates = this.dataSource.getColumns();
// Get events for the period from EventManager
const startDate = dates[0];
const endDate = dates[dates.length - 1];
const events = await this.eventManager.getEventsForPeriod(startDate, endDate);
// Delegate to GridRenderer with dates and events
this.gridRenderer.renderGrid(this.container, this.currentDate, this.currentView, dates, events);
// Emit grid rendered event
eventBus.emit(CoreEvents.GRID_RENDERED, {
container: this.container,
currentDate: this.currentDate,
dates: dates
});
}
}
//# sourceMappingURL=GridManager.js.map