Refactor data source and configuration management

Abstracts column data source with interface
Updates managers to use configuration-driven view and date
Decouples datasource creation from individual managers

Improves flexibility and dependency injection for calendar components
This commit is contained in:
Janus C. H. Knudsen 2025-11-18 22:33:48 +01:00
parent 0f10d44037
commit 9d270217bd
6 changed files with 31 additions and 17 deletions

View file

@ -16,7 +16,7 @@ export class CalendarManager {
private eventRenderer: EventRenderingService;
private scrollManager: ScrollManager;
private config: Configuration;
private currentView: CalendarView = 'week';
private currentView: CalendarView;
private currentDate: Date = new Date();
private isInitialized: boolean = false;
@ -34,6 +34,7 @@ export class CalendarManager {
this.eventRenderer = eventRenderingService;
this.scrollManager = scrollManager;
this.config = config;
this.currentView = this.config.currentView;
this.setupEventListeners();
}

View file

@ -8,7 +8,7 @@ import { CoreEvents } from '../constants/CoreEvents';
import { CalendarView } from '../types/CalendarTypes';
import { GridRenderer } from '../renderers/GridRenderer';
import { DateService } from '../utils/DateService';
import { DateColumnDataSource } from '../datasources/DateColumnDataSource';
import { IColumnDataSource } from '../types/ColumnDataSource';
import { Configuration } from '../configurations/CalendarConfig';
import { EventManager } from './EventManager';
@ -22,20 +22,21 @@ export class GridManager {
private gridRenderer: GridRenderer;
private dateService: DateService;
private config: Configuration;
private dataSource: DateColumnDataSource;
private dataSource: IColumnDataSource;
private eventManager: EventManager;
constructor(
gridRenderer: GridRenderer,
dateService: DateService,
config: Configuration,
eventManager: EventManager
eventManager: EventManager,
dataSource: IColumnDataSource
) {
this.gridRenderer = gridRenderer;
this.dateService = dateService;
this.config = config;
this.eventManager = eventManager;
this.dataSource = new DateColumnDataSource(dateService, config, this.currentDate, this.currentView);
this.dataSource = dataSource;
this.init();
}

View file

@ -4,7 +4,7 @@ import { CoreEvents } from '../constants/CoreEvents';
import { IHeaderRenderer, IHeaderRenderContext } from '../renderers/DateHeaderRenderer';
import { IDragMouseEnterHeaderEventPayload, IDragMouseLeaveHeaderEventPayload, IHeaderReadyEventPayload } from '../types/EventTypes';
import { ColumnDetectionUtils } from '../utils/ColumnDetectionUtils';
import { DateColumnDataSource } from '../datasources/DateColumnDataSource';
import { IColumnDataSource } from '../types/ColumnDataSource';
/**
* HeaderManager - Handles all header-related event logic
@ -14,9 +14,9 @@ import { DateColumnDataSource } from '../datasources/DateColumnDataSource';
export class HeaderManager {
private headerRenderer: IHeaderRenderer;
private config: Configuration;
private dataSource: DateColumnDataSource;
private dataSource: IColumnDataSource;
constructor(headerRenderer: IHeaderRenderer, config: Configuration, dataSource: DateColumnDataSource) {
constructor(headerRenderer: IHeaderRenderer, config: Configuration, dataSource: IColumnDataSource) {
this.headerRenderer = headerRenderer;
this.config = config;
this.dataSource = dataSource;

View file

@ -5,7 +5,7 @@ import { CoreEvents } from '../constants/CoreEvents';
import { WeekInfoRenderer } from '../renderers/WeekInfoRenderer';
import { GridRenderer } from '../renderers/GridRenderer';
import { INavButtonClickedEventPayload } from '../types/EventTypes';
import { DateColumnDataSource } from '../datasources/DateColumnDataSource';
import { IColumnDataSource } from '../types/ColumnDataSource';
import { Configuration } from '../configurations/CalendarConfig';
export class NavigationManager {
@ -14,7 +14,7 @@ export class NavigationManager {
private gridRenderer: GridRenderer;
private dateService: DateService;
private config: Configuration;
private dataSource: DateColumnDataSource;
private dataSource: IColumnDataSource;
private currentWeek: Date;
private targetWeek: Date;
private animationQueue: number = 0;
@ -25,7 +25,8 @@ export class NavigationManager {
gridRenderer: GridRenderer,
dateService: DateService,
weekInfoRenderer: WeekInfoRenderer,
config: Configuration
config: Configuration,
dataSource: IColumnDataSource
) {
this.eventBus = eventBus;
this.dateService = dateService;
@ -34,7 +35,7 @@ export class NavigationManager {
this.config = config;
this.currentWeek = this.getISOWeekStart(new Date());
this.targetWeek = new Date(this.currentWeek);
this.dataSource = new DateColumnDataSource(dateService, config, this.currentWeek, 'week' as CalendarView);
this.dataSource = dataSource;
this.init();
}