2025-08-07 00:15:44 +02:00
|
|
|
// Grid structure management - Simple CSS Grid Implementation with Strategy Pattern
|
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';
|
2025-08-07 00:15:44 +02:00
|
|
|
import { ResourceCalendarData } from '../types/CalendarTypes';
|
|
|
|
|
import { CalendarTypeFactory } from '../factories/CalendarTypeFactory';
|
|
|
|
|
import { HeaderRenderContext } from '../renderers/HeaderRenderer';
|
|
|
|
|
import { ColumnRenderContext } from '../renderers/ColumnRenderer';
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Grid position interface
|
|
|
|
|
*/
|
|
|
|
|
interface GridPosition {
|
|
|
|
|
minutes: number;
|
|
|
|
|
time: string;
|
|
|
|
|
y: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-08-07 00:15:44 +02:00
|
|
|
* Manages the calendar grid structure using simple CSS Grid with Strategy Pattern
|
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;
|
2025-08-04 23:55:04 +02:00
|
|
|
private allDayEvents: any[] = []; // Store all-day events for current week
|
2025-08-07 00:15:44 +02:00
|
|
|
private resourceData: ResourceCalendarData | null = null; // Store resource data for resource calendar
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private init(): void {
|
2025-08-07 00:15:44 +02:00
|
|
|
// Initialize the factory
|
|
|
|
|
CalendarTypeFactory.initialize();
|
|
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
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;
|
2025-08-05 21:56:06 +02:00
|
|
|
if (['dayStartHour', 'dayEndHour', 'hourHeight', 'view', 'weekDays', 'fitToWidth'].includes(detail.key)) {
|
2025-07-24 22:17:38 +02:00
|
|
|
this.render();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
// Re-render on calendar type change
|
|
|
|
|
eventBus.on(EventTypes.CALENDAR_TYPE_CHANGED, () => {
|
|
|
|
|
this.render();
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
// 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-08-04 23:55:04 +02:00
|
|
|
// Handle events loaded
|
|
|
|
|
eventBus.on(EventTypes.EVENTS_LOADED, (e: Event) => {
|
|
|
|
|
const detail = (e as CustomEvent).detail;
|
|
|
|
|
this.updateAllDayEvents(detail.events);
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
// Handle resource data loaded
|
|
|
|
|
eventBus.on(EventTypes.RESOURCE_DATA_LOADED, (e: Event) => {
|
|
|
|
|
const detail = (e as CustomEvent).detail;
|
|
|
|
|
this.resourceData = detail.resourceData;
|
|
|
|
|
console.log(`GridManager: Received resource data for ${this.resourceData!.resources.length} resources`);
|
|
|
|
|
|
|
|
|
|
// Update grid styles with new column count immediately
|
|
|
|
|
this.updateGridStyles();
|
|
|
|
|
|
|
|
|
|
// Re-render if grid is already rendered
|
|
|
|
|
if (this.grid && this.grid.children.length > 0) {
|
|
|
|
|
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-08-05 00:41:59 +02:00
|
|
|
// Only clear and rebuild if grid is empty (first render)
|
|
|
|
|
if (this.grid.children.length === 0) {
|
|
|
|
|
console.log('GridManager: First render - creating grid structure');
|
|
|
|
|
// Create POC structure: header-spacer + time-axis + week-container + right-column + bottom spacers
|
|
|
|
|
this.createHeaderSpacer();
|
|
|
|
|
this.createTimeAxis();
|
|
|
|
|
this.createWeekContainer();
|
|
|
|
|
} else {
|
|
|
|
|
console.log('GridManager: Re-render - updating existing structure');
|
2025-08-07 00:26:33 +02:00
|
|
|
// Just update the calendar header for all-day events
|
|
|
|
|
this.updateCalendarHeader();
|
2025-08-05 00:41:59 +02:00
|
|
|
}
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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-08-07 00:15:44 +02:00
|
|
|
* Create week container with header and scrollable content using Strategy Pattern
|
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-08-07 00:15:44 +02:00
|
|
|
const weekContainer = document.createElement('swp-grid-container');
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
// Create calendar header using Strategy Pattern
|
|
|
|
|
const calendarHeader = document.createElement('swp-calendar-header');
|
|
|
|
|
this.renderCalendarHeader(calendarHeader);
|
|
|
|
|
weekContainer.appendChild(calendarHeader);
|
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);
|
|
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
// Create column container using Strategy Pattern
|
|
|
|
|
const columnContainer = document.createElement('swp-day-columns');
|
|
|
|
|
this.renderColumnContainer(columnContainer);
|
|
|
|
|
timeGrid.appendChild(columnContainer);
|
2025-07-25 23:31:25 +02:00
|
|
|
|
|
|
|
|
scrollableContent.appendChild(timeGrid);
|
|
|
|
|
weekContainer.appendChild(scrollableContent);
|
|
|
|
|
|
|
|
|
|
this.grid.appendChild(weekContainer);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-29 21:22:13 +02:00
|
|
|
/**
|
2025-08-07 00:26:33 +02:00
|
|
|
* Render calendar header using Strategy Pattern
|
2025-07-29 21:22:13 +02:00
|
|
|
*/
|
2025-08-07 00:26:33 +02:00
|
|
|
private renderCalendarHeader(calendarHeader: HTMLElement): void {
|
2025-08-07 00:15:44 +02:00
|
|
|
if (!this.currentWeek) return;
|
2025-07-29 21:22:13 +02:00
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
const calendarType = calendarConfig.getCalendarType();
|
|
|
|
|
const headerRenderer = CalendarTypeFactory.getHeaderRenderer(calendarType);
|
|
|
|
|
|
|
|
|
|
const context: HeaderRenderContext = {
|
|
|
|
|
currentWeek: this.currentWeek,
|
|
|
|
|
config: calendarConfig,
|
|
|
|
|
allDayEvents: this.allDayEvents,
|
|
|
|
|
resourceData: this.resourceData
|
|
|
|
|
};
|
2025-07-29 23:01:00 +02:00
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
headerRenderer.render(calendarHeader, context);
|
2025-07-29 23:01:00 +02:00
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
// Update spacer heights based on all-day events
|
|
|
|
|
this.updateSpacerHeights();
|
2025-07-29 21:22:13 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 23:31:25 +02:00
|
|
|
/**
|
2025-08-07 00:26:33 +02:00
|
|
|
* Render column container using Strategy Pattern
|
2025-07-25 23:31:25 +02:00
|
|
|
*/
|
2025-08-07 00:26:33 +02:00
|
|
|
private renderColumnContainer(columnContainer: HTMLElement): void {
|
2025-07-25 23:31:25 +02:00
|
|
|
if (!this.currentWeek) return;
|
|
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
console.log('GridManager: renderColumnContainer called');
|
2025-08-07 00:15:44 +02:00
|
|
|
const calendarType = calendarConfig.getCalendarType();
|
|
|
|
|
const columnRenderer = CalendarTypeFactory.getColumnRenderer(calendarType);
|
|
|
|
|
|
|
|
|
|
const context: ColumnRenderContext = {
|
|
|
|
|
currentWeek: this.currentWeek,
|
|
|
|
|
config: calendarConfig,
|
|
|
|
|
resourceData: this.resourceData
|
|
|
|
|
};
|
2025-08-04 23:22:31 +02:00
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
columnRenderer.render(columnContainer, context);
|
2025-08-04 23:22:31 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-05 00:41:59 +02:00
|
|
|
/**
|
2025-08-07 00:26:33 +02:00
|
|
|
* Update only the calendar header (for all-day events) without rebuilding entire grid
|
2025-08-05 00:41:59 +02:00
|
|
|
*/
|
2025-08-07 00:26:33 +02:00
|
|
|
private updateCalendarHeader(): void {
|
2025-08-05 00:41:59 +02:00
|
|
|
if (!this.grid || !this.currentWeek) return;
|
|
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
const calendarHeader = this.grid.querySelector('swp-calendar-header');
|
|
|
|
|
if (!calendarHeader) return;
|
2025-08-05 00:41:59 +02:00
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
// Clear existing content
|
2025-08-07 00:26:33 +02:00
|
|
|
calendarHeader.innerHTML = '';
|
2025-08-05 00:41:59 +02:00
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
// Re-render headers using Strategy Pattern
|
2025-08-07 00:26:33 +02:00
|
|
|
this.renderCalendarHeader(calendarHeader as HTMLElement);
|
2025-08-05 00:41:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-04 23:55:04 +02:00
|
|
|
/**
|
|
|
|
|
* Update all-day events data and re-render if needed
|
|
|
|
|
*/
|
|
|
|
|
private updateAllDayEvents(events: any[]): void {
|
|
|
|
|
if (!this.currentWeek) return;
|
|
|
|
|
|
|
|
|
|
// Filter all-day events for current week
|
|
|
|
|
const weekStart = this.currentWeek;
|
|
|
|
|
const weekEnd = new Date(weekStart);
|
|
|
|
|
weekEnd.setDate(weekStart.getDate() + 6);
|
|
|
|
|
|
|
|
|
|
this.allDayEvents = events.filter(event => {
|
|
|
|
|
if (!event.allDay) return false;
|
|
|
|
|
|
|
|
|
|
const eventDate = new Date(event.start);
|
|
|
|
|
return eventDate >= weekStart && eventDate <= weekEnd;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log('GridManager: Updated all-day events:', this.allDayEvents.length);
|
|
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
// Update only the calendar header if grid is already rendered
|
2025-08-04 23:55:04 +02:00
|
|
|
if (this.grid && this.grid.children.length > 0) {
|
2025-08-07 00:26:33 +02:00
|
|
|
this.updateCalendarHeader();
|
2025-08-04 23:55:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 23:22:31 +02:00
|
|
|
/**
|
|
|
|
|
* Update spacer heights based on all-day events presence
|
|
|
|
|
*/
|
|
|
|
|
private updateSpacerHeights(): void {
|
2025-08-05 00:17:17 +02:00
|
|
|
const allDayEventCount = 1;
|
|
|
|
|
const eventHeight = 26; // Height per all-day event in pixels
|
|
|
|
|
const padding = 0; // Top/bottom padding
|
2025-08-04 23:55:04 +02:00
|
|
|
const allDayHeight = allDayEventCount > 0 ? (allDayEventCount * eventHeight) + padding : 0;
|
2025-08-04 23:22:31 +02:00
|
|
|
|
|
|
|
|
// Set CSS variable for dynamic spacer height
|
|
|
|
|
document.documentElement.style.setProperty('--all-day-row-height', `${allDayHeight}px`);
|
|
|
|
|
|
2025-08-04 23:55:04 +02:00
|
|
|
console.log('GridManager: Updated --all-day-row-height to', `${allDayHeight}px`, 'for', allDayEventCount, 'events');
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update grid CSS variables
|
|
|
|
|
*/
|
|
|
|
|
private updateGridStyles(): void {
|
|
|
|
|
const root = document.documentElement;
|
|
|
|
|
const config = calendarConfig.getAll();
|
2025-08-05 21:56:06 +02:00
|
|
|
const calendar = document.querySelector('swp-calendar') as HTMLElement;
|
2025-08-07 00:15:44 +02:00
|
|
|
const calendarType = calendarConfig.getCalendarType();
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
// 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-08-05 21:56:06 +02:00
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
// Set number of columns based on calendar type
|
|
|
|
|
let columnCount = 7; // Default for date mode
|
|
|
|
|
if (calendarType === 'resource' && this.resourceData) {
|
|
|
|
|
columnCount = this.resourceData.resources.length;
|
|
|
|
|
} else if (calendarType === 'date') {
|
|
|
|
|
columnCount = config.weekDays;
|
|
|
|
|
}
|
|
|
|
|
root.style.setProperty('--grid-columns', columnCount.toString());
|
|
|
|
|
|
2025-08-05 21:56:06 +02:00
|
|
|
// Set day column min width based on fitToWidth setting
|
|
|
|
|
if (config.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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set fitToWidth data attribute for CSS targeting
|
|
|
|
|
if (calendar) {
|
|
|
|
|
calendar.setAttribute('data-fit-to-width', config.fitToWidth.toString());
|
|
|
|
|
}
|
2025-08-07 00:15:44 +02:00
|
|
|
|
|
|
|
|
console.log('GridManager: Updated grid styles with', columnCount, 'columns for', calendarType, 'calendar');
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
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-08-07 00:15:44 +02:00
|
|
|
// Click handler for day columns (works for both date and resource columns)
|
2025-07-25 23:31:25 +02:00
|
|
|
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-08-07 00:15:44 +02:00
|
|
|
const dayColumn = (e.target as Element).closest('swp-day-column, swp-resource-column') as HTMLElement;
|
2025-07-25 23:31:25 +02:00
|
|
|
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-08-07 00:15:44 +02:00
|
|
|
resource: (dayColumn as any).dataset.resource,
|
|
|
|
|
employeeId: (dayColumn as any).dataset.employeeId,
|
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-08-07 00:15:44 +02:00
|
|
|
const dayColumn = (e.target as Element).closest('swp-day-column, swp-resource-column') as HTMLElement;
|
2025-07-25 23:31:25 +02:00
|
|
|
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-08-07 00:15:44 +02:00
|
|
|
resource: (dayColumn as any).dataset.resource,
|
|
|
|
|
employeeId: (dayColumn as any).dataset.employeeId,
|
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 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}`;
|
|
|
|
|
}
|
|
|
|
|
}
|