Refactor calendar datasource architecture
Centralizes date calculation logic into DateColumnDataSource Improves separation of concerns across rendering components Key changes: - Introduces IColumnInfo interface for flexible column data - Moves date calculation from multiple managers to dedicated datasource - Removes duplicate date rendering logic - Prepares architecture for future resource-based views
This commit is contained in:
parent
75a2d4913e
commit
f86ae09ec3
15 changed files with 885 additions and 76 deletions
|
|
@ -5,6 +5,7 @@ import { eventBus } from '../core/EventBus';
|
|||
import { DateService } from '../utils/DateService';
|
||||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
import { TimeFormatter } from '../utils/TimeFormatter';
|
||||
import { IColumnInfo } from '../types/ColumnDataSource';
|
||||
|
||||
/**
|
||||
* GridRenderer - Centralized DOM rendering for calendar grid structure
|
||||
|
|
@ -111,7 +112,7 @@ export class GridRenderer {
|
|||
grid: HTMLElement,
|
||||
currentDate: Date,
|
||||
view: CalendarView = 'week',
|
||||
dates: Date[] = [],
|
||||
columns: IColumnInfo[] = [],
|
||||
events: ICalendarEvent[] = []
|
||||
): void {
|
||||
|
||||
|
|
@ -124,10 +125,10 @@ export class GridRenderer {
|
|||
|
||||
// Only clear and rebuild if grid is empty (first render)
|
||||
if (grid.children.length === 0) {
|
||||
this.createCompleteGridStructure(grid, currentDate, view, dates, events);
|
||||
this.createCompleteGridStructure(grid, currentDate, view, columns, events);
|
||||
} else {
|
||||
// Optimized update - only refresh dynamic content
|
||||
this.updateGridContent(grid, currentDate, view, dates, events);
|
||||
this.updateGridContent(grid, currentDate, view, columns, events);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ export class GridRenderer {
|
|||
grid: HTMLElement,
|
||||
currentDate: Date,
|
||||
view: CalendarView,
|
||||
dates: Date[],
|
||||
columns: IColumnInfo[],
|
||||
events: ICalendarEvent[]
|
||||
): void {
|
||||
// Create all elements in memory first for better performance
|
||||
|
|
@ -167,7 +168,7 @@ export class GridRenderer {
|
|||
fragment.appendChild(timeAxis);
|
||||
|
||||
// Create grid container with caching
|
||||
const gridContainer = this.createOptimizedGridContainer(dates, events);
|
||||
const gridContainer = this.createOptimizedGridContainer(columns, events);
|
||||
this.cachedGridContainer = gridContainer;
|
||||
fragment.appendChild(gridContainer);
|
||||
|
||||
|
|
@ -218,7 +219,7 @@ export class GridRenderer {
|
|||
* @returns Complete grid container element
|
||||
*/
|
||||
private createOptimizedGridContainer(
|
||||
dates: Date[],
|
||||
columns: IColumnInfo[],
|
||||
events: ICalendarEvent[]
|
||||
): HTMLElement {
|
||||
const gridContainer = document.createElement('swp-grid-container');
|
||||
|
|
@ -237,7 +238,7 @@ export class GridRenderer {
|
|||
|
||||
// Create column container
|
||||
const columnContainer = document.createElement('swp-day-columns');
|
||||
this.renderColumnContainer(columnContainer, dates, events);
|
||||
this.renderColumnContainer(columnContainer, columns, events);
|
||||
timeGrid.appendChild(columnContainer);
|
||||
|
||||
scrollableContent.appendChild(timeGrid);
|
||||
|
|
@ -259,12 +260,12 @@ export class GridRenderer {
|
|||
*/
|
||||
private renderColumnContainer(
|
||||
columnContainer: HTMLElement,
|
||||
dates: Date[],
|
||||
columns: IColumnInfo[],
|
||||
events: ICalendarEvent[]
|
||||
): void {
|
||||
// Delegate to ColumnRenderer
|
||||
this.columnRenderer.render(columnContainer, {
|
||||
dates: dates,
|
||||
columns: columns,
|
||||
config: this.config
|
||||
});
|
||||
}
|
||||
|
|
@ -285,14 +286,14 @@ export class GridRenderer {
|
|||
grid: HTMLElement,
|
||||
currentDate: Date,
|
||||
view: CalendarView,
|
||||
dates: Date[],
|
||||
columns: IColumnInfo[],
|
||||
events: ICalendarEvent[]
|
||||
): void {
|
||||
// Update column container if needed
|
||||
const columnContainer = grid.querySelector('swp-day-columns');
|
||||
if (columnContainer) {
|
||||
columnContainer.innerHTML = '';
|
||||
this.renderColumnContainer(columnContainer as HTMLElement, dates, events);
|
||||
this.renderColumnContainer(columnContainer as HTMLElement, columns, events);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -308,9 +309,9 @@ export class GridRenderer {
|
|||
* @param dates - Array of dates to render
|
||||
* @returns New grid element ready for animation
|
||||
*/
|
||||
public createNavigationGrid(parentContainer: HTMLElement, dates: Date[]): HTMLElement {
|
||||
public createNavigationGrid(parentContainer: HTMLElement, columns: IColumnInfo[]): HTMLElement {
|
||||
// Create grid structure without events (events rendered by EventRenderingService)
|
||||
const newGrid = this.createOptimizedGridContainer(dates, []);
|
||||
const newGrid = this.createOptimizedGridContainer(columns, []);
|
||||
|
||||
// Position new grid for animation - NO transform here, let Animation API handle it
|
||||
newGrid.style.position = 'absolute';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue