2025-09-03 20:04:47 +02:00
|
|
|
import { calendarConfig } from '../core/CalendarConfig';
|
2025-08-17 22:54:00 +02:00
|
|
|
import { ResourceCalendarData } from '../types/CalendarTypes';
|
|
|
|
|
|
2025-09-23 20:44:15 +02:00
|
|
|
interface GridSettings {
|
|
|
|
|
hourHeight: number;
|
|
|
|
|
snapInterval: number;
|
|
|
|
|
dayStartHour: number;
|
|
|
|
|
dayEndHour: number;
|
|
|
|
|
workStartHour: number;
|
|
|
|
|
workEndHour: number;
|
|
|
|
|
fitToWidth?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-17 22:54:00 +02:00
|
|
|
/**
|
|
|
|
|
* GridStyleManager - Manages CSS variables and styling for the grid
|
|
|
|
|
* Separated from GridManager to follow Single Responsibility Principle
|
|
|
|
|
*/
|
|
|
|
|
export class GridStyleManager {
|
2025-09-03 20:04:47 +02:00
|
|
|
constructor() {
|
2025-08-17 22:54:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update all grid CSS variables
|
|
|
|
|
*/
|
|
|
|
|
public updateGridStyles(resourceData: ResourceCalendarData | null = null): void {
|
|
|
|
|
const root = document.documentElement;
|
2025-09-03 20:04:47 +02:00
|
|
|
const gridSettings = calendarConfig.getGridSettings();
|
2025-08-17 22:54:00 +02:00
|
|
|
const calendar = document.querySelector('swp-calendar') as HTMLElement;
|
2025-09-03 20:04:47 +02:00
|
|
|
const calendarType = calendarConfig.getCalendarMode();
|
2025-08-17 22:54:00 +02:00
|
|
|
|
|
|
|
|
// Set CSS variables for time and grid measurements
|
|
|
|
|
this.setTimeVariables(root, gridSettings);
|
|
|
|
|
|
|
|
|
|
// Set column count based on calendar type
|
|
|
|
|
const columnCount = this.calculateColumnCount(calendarType, resourceData);
|
|
|
|
|
root.style.setProperty('--grid-columns', columnCount.toString());
|
|
|
|
|
|
|
|
|
|
// Set column width based on fitToWidth setting
|
|
|
|
|
this.setColumnWidth(root, gridSettings);
|
|
|
|
|
|
|
|
|
|
// Set fitToWidth data attribute for CSS targeting
|
|
|
|
|
if (calendar) {
|
|
|
|
|
calendar.setAttribute('data-fit-to-width', gridSettings.fitToWidth.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set time-related CSS variables
|
|
|
|
|
*/
|
2025-09-23 20:44:15 +02:00
|
|
|
private setTimeVariables(root: HTMLElement, gridSettings: GridSettings): void {
|
2025-09-30 00:13:52 +02:00
|
|
|
root.style.setProperty('--header-height', '80px'); // Fixed header height
|
2025-08-17 22:54:00 +02:00
|
|
|
root.style.setProperty('--hour-height', `${gridSettings.hourHeight}px`);
|
|
|
|
|
root.style.setProperty('--minute-height', `${gridSettings.hourHeight / 60}px`);
|
|
|
|
|
root.style.setProperty('--snap-interval', gridSettings.snapInterval.toString());
|
|
|
|
|
root.style.setProperty('--day-start-hour', gridSettings.dayStartHour.toString());
|
|
|
|
|
root.style.setProperty('--day-end-hour', gridSettings.dayEndHour.toString());
|
|
|
|
|
root.style.setProperty('--work-start-hour', gridSettings.workStartHour.toString());
|
|
|
|
|
root.style.setProperty('--work-end-hour', gridSettings.workEndHour.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate number of columns based on calendar type and view
|
|
|
|
|
*/
|
|
|
|
|
private calculateColumnCount(calendarType: string, resourceData: ResourceCalendarData | null): number {
|
|
|
|
|
if (calendarType === 'resource' && resourceData) {
|
|
|
|
|
return resourceData.resources.length;
|
|
|
|
|
} else if (calendarType === 'date') {
|
2025-09-03 20:04:47 +02:00
|
|
|
const dateSettings = calendarConfig.getDateViewSettings();
|
|
|
|
|
const workWeekSettings = calendarConfig.getWorkWeekSettings();
|
2025-08-18 22:27:17 +02:00
|
|
|
|
2025-08-17 22:54:00 +02:00
|
|
|
switch (dateSettings.period) {
|
|
|
|
|
case 'day':
|
|
|
|
|
return 1;
|
|
|
|
|
case 'week':
|
2025-08-18 22:27:17 +02:00
|
|
|
return workWeekSettings.totalDays;
|
2025-08-17 22:54:00 +02:00
|
|
|
case 'month':
|
2025-08-18 22:27:17 +02:00
|
|
|
return workWeekSettings.totalDays; // Use work week for month view too
|
2025-08-17 22:54:00 +02:00
|
|
|
default:
|
2025-08-18 22:27:17 +02:00
|
|
|
return workWeekSettings.totalDays;
|
2025-08-17 22:54:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-03 20:04:47 +02:00
|
|
|
return calendarConfig.getWorkWeekSettings().totalDays; // Default to work week
|
2025-08-17 22:54:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set column width based on fitToWidth setting
|
|
|
|
|
*/
|
2025-09-23 20:44:15 +02:00
|
|
|
private setColumnWidth(root: HTMLElement, gridSettings: GridSettings): void {
|
2025-08-17 22:54:00 +02:00
|
|
|
if (gridSettings.fitToWidth) {
|
|
|
|
|
root.style.setProperty('--day-column-min-width', '50px'); // Small min-width allows columns to fit available space
|
|
|
|
|
} else {
|
|
|
|
|
root.style.setProperty('--day-column-min-width', '250px'); // Default min-width for horizontal scroll mode
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|