2025-07-25 23:31:25 +02:00
|
|
|
// Grid structure management - Simple CSS Grid Implementation
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
import { eventBus } from '../core/EventBus';
|
|
|
|
|
import { calendarConfig } from '../core/CalendarConfig';
|
|
|
|
|
import { EventTypes } from '../constants/EventTypes';
|
|
|
|
|
import { DateUtils } from '../utils/DateUtils';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Grid position interface
|
|
|
|
|
*/
|
|
|
|
|
interface GridPosition {
|
|
|
|
|
minutes: number;
|
|
|
|
|
time: string;
|
|
|
|
|
y: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-25 23:31:25 +02:00
|
|
|
* Manages the calendar grid structure using simple CSS Grid
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
|
|
|
|
export class GridManager {
|
|
|
|
|
private container: HTMLElement | null = null;
|
2025-07-25 23:31:25 +02:00
|
|
|
private grid: HTMLElement | null = null;
|
2025-07-24 22:17:38 +02:00
|
|
|
private currentWeek: Date | null = null;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private init(): void {
|
|
|
|
|
this.findElements();
|
|
|
|
|
this.subscribeToEvents();
|
2025-07-25 23:31:25 +02:00
|
|
|
|
|
|
|
|
// Set initial current week to today if not set
|
|
|
|
|
if (!this.currentWeek) {
|
|
|
|
|
this.currentWeek = this.getWeekStart(new Date());
|
|
|
|
|
console.log('GridManager: Set initial currentWeek to', this.currentWeek);
|
|
|
|
|
// Render initial grid
|
|
|
|
|
this.render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getWeekStart(date: Date): Date {
|
2025-08-02 23:59:52 +02:00
|
|
|
// Use DateUtils for consistent week calculation (Sunday = 0)
|
|
|
|
|
return DateUtils.getWeekStart(date, 0);
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private findElements(): void {
|
2025-07-25 23:31:25 +02:00
|
|
|
this.grid = document.querySelector('swp-calendar-container');
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private subscribeToEvents(): void {
|
|
|
|
|
// Re-render grid on config changes
|
|
|
|
|
eventBus.on(EventTypes.CONFIG_UPDATE, (e: Event) => {
|
|
|
|
|
const detail = (e as CustomEvent).detail;
|
|
|
|
|
if (['dayStartHour', 'dayEndHour', 'hourHeight', 'view', 'weekDays'].includes(detail.key)) {
|
|
|
|
|
this.render();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Re-render on view change
|
|
|
|
|
eventBus.on(EventTypes.VIEW_CHANGE, () => {
|
|
|
|
|
this.render();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Re-render on period change
|
|
|
|
|
eventBus.on(EventTypes.PERIOD_CHANGE, (e: Event) => {
|
|
|
|
|
const detail = (e as CustomEvent).detail;
|
|
|
|
|
this.currentWeek = detail.week;
|
2025-07-25 23:31:25 +02:00
|
|
|
this.render();
|
2025-07-24 22:17:38 +02:00
|
|
|
});
|
|
|
|
|
|
2025-07-25 00:24:15 +02:00
|
|
|
// Handle week changes from NavigationManager
|
|
|
|
|
eventBus.on(EventTypes.WEEK_CHANGED, (e: Event) => {
|
|
|
|
|
const detail = (e as CustomEvent).detail;
|
|
|
|
|
this.currentWeek = detail.weekStart;
|
|
|
|
|
this.render();
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
// Handle grid clicks
|
|
|
|
|
this.setupGridInteractions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Render the complete grid structure
|
|
|
|
|
*/
|
|
|
|
|
render(): void {
|
2025-07-25 23:31:25 +02:00
|
|
|
if (!this.grid) return;
|
|
|
|
|
|
|
|
|
|
this.updateGridStyles();
|
2025-07-24 22:17:38 +02:00
|
|
|
this.renderGrid();
|
|
|
|
|
|
|
|
|
|
// Emit grid rendered event
|
2025-07-29 00:52:01 +02:00
|
|
|
console.log('GridManager: Emitting GRID_RENDERED event');
|
2025-07-24 22:17:38 +02:00
|
|
|
eventBus.emit(EventTypes.GRID_RENDERED);
|
2025-07-29 00:52:01 +02:00
|
|
|
console.log('GridManager: GRID_RENDERED event emitted');
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-25 23:31:25 +02:00
|
|
|
* Render the complete grid using POC structure
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
2025-07-25 23:31:25 +02:00
|
|
|
private renderGrid(): void {
|
|
|
|
|
console.log('GridManager: renderGrid called', {
|
|
|
|
|
hasGrid: !!this.grid,
|
|
|
|
|
hasCurrentWeek: !!this.currentWeek,
|
|
|
|
|
currentWeek: this.currentWeek
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!this.grid || !this.currentWeek) {
|
|
|
|
|
console.warn('GridManager: Cannot render - missing grid or currentWeek');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
// Clear existing grid and rebuild POC structure
|
|
|
|
|
this.grid.innerHTML = '';
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-29 23:01:00 +02:00
|
|
|
// Create POC structure: header-spacer + time-axis + week-container + right-column + bottom spacers
|
2025-07-29 00:52:01 +02:00
|
|
|
this.createHeaderSpacer();
|
2025-07-29 23:01:00 +02:00
|
|
|
this.createRightHeaderSpacer();
|
2025-07-25 23:31:25 +02:00
|
|
|
this.createTimeAxis();
|
|
|
|
|
this.createWeekContainer();
|
2025-07-29 23:01:00 +02:00
|
|
|
this.createRightColumn();
|
2025-07-29 21:22:13 +02:00
|
|
|
this.createBottomRow();
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
console.log('GridManager: Grid rendered successfully with POC structure');
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-29 00:52:01 +02:00
|
|
|
* Create header spacer to align time axis with week content
|
|
|
|
|
*/
|
|
|
|
|
private createHeaderSpacer(): void {
|
|
|
|
|
if (!this.grid) return;
|
|
|
|
|
|
|
|
|
|
const headerSpacer = document.createElement('swp-header-spacer');
|
|
|
|
|
this.grid.appendChild(headerSpacer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-29 23:01:00 +02:00
|
|
|
* Create right header spacer for scrollbar alignment
|
2025-07-29 00:52:01 +02:00
|
|
|
*/
|
2025-07-29 23:01:00 +02:00
|
|
|
private createRightHeaderSpacer(): void {
|
|
|
|
|
if (!this.grid) return;
|
|
|
|
|
|
|
|
|
|
const rightHeaderSpacer = document.createElement('swp-right-header-spacer');
|
|
|
|
|
this.grid.appendChild(rightHeaderSpacer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create right column for scrollbar area
|
|
|
|
|
*/
|
|
|
|
|
private createRightColumn(): void {
|
|
|
|
|
if (!this.grid) return;
|
2025-07-29 00:52:01 +02:00
|
|
|
|
|
|
|
|
const rightColumn = document.createElement('swp-right-column');
|
2025-07-29 23:01:00 +02:00
|
|
|
this.grid.appendChild(rightColumn);
|
2025-07-29 00:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-29 23:01:00 +02:00
|
|
|
|
2025-07-29 00:52:01 +02:00
|
|
|
/**
|
|
|
|
|
* Create time axis (positioned beside week container) like in POC
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
2025-07-25 23:31:25 +02:00
|
|
|
private createTimeAxis(): void {
|
|
|
|
|
if (!this.grid) return;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const timeAxis = document.createElement('swp-time-axis');
|
2025-08-01 23:45:13 +02:00
|
|
|
const timeAxisContent = document.createElement('swp-time-axis-content');
|
2025-07-25 23:31:25 +02:00
|
|
|
const startHour = calendarConfig.get('dayStartHour');
|
|
|
|
|
const endHour = calendarConfig.get('dayEndHour');
|
2025-08-02 00:28:45 +02:00
|
|
|
console.log('GridManager: Creating time axis - startHour:', startHour, 'endHour:', endHour);
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-29 00:52:01 +02:00
|
|
|
for (let hour = startHour; hour < endHour; hour++) {
|
2025-07-25 23:31:25 +02:00
|
|
|
const marker = document.createElement('swp-hour-marker');
|
|
|
|
|
const period = hour >= 12 ? 'PM' : 'AM';
|
|
|
|
|
const displayHour = hour > 12 ? hour - 12 : (hour === 0 ? 12 : hour);
|
|
|
|
|
marker.textContent = `${displayHour} ${period}`;
|
2025-08-01 23:45:13 +02:00
|
|
|
timeAxisContent.appendChild(marker);
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
2025-07-25 23:31:25 +02:00
|
|
|
|
2025-08-01 23:45:13 +02:00
|
|
|
timeAxis.appendChild(timeAxisContent);
|
2025-07-25 23:31:25 +02:00
|
|
|
this.grid.appendChild(timeAxis);
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-25 23:31:25 +02:00
|
|
|
* Create week container with header and scrollable content like in POC
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
2025-07-25 23:31:25 +02:00
|
|
|
private createWeekContainer(): void {
|
|
|
|
|
if (!this.grid || !this.currentWeek) return;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const weekContainer = document.createElement('swp-week-container');
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
// Create week header
|
|
|
|
|
const weekHeader = document.createElement('swp-week-header');
|
|
|
|
|
this.renderWeekHeaders(weekHeader);
|
|
|
|
|
weekContainer.appendChild(weekHeader);
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
// Create scrollable content
|
|
|
|
|
const scrollableContent = document.createElement('swp-scrollable-content');
|
|
|
|
|
const timeGrid = document.createElement('swp-time-grid');
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
// Add grid lines
|
|
|
|
|
const gridLines = document.createElement('swp-grid-lines');
|
|
|
|
|
timeGrid.appendChild(gridLines);
|
|
|
|
|
|
|
|
|
|
// Create day columns
|
|
|
|
|
const dayColumns = document.createElement('swp-day-columns');
|
|
|
|
|
this.renderDayColumns(dayColumns);
|
|
|
|
|
timeGrid.appendChild(dayColumns);
|
|
|
|
|
|
|
|
|
|
scrollableContent.appendChild(timeGrid);
|
|
|
|
|
weekContainer.appendChild(scrollableContent);
|
|
|
|
|
|
|
|
|
|
this.grid.appendChild(weekContainer);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-29 21:22:13 +02:00
|
|
|
/**
|
2025-07-29 23:01:00 +02:00
|
|
|
* Create bottom row with spacers
|
2025-07-29 21:22:13 +02:00
|
|
|
*/
|
|
|
|
|
private createBottomRow(): void {
|
|
|
|
|
if (!this.grid) return;
|
|
|
|
|
|
|
|
|
|
// Bottom spacer (left)
|
|
|
|
|
const bottomSpacer = document.createElement('swp-bottom-spacer');
|
|
|
|
|
this.grid.appendChild(bottomSpacer);
|
2025-07-29 23:01:00 +02:00
|
|
|
|
|
|
|
|
// Bottom middle spacer
|
|
|
|
|
const bottomMiddleSpacer = document.createElement('swp-bottom-middle-spacer');
|
|
|
|
|
this.grid.appendChild(bottomMiddleSpacer);
|
|
|
|
|
|
|
|
|
|
// Right bottom spacer
|
|
|
|
|
const rightBottomSpacer = document.createElement('swp-right-bottom-spacer');
|
|
|
|
|
this.grid.appendChild(rightBottomSpacer);
|
2025-07-29 21:22:13 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
/**
|
|
|
|
|
* Render week headers like in POC
|
|
|
|
|
*/
|
|
|
|
|
private renderWeekHeaders(weekHeader: HTMLElement): void {
|
|
|
|
|
if (!this.currentWeek) return;
|
|
|
|
|
|
|
|
|
|
const dates = this.getWeekDates(this.currentWeek);
|
|
|
|
|
const weekDays = calendarConfig.get('weekDays');
|
|
|
|
|
const daysToShow = dates.slice(0, weekDays);
|
|
|
|
|
|
|
|
|
|
daysToShow.forEach((date) => {
|
|
|
|
|
const header = document.createElement('swp-day-header');
|
|
|
|
|
if (this.isToday(date)) {
|
|
|
|
|
(header as any).dataset.today = 'true';
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
header.innerHTML = `
|
|
|
|
|
<swp-day-name>${this.getDayName(date)}</swp-day-name>
|
|
|
|
|
<swp-day-date>${date.getDate()}</swp-day-date>
|
|
|
|
|
`;
|
|
|
|
|
(header as any).dataset.date = this.formatDate(date);
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
weekHeader.appendChild(header);
|
|
|
|
|
});
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-25 23:31:25 +02:00
|
|
|
* Render day columns like in POC
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
2025-07-25 23:31:25 +02:00
|
|
|
private renderDayColumns(dayColumns: HTMLElement): void {
|
|
|
|
|
console.log('GridManager: renderDayColumns called');
|
|
|
|
|
if (!this.currentWeek) {
|
|
|
|
|
console.log('GridManager: No currentWeek, returning');
|
|
|
|
|
return;
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const dates = this.getWeekDates(this.currentWeek);
|
|
|
|
|
const weekDays = calendarConfig.get('weekDays');
|
|
|
|
|
const daysToShow = dates.slice(0, weekDays);
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
console.log('GridManager: About to render', daysToShow.length, 'day columns');
|
|
|
|
|
|
|
|
|
|
daysToShow.forEach((date, dayIndex) => {
|
|
|
|
|
const column = document.createElement('swp-day-column');
|
|
|
|
|
(column as any).dataset.date = this.formatDate(date);
|
|
|
|
|
|
|
|
|
|
const eventsLayer = document.createElement('swp-events-layer');
|
|
|
|
|
column.appendChild(eventsLayer);
|
|
|
|
|
|
|
|
|
|
dayColumns.appendChild(column);
|
|
|
|
|
});
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update grid CSS variables
|
|
|
|
|
*/
|
|
|
|
|
private updateGridStyles(): void {
|
|
|
|
|
const root = document.documentElement;
|
|
|
|
|
const config = calendarConfig.getAll();
|
|
|
|
|
|
|
|
|
|
// Set CSS variables
|
|
|
|
|
root.style.setProperty('--hour-height', `${config.hourHeight}px`);
|
|
|
|
|
root.style.setProperty('--minute-height', `${config.hourHeight / 60}px`);
|
|
|
|
|
root.style.setProperty('--snap-interval', config.snapInterval.toString());
|
|
|
|
|
root.style.setProperty('--day-start-hour', config.dayStartHour.toString());
|
|
|
|
|
root.style.setProperty('--day-end-hour', config.dayEndHour.toString());
|
|
|
|
|
root.style.setProperty('--work-start-hour', config.workStartHour.toString());
|
|
|
|
|
root.style.setProperty('--work-end-hour', config.workEndHour.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-25 23:31:25 +02:00
|
|
|
* Setup grid interaction handlers for POC structure
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
|
|
|
|
private setupGridInteractions(): void {
|
2025-07-25 23:31:25 +02:00
|
|
|
if (!this.grid) return;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
// Click handler for day columns
|
|
|
|
|
this.grid.addEventListener('click', (e: MouseEvent) => {
|
2025-07-24 22:17:38 +02:00
|
|
|
// Ignore if clicking on an event
|
|
|
|
|
if ((e.target as Element).closest('swp-event')) return;
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const dayColumn = (e.target as Element).closest('swp-day-column') as HTMLElement;
|
|
|
|
|
if (!dayColumn) return;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const position = this.getClickPosition(e, dayColumn);
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
eventBus.emit(EventTypes.GRID_CLICK, {
|
2025-07-25 23:31:25 +02:00
|
|
|
date: (dayColumn as any).dataset.date,
|
2025-07-24 22:17:38 +02:00
|
|
|
time: position.time,
|
2025-07-26 00:00:03 +02:00
|
|
|
minutes: position.minutes
|
2025-07-24 22:17:38 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
// Double click handler for day columns
|
|
|
|
|
this.grid.addEventListener('dblclick', (e: MouseEvent) => {
|
2025-07-24 22:17:38 +02:00
|
|
|
// Ignore if clicking on an event
|
|
|
|
|
if ((e.target as Element).closest('swp-event')) return;
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const dayColumn = (e.target as Element).closest('swp-day-column') as HTMLElement;
|
|
|
|
|
if (!dayColumn) return;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const position = this.getClickPosition(e, dayColumn);
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
eventBus.emit(EventTypes.GRID_DBLCLICK, {
|
2025-07-25 23:31:25 +02:00
|
|
|
date: (dayColumn as any).dataset.date,
|
2025-07-24 22:17:38 +02:00
|
|
|
time: position.time,
|
2025-07-26 00:00:03 +02:00
|
|
|
minutes: position.minutes
|
2025-07-24 22:17:38 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-25 23:31:25 +02:00
|
|
|
* Get click position in day column (POC structure)
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
2025-07-25 23:31:25 +02:00
|
|
|
private getClickPosition(event: MouseEvent, dayColumn: HTMLElement): GridPosition {
|
|
|
|
|
const rect = dayColumn.getBoundingClientRect();
|
|
|
|
|
const y = event.clientY - rect.top;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
const hourHeight = calendarConfig.get('hourHeight');
|
|
|
|
|
const minuteHeight = hourHeight / 60;
|
2025-07-24 22:17:38 +02:00
|
|
|
const snapInterval = calendarConfig.get('snapInterval');
|
|
|
|
|
const dayStartHour = calendarConfig.get('dayStartHour');
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
// Calculate total minutes from day start
|
|
|
|
|
let totalMinutes = Math.floor(y / minuteHeight);
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
// Snap to interval
|
2025-07-25 23:31:25 +02:00
|
|
|
totalMinutes = Math.round(totalMinutes / snapInterval) * snapInterval;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
// Add day start offset
|
2025-07-25 23:31:25 +02:00
|
|
|
totalMinutes += dayStartHour * 60;
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
minutes: totalMinutes,
|
|
|
|
|
time: this.minutesToTime(totalMinutes),
|
2025-07-25 23:31:25 +02:00
|
|
|
y: y
|
2025-07-24 22:17:38 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
/**
|
|
|
|
|
* Scroll to specific hour
|
|
|
|
|
*/
|
|
|
|
|
scrollToHour(hour: number): void {
|
|
|
|
|
if (!this.grid) return;
|
|
|
|
|
|
|
|
|
|
const hourHeight = calendarConfig.get('hourHeight');
|
|
|
|
|
const dayStartHour = calendarConfig.get('dayStartHour');
|
|
|
|
|
const headerHeight = 80; // Header row height
|
|
|
|
|
const scrollTop = headerHeight + ((hour - dayStartHour) * hourHeight);
|
|
|
|
|
|
|
|
|
|
this.grid.scrollTop = scrollTop;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
/**
|
|
|
|
|
* Utility methods
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private formatHour(hour: number): string {
|
|
|
|
|
const period = hour >= 12 ? 'PM' : 'AM';
|
|
|
|
|
const displayHour = hour > 12 ? hour - 12 : (hour === 0 ? 12 : hour);
|
|
|
|
|
return `${displayHour} ${period}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private formatDate(date: Date): string {
|
|
|
|
|
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getDayName(date: Date): string {
|
|
|
|
|
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
|
|
|
return days[date.getDay()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getWeekDates(weekStart: Date): Date[] {
|
|
|
|
|
const dates: Date[] = [];
|
|
|
|
|
for (let i = 0; i < 7; i++) {
|
|
|
|
|
const date = new Date(weekStart);
|
|
|
|
|
date.setDate(weekStart.getDate() + i);
|
|
|
|
|
dates.push(date);
|
|
|
|
|
}
|
|
|
|
|
return dates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private isToday(date: Date): boolean {
|
|
|
|
|
const today = new Date();
|
|
|
|
|
return date.toDateString() === today.toDateString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private minutesToTime(totalMinutes: number): string {
|
|
|
|
|
const hours = Math.floor(totalMinutes / 60);
|
|
|
|
|
const minutes = totalMinutes % 60;
|
|
|
|
|
const period = hours >= 12 ? 'PM' : 'AM';
|
|
|
|
|
const displayHour = hours > 12 ? hours - 12 : (hours === 0 ? 12 : hours);
|
|
|
|
|
|
|
|
|
|
return `${displayHour}:${minutes.toString().padStart(2, '0')} ${period}`;
|
|
|
|
|
}
|
|
|
|
|
}
|