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,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
import { IEventBus } from '../types/CalendarTypes';
|
||||
import { CalendarConfig } from '../core/CalendarConfig';
|
||||
import { calendarConfig } from '../core/CalendarConfig';
|
||||
import { DateCalculator } from '../utils/DateCalculator';
|
||||
|
||||
interface CachedElements {
|
||||
|
|
@ -20,7 +20,6 @@ interface Position {
|
|||
|
||||
export class DragDropManager {
|
||||
private eventBus: IEventBus;
|
||||
private config: CalendarConfig;
|
||||
|
||||
// Mouse tracking with optimized state
|
||||
private isMouseDown = false;
|
||||
|
|
@ -61,12 +60,11 @@ export class DragDropManager {
|
|||
return (this.snapIntervalMinutes / 60) * this.hourHeightPx;
|
||||
}
|
||||
|
||||
constructor(eventBus: IEventBus, config: CalendarConfig) {
|
||||
constructor(eventBus: IEventBus) {
|
||||
this.eventBus = eventBus;
|
||||
this.config = config;
|
||||
|
||||
|
||||
// Get config values
|
||||
const gridSettings = config.getGridSettings();
|
||||
const gridSettings = calendarConfig.getGridSettings();
|
||||
this.hourHeightPx = gridSettings.hourHeight;
|
||||
|
||||
this.init();
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export class GridManager {
|
|||
|
||||
constructor() {
|
||||
// Initialize GridRenderer with config
|
||||
this.gridRenderer = new GridRenderer(calendarConfig);
|
||||
this.gridRenderer = new GridRenderer();
|
||||
this.init();
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ export class GridManager {
|
|||
|
||||
this.currentDate = nextDate;
|
||||
|
||||
eventBus.emit(CoreEvents.PERIOD_CHANGED, {
|
||||
eventBus.emit(CoreEvents.NAVIGATION_COMPLETED, {
|
||||
direction: 'next',
|
||||
newDate: nextDate,
|
||||
periodLabel: this.getCurrentPeriodLabel()
|
||||
|
|
@ -182,7 +182,7 @@ export class GridManager {
|
|||
|
||||
this.currentDate = prevDate;
|
||||
|
||||
eventBus.emit(CoreEvents.PERIOD_CHANGED, {
|
||||
eventBus.emit(CoreEvents.NAVIGATION_COMPLETED, {
|
||||
direction: 'previous',
|
||||
newDate: prevDate,
|
||||
periodLabel: this.getCurrentPeriodLabel()
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export class NavigationManager {
|
|||
this.eventBus = eventBus;
|
||||
DateCalculator.initialize(calendarConfig);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
this.navigationRenderer = new NavigationRenderer(eventBus, calendarConfig, eventRenderer);
|
||||
this.navigationRenderer = new NavigationRenderer(eventBus, eventRenderer);
|
||||
this.currentWeek = DateCalculator.getISOWeekStart(new Date());
|
||||
this.targetWeek = new Date(this.currentWeek);
|
||||
this.init();
|
||||
|
|
@ -239,7 +239,7 @@ export class NavigationManager {
|
|||
this.updateWeekInfo();
|
||||
|
||||
// Emit period change event for ScrollManager
|
||||
this.eventBus.emit(CoreEvents.PERIOD_CHANGED, {
|
||||
this.eventBus.emit(CoreEvents.NAVIGATION_COMPLETED, {
|
||||
direction,
|
||||
weekStart: this.currentWeek
|
||||
});
|
||||
|
|
@ -253,7 +253,7 @@ export class NavigationManager {
|
|||
const dateRange = DateCalculator.formatDateRange(this.currentWeek, weekEnd);
|
||||
|
||||
// Notify other managers about week info update - DOM manipulation should happen via events
|
||||
this.eventBus.emit(CoreEvents.WEEK_CHANGED, {
|
||||
this.eventBus.emit(CoreEvents.PERIOD_INFO_UPDATE, {
|
||||
weekNumber,
|
||||
dateRange,
|
||||
weekStart: this.currentWeek,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export class ScrollManager {
|
|||
|
||||
private subscribeToEvents(): void {
|
||||
// Handle navigation animation completion - sync time axis position
|
||||
eventBus.on(CoreEvents.PERIOD_CHANGED, () => {
|
||||
eventBus.on(CoreEvents.NAVIGATION_COMPLETED, () => {
|
||||
this.syncTimeAxisPosition();
|
||||
this.setupScrolling();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Work hours management for per-column scheduling
|
||||
|
||||
import { DateCalculator } from '../utils/DateCalculator';
|
||||
import { CalendarConfig } from '../core/CalendarConfig';
|
||||
import { calendarConfig } from '../core/CalendarConfig';
|
||||
|
||||
/**
|
||||
* Work hours for a specific day
|
||||
|
|
@ -33,13 +33,11 @@ export interface WorkScheduleConfig {
|
|||
* Manages work hours scheduling with weekly defaults and date-specific overrides
|
||||
*/
|
||||
export class WorkHoursManager {
|
||||
private config: CalendarConfig;
|
||||
private dateCalculator: DateCalculator;
|
||||
private workSchedule: WorkScheduleConfig;
|
||||
|
||||
constructor(config: CalendarConfig) {
|
||||
this.config = config;
|
||||
DateCalculator.initialize(config);
|
||||
constructor() {
|
||||
DateCalculator.initialize(calendarConfig);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
|
||||
// Default work schedule - will be loaded from JSON later
|
||||
|
|
@ -100,7 +98,7 @@ export class WorkHoursManager {
|
|||
return null; // Full day will be colored via CSS background
|
||||
}
|
||||
|
||||
const gridSettings = this.config.getGridSettings();
|
||||
const gridSettings = calendarConfig.getGridSettings();
|
||||
const dayStartHour = gridSettings.dayStartHour;
|
||||
const dayEndHour = gridSettings.dayEndHour;
|
||||
const hourHeight = gridSettings.hourHeight;
|
||||
|
|
@ -125,7 +123,7 @@ export class WorkHoursManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
const gridSettings = this.config.getGridSettings();
|
||||
const gridSettings = calendarConfig.getGridSettings();
|
||||
const dayStartHour = gridSettings.dayStartHour;
|
||||
const hourHeight = gridSettings.hourHeight;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue