2025-08-07 00:15:44 +02:00
|
|
|
// Column rendering strategy interface and implementations
|
|
|
|
|
|
2025-11-03 21:30:50 +01:00
|
|
|
import { Configuration } from '../configuration/CalendarConfig';
|
2025-10-03 20:50:40 +02:00
|
|
|
import { DateService } from '../utils/DateService';
|
2025-08-22 22:57:35 +02:00
|
|
|
import { WorkHoursManager } from '../managers/WorkHoursManager';
|
2025-08-07 00:15:44 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface for column rendering strategies
|
|
|
|
|
*/
|
2025-11-03 21:30:50 +01:00
|
|
|
export interface IColumnRenderer {
|
|
|
|
|
render(columnContainer: HTMLElement, context: IColumnRenderContext): void;
|
2025-08-07 00:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Context for column rendering
|
|
|
|
|
*/
|
2025-11-03 21:30:50 +01:00
|
|
|
export interface IColumnRenderContext {
|
2025-08-07 00:15:44 +02:00
|
|
|
currentWeek: Date;
|
2025-11-03 21:30:50 +01:00
|
|
|
config: Configuration;
|
2025-08-07 00:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Date-based column renderer (original functionality)
|
|
|
|
|
*/
|
2025-11-03 21:30:50 +01:00
|
|
|
export class DateColumnRenderer implements IColumnRenderer {
|
2025-10-30 23:47:30 +01:00
|
|
|
private dateService: DateService;
|
|
|
|
|
private workHoursManager: WorkHoursManager;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
dateService: DateService,
|
|
|
|
|
workHoursManager: WorkHoursManager
|
|
|
|
|
) {
|
|
|
|
|
this.dateService = dateService;
|
|
|
|
|
this.workHoursManager = workHoursManager;
|
|
|
|
|
}
|
2025-08-18 23:42:03 +02:00
|
|
|
|
2025-11-03 21:30:50 +01:00
|
|
|
render(columnContainer: HTMLElement, context: IColumnRenderContext): void {
|
2025-08-07 00:15:44 +02:00
|
|
|
const { currentWeek, config } = context;
|
|
|
|
|
|
2025-10-03 20:50:40 +02:00
|
|
|
const workWeekSettings = config.getWorkWeekSettings();
|
|
|
|
|
const dates = this.dateService.getWorkWeekDates(currentWeek, workWeekSettings.workDays);
|
2025-08-09 01:16:04 +02:00
|
|
|
const dateSettings = config.getDateViewSettings();
|
|
|
|
|
const daysToShow = dates.slice(0, dateSettings.weekDays);
|
2025-08-07 00:15:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
daysToShow.forEach((date) => {
|
|
|
|
|
const column = document.createElement('swp-day-column');
|
2025-10-03 20:50:40 +02:00
|
|
|
(column as any).dataset.date = this.dateService.formatISODate(date);
|
2025-08-07 00:15:44 +02:00
|
|
|
|
2025-08-22 22:57:35 +02:00
|
|
|
// Apply work hours styling
|
|
|
|
|
this.applyWorkHoursToColumn(column, date);
|
|
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
const eventsLayer = document.createElement('swp-events-layer');
|
|
|
|
|
column.appendChild(eventsLayer);
|
|
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
columnContainer.appendChild(column);
|
2025-08-07 00:15:44 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-22 22:57:35 +02:00
|
|
|
private applyWorkHoursToColumn(column: HTMLElement, date: Date): void {
|
|
|
|
|
const workHours = this.workHoursManager.getWorkHoursForDate(date);
|
|
|
|
|
|
|
|
|
|
if (workHours === 'off') {
|
|
|
|
|
// No work hours - mark as off day (full day will be colored)
|
|
|
|
|
(column as any).dataset.workHours = 'off';
|
|
|
|
|
} else {
|
|
|
|
|
// Calculate and apply non-work hours overlays (before and after work)
|
|
|
|
|
const nonWorkStyle = this.workHoursManager.calculateNonWorkHoursStyle(workHours);
|
|
|
|
|
if (nonWorkStyle) {
|
|
|
|
|
// Before work overlay (::before pseudo-element)
|
|
|
|
|
column.style.setProperty('--before-work-height', `${nonWorkStyle.beforeWorkHeight}px`);
|
|
|
|
|
|
|
|
|
|
// After work overlay (::after pseudo-element)
|
|
|
|
|
column.style.setProperty('--after-work-top', `${nonWorkStyle.afterWorkTop}px`);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
}
|