2025-09-12 00:36:02 +02:00
|
|
|
// All-day row height management and animations
|
|
|
|
|
|
|
|
|
|
import { eventBus } from '../core/EventBus';
|
|
|
|
|
import { ALL_DAY_CONSTANTS } from '../core/CalendarConfig';
|
2025-09-13 00:39:56 +02:00
|
|
|
import { AllDayEventRenderer } from '../renderers/AllDayEventRenderer';
|
2025-09-27 15:01:22 +02:00
|
|
|
import { AllDayLayoutEngine, EventLayout } from '../utils/AllDayLayoutEngine';
|
2025-09-28 13:25:09 +02:00
|
|
|
import { ColumnBounds, ColumnDetectionUtils } from '../utils/ColumnDetectionUtils';
|
2025-09-13 00:39:56 +02:00
|
|
|
import { CalendarEvent } from '../types/CalendarTypes';
|
2025-09-21 15:48:13 +02:00
|
|
|
import {
|
|
|
|
|
DragMouseEnterHeaderEventPayload,
|
|
|
|
|
DragStartEventPayload,
|
|
|
|
|
DragMoveEventPayload,
|
2025-09-26 22:11:57 +02:00
|
|
|
DragEndEventPayload,
|
2025-10-01 21:27:13 +02:00
|
|
|
DragColumnChangeEventPayload,
|
|
|
|
|
HeaderReadyEventPayload
|
2025-09-21 15:48:13 +02:00
|
|
|
} from '../types/EventTypes';
|
2025-09-23 20:44:15 +02:00
|
|
|
import { DragOffset, MousePosition } from '../types/DragDropTypes';
|
2025-10-01 21:27:13 +02:00
|
|
|
import { CoreEvents } from '../constants/CoreEvents';
|
|
|
|
|
import { EventManager } from './EventManager';
|
2025-09-12 00:36:02 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AllDayManager - Handles all-day row height animations and management
|
2025-09-25 23:38:17 +02:00
|
|
|
* Uses AllDayLayoutEngine for all overlap detection and layout calculation
|
2025-09-12 00:36:02 +02:00
|
|
|
*/
|
|
|
|
|
export class AllDayManager {
|
2025-09-13 00:39:56 +02:00
|
|
|
private allDayEventRenderer: AllDayEventRenderer;
|
2025-10-01 21:27:13 +02:00
|
|
|
private eventManager: EventManager;
|
|
|
|
|
|
2025-09-25 23:38:17 +02:00
|
|
|
private layoutEngine: AllDayLayoutEngine | null = null;
|
2025-09-28 13:25:09 +02:00
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// State tracking for differential updates
|
2025-09-30 22:35:07 +02:00
|
|
|
private currentLayouts: EventLayout[] = [];
|
2025-09-26 22:11:57 +02:00
|
|
|
private currentAllDayEvents: CalendarEvent[] = [];
|
2025-10-01 21:27:13 +02:00
|
|
|
private currentWeekDates: ColumnBounds[] = [];
|
2025-09-30 22:35:07 +02:00
|
|
|
private newLayouts: EventLayout[] = [];
|
2025-09-12 00:36:02 +02:00
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
// Expand/collapse state
|
|
|
|
|
private isExpanded: boolean = false;
|
|
|
|
|
private actualRowCount: number = 0;
|
2025-10-02 15:37:01 +02:00
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
|
2025-10-01 21:27:13 +02:00
|
|
|
constructor(eventManager: EventManager) {
|
|
|
|
|
this.eventManager = eventManager;
|
2025-09-13 00:39:56 +02:00
|
|
|
this.allDayEventRenderer = new AllDayEventRenderer();
|
2025-10-02 15:37:01 +02:00
|
|
|
|
2025-10-02 01:03:35 +02:00
|
|
|
// Sync CSS variable with TypeScript constant to ensure consistency
|
|
|
|
|
document.documentElement.style.setProperty(
|
|
|
|
|
'--single-row-height',
|
|
|
|
|
`${ALL_DAY_CONSTANTS.EVENT_HEIGHT}px`
|
|
|
|
|
);
|
2025-10-02 15:37:01 +02:00
|
|
|
|
2025-09-13 00:39:56 +02:00
|
|
|
this.setupEventListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup event listeners for drag conversions
|
|
|
|
|
*/
|
|
|
|
|
private setupEventListeners(): void {
|
2025-09-21 15:48:13 +02:00
|
|
|
eventBus.on('drag:mouseenter-header', (event) => {
|
2025-09-29 20:50:52 +02:00
|
|
|
const payload = (event as CustomEvent<DragMouseEnterHeaderEventPayload>).detail;
|
2025-09-21 21:30:51 +02:00
|
|
|
|
2025-09-21 15:48:13 +02:00
|
|
|
console.log('🔄 AllDayManager: Received drag:mouseenter-header', {
|
2025-09-29 20:50:52 +02:00
|
|
|
targetDate: payload.targetColumn,
|
|
|
|
|
originalElementId: payload.originalElement?.dataset?.eventId,
|
|
|
|
|
originalElementTag: payload.originalElement?.tagName
|
2025-09-18 17:55:52 +02:00
|
|
|
});
|
2025-09-22 23:37:43 +02:00
|
|
|
|
2025-10-01 21:27:13 +02:00
|
|
|
this.handleConvertToAllDay(payload);
|
2025-09-13 00:39:56 +02:00
|
|
|
});
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-21 21:30:51 +02:00
|
|
|
eventBus.on('drag:mouseleave-header', (event) => {
|
|
|
|
|
const { originalElement, cloneElement } = (event as CustomEvent).detail;
|
2025-09-18 17:55:52 +02:00
|
|
|
|
2025-09-21 21:30:51 +02:00
|
|
|
console.log('🚪 AllDayManager: Received drag:mouseleave-header', {
|
|
|
|
|
originalElementId: originalElement?.dataset?.eventId
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-01 18:41:28 +02:00
|
|
|
//this.checkAndAnimateAllDayHeight();
|
2025-09-18 19:26:00 +02:00
|
|
|
});
|
2025-09-19 00:20:30 +02:00
|
|
|
|
|
|
|
|
// Listen for drag operations on all-day events
|
|
|
|
|
eventBus.on('drag:start', (event) => {
|
2025-09-26 22:53:49 +02:00
|
|
|
const { draggedElement, draggedClone, mouseOffset } = (event as CustomEvent<DragStartEventPayload>).detail;
|
2025-09-21 21:30:51 +02:00
|
|
|
|
2025-09-21 15:48:13 +02:00
|
|
|
// Check if this is an all-day event by checking if it's in all-day container
|
|
|
|
|
const isAllDayEvent = draggedElement.closest('swp-allday-container');
|
|
|
|
|
if (!isAllDayEvent) return; // Not an all-day event
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-21 15:48:13 +02:00
|
|
|
const eventId = draggedElement.dataset.eventId;
|
2025-09-19 00:20:30 +02:00
|
|
|
console.log('🎯 AllDayManager: Starting drag for all-day event', { eventId });
|
2025-09-21 15:48:13 +02:00
|
|
|
this.handleDragStart(draggedElement, eventId || '', mouseOffset);
|
2025-09-19 00:20:30 +02:00
|
|
|
});
|
|
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
eventBus.on('drag:column-change', (event) => {
|
2025-09-30 00:13:52 +02:00
|
|
|
const { originalElement: draggedElement, draggedClone, mousePosition } = (event as CustomEvent<DragColumnChangeEventPayload>).detail;
|
2025-09-28 13:25:09 +02:00
|
|
|
|
|
|
|
|
if (draggedClone == null)
|
2025-09-26 22:53:49 +02:00
|
|
|
return;
|
2025-09-21 15:48:13 +02:00
|
|
|
|
2025-09-26 22:53:49 +02:00
|
|
|
// Filter: Only handle events where clone IS an all-day event
|
|
|
|
|
if (!draggedClone.hasAttribute('data-allday')) {
|
|
|
|
|
return; // This is not an all-day event, let EventRendererManager handle it
|
2025-09-26 22:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-26 22:53:49 +02:00
|
|
|
console.log('🔄 AllDayManager: Handling drag:column-change for all-day event', {
|
2025-09-28 13:25:09 +02:00
|
|
|
eventId: draggedElement.dataset.eventId,
|
2025-09-26 22:53:49 +02:00
|
|
|
cloneId: draggedClone.dataset.eventId
|
|
|
|
|
});
|
2025-09-28 13:25:09 +02:00
|
|
|
|
2025-09-26 22:53:49 +02:00
|
|
|
this.handleColumnChange(draggedClone, mousePosition);
|
2025-09-19 00:20:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
eventBus.on('drag:end', (event) => {
|
2025-09-28 13:25:09 +02:00
|
|
|
let draggedElement: DragEndEventPayload = (event as CustomEvent<DragEndEventPayload>).detail;
|
2025-09-20 09:40:56 +02:00
|
|
|
|
2025-09-28 13:25:09 +02:00
|
|
|
if (draggedElement.target != 'swp-day-header') // we are not inside the swp-day-header, so just ignore.
|
2025-09-20 09:40:56 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-09-29 20:50:52 +02:00
|
|
|
this.handleDragEnd(draggedElement);
|
2025-09-19 00:20:30 +02:00
|
|
|
});
|
2025-09-22 17:51:24 +02:00
|
|
|
|
|
|
|
|
// Listen for drag cancellation to recalculate height
|
|
|
|
|
eventBus.on('drag:cancelled', (event) => {
|
|
|
|
|
const { draggedElement, reason } = (event as CustomEvent).detail;
|
2025-09-22 23:37:43 +02:00
|
|
|
|
2025-09-22 17:51:24 +02:00
|
|
|
console.log('🚫 AllDayManager: Drag cancelled', {
|
|
|
|
|
eventId: draggedElement?.dataset?.eventId,
|
|
|
|
|
reason
|
|
|
|
|
});
|
2025-09-22 23:37:43 +02:00
|
|
|
|
2025-09-22 17:51:24 +02:00
|
|
|
});
|
2025-09-22 21:53:18 +02:00
|
|
|
|
2025-10-01 21:27:13 +02:00
|
|
|
// Listen for header ready - when dates are populated with period data
|
|
|
|
|
eventBus.on('header:ready', (event: Event) => {
|
|
|
|
|
let headerReadyEventPayload = (event as CustomEvent<HeaderReadyEventPayload>).detail;
|
|
|
|
|
|
2025-10-01 21:47:05 +02:00
|
|
|
let startDate = new Date(headerReadyEventPayload.headerElements.at(0)!.date);
|
|
|
|
|
let endDate = new Date(headerReadyEventPayload.headerElements.at(-1)!.date);
|
2025-10-01 21:27:13 +02:00
|
|
|
|
2025-10-01 22:38:15 +02:00
|
|
|
let events: CalendarEvent[] = this.eventManager.getEventsForPeriod(startDate, endDate);
|
2025-10-01 21:27:13 +02:00
|
|
|
// Filter for all-day events
|
|
|
|
|
const allDayEvents = events.filter(event => event.allDay);
|
2025-10-01 21:47:05 +02:00
|
|
|
|
2025-10-02 01:03:35 +02:00
|
|
|
this.currentLayouts = this.calculateAllDayEventsLayout(allDayEvents, headerReadyEventPayload.headerElements)
|
2025-10-01 21:27:13 +02:00
|
|
|
|
2025-10-02 15:37:01 +02:00
|
|
|
this.allDayEventRenderer.renderAllDayEventsForPeriod(this.currentLayouts);
|
2025-10-01 21:27:13 +02:00
|
|
|
this.checkAndAnimateAllDayHeight();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
eventBus.on(CoreEvents.VIEW_CHANGED, (event: Event) => {
|
|
|
|
|
this.allDayEventRenderer.handleViewChanged(event as CustomEvent);
|
|
|
|
|
});
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getAllDayContainer(): HTMLElement | null {
|
2025-09-22 23:37:43 +02:00
|
|
|
return document.querySelector('swp-calendar-header swp-allday-container');
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getCalendarHeader(): HTMLElement | null {
|
2025-09-22 23:37:43 +02:00
|
|
|
return document.querySelector('swp-calendar-header');
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getHeaderSpacer(): HTMLElement | null {
|
2025-09-22 23:37:43 +02:00
|
|
|
return document.querySelector('swp-header-spacer');
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate all-day height based on number of rows
|
|
|
|
|
*/
|
|
|
|
|
private calculateAllDayHeight(targetRows: number): {
|
|
|
|
|
targetHeight: number;
|
|
|
|
|
currentHeight: number;
|
|
|
|
|
heightDifference: number;
|
|
|
|
|
} {
|
|
|
|
|
const root = document.documentElement;
|
2025-10-02 01:03:35 +02:00
|
|
|
const targetHeight = targetRows * ALL_DAY_CONSTANTS.SINGLE_ROW_HEIGHT + 2;
|
2025-09-25 23:38:17 +02:00
|
|
|
// Read CSS variable directly from style property or default to 0
|
|
|
|
|
const currentHeightStr = root.style.getPropertyValue('--all-day-row-height') || '0px';
|
|
|
|
|
const currentHeight = parseInt(currentHeightStr) || 0;
|
2025-09-12 00:36:02 +02:00
|
|
|
const heightDifference = targetHeight - currentHeight;
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
return { targetHeight, currentHeight, heightDifference };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Collapse all-day row when no events
|
|
|
|
|
*/
|
|
|
|
|
public collapseAllDayRow(): void {
|
|
|
|
|
this.animateToRows(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check current all-day events and animate to correct height
|
|
|
|
|
*/
|
|
|
|
|
public checkAndAnimateAllDayHeight(): void {
|
|
|
|
|
// Calculate required rows - 0 if no events (will collapse)
|
|
|
|
|
let maxRows = 0;
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-30 22:49:16 +02:00
|
|
|
if (this.currentLayouts.length > 0) {
|
|
|
|
|
// Find the HIGHEST row number in use from currentLayouts
|
2025-09-25 18:17:37 +02:00
|
|
|
let highestRow = 0;
|
2025-09-22 23:37:43 +02:00
|
|
|
|
2025-09-30 22:49:16 +02:00
|
|
|
this.currentLayouts.forEach((layout) => {
|
|
|
|
|
highestRow = Math.max(highestRow, layout.row);
|
2025-09-21 22:13:31 +02:00
|
|
|
});
|
2025-09-22 23:37:43 +02:00
|
|
|
|
2025-09-25 18:17:37 +02:00
|
|
|
// Max rows = highest row number (e.g. if row 3 is used, height = 3 rows)
|
|
|
|
|
maxRows = highestRow;
|
2025-10-02 15:37:01 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
// Store actual row count
|
|
|
|
|
this.actualRowCount = maxRows;
|
|
|
|
|
|
|
|
|
|
// Determine what to display
|
|
|
|
|
let displayRows = maxRows;
|
2025-09-30 22:35:07 +02:00
|
|
|
|
2025-10-02 15:37:01 +02:00
|
|
|
if (maxRows > ALL_DAY_CONSTANTS.MAX_COLLAPSED_ROWS) {
|
2025-09-30 00:34:27 +02:00
|
|
|
// Show chevron button
|
|
|
|
|
this.updateChevronButton(true);
|
2025-09-30 22:35:07 +02:00
|
|
|
|
2025-09-30 15:24:58 +02:00
|
|
|
// Show 4 rows when collapsed (3 events + indicators)
|
2025-09-30 00:34:27 +02:00
|
|
|
if (!this.isExpanded) {
|
2025-09-30 22:49:16 +02:00
|
|
|
|
2025-10-02 15:37:01 +02:00
|
|
|
displayRows = ALL_DAY_CONSTANTS.MAX_COLLAPSED_ROWS;
|
2025-09-30 15:24:58 +02:00
|
|
|
this.updateOverflowIndicators();
|
2025-09-30 22:49:16 +02:00
|
|
|
|
2025-09-30 15:24:58 +02:00
|
|
|
} else {
|
2025-09-30 22:49:16 +02:00
|
|
|
|
2025-09-30 15:24:58 +02:00
|
|
|
this.clearOverflowIndicators();
|
2025-09-30 22:49:16 +02:00
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2025-10-01 18:41:28 +02:00
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
// Hide chevron - not needed
|
|
|
|
|
this.updateChevronButton(false);
|
2025-09-30 15:24:58 +02:00
|
|
|
this.clearOverflowIndicators();
|
2025-09-30 00:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
// Animate to required rows (0 = collapse, >0 = expand)
|
2025-09-30 00:34:27 +02:00
|
|
|
this.animateToRows(displayRows);
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Animate all-day container to specific number of rows
|
|
|
|
|
*/
|
|
|
|
|
public animateToRows(targetRows: number): void {
|
|
|
|
|
const { targetHeight, currentHeight, heightDifference } = this.calculateAllDayHeight(targetRows);
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
if (targetHeight === currentHeight) return; // No animation needed
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
console.log(`🎬 All-day height animation: ${currentHeight}px → ${targetHeight}px (${Math.ceil(currentHeight / ALL_DAY_CONSTANTS.SINGLE_ROW_HEIGHT)} → ${targetRows} rows)`);
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
// Get cached elements
|
|
|
|
|
const calendarHeader = this.getCalendarHeader();
|
|
|
|
|
const headerSpacer = this.getHeaderSpacer();
|
|
|
|
|
const allDayContainer = this.getAllDayContainer();
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
if (!calendarHeader || !allDayContainer) return;
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
// Get current parent height for animation
|
|
|
|
|
const currentParentHeight = parseFloat(getComputedStyle(calendarHeader).height);
|
|
|
|
|
const targetParentHeight = currentParentHeight + heightDifference;
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
const animations = [
|
|
|
|
|
calendarHeader.animate([
|
|
|
|
|
{ height: `${currentParentHeight}px` },
|
|
|
|
|
{ height: `${targetParentHeight}px` }
|
|
|
|
|
], {
|
2025-09-22 23:37:43 +02:00
|
|
|
duration: 150,
|
2025-09-12 00:36:02 +02:00
|
|
|
easing: 'ease-out',
|
|
|
|
|
fill: 'forwards'
|
|
|
|
|
})
|
|
|
|
|
];
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-23 16:30:30 +02:00
|
|
|
// Add spacer animation if spacer exists, but don't use fill: 'forwards'
|
2025-09-12 00:36:02 +02:00
|
|
|
if (headerSpacer) {
|
|
|
|
|
const root = document.documentElement;
|
2025-09-25 23:38:17 +02:00
|
|
|
const headerHeightStr = root.style.getPropertyValue('--header-height');
|
|
|
|
|
const headerHeight = parseInt(headerHeightStr);
|
|
|
|
|
const currentSpacerHeight = headerHeight + currentHeight;
|
|
|
|
|
const targetSpacerHeight = headerHeight + targetHeight;
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
animations.push(
|
|
|
|
|
headerSpacer.animate([
|
|
|
|
|
{ height: `${currentSpacerHeight}px` },
|
|
|
|
|
{ height: `${targetSpacerHeight}px` }
|
|
|
|
|
], {
|
2025-09-23 09:46:47 +02:00
|
|
|
duration: 150,
|
2025-09-23 16:30:30 +02:00
|
|
|
easing: 'ease-out'
|
|
|
|
|
// No fill: 'forwards' - let CSS calc() take over after animation
|
2025-09-12 00:36:02 +02:00
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
// Update CSS variable after animation
|
|
|
|
|
Promise.all(animations.map(anim => anim.finished)).then(() => {
|
|
|
|
|
const root = document.documentElement;
|
|
|
|
|
root.style.setProperty('--all-day-row-height', `${targetHeight}px`);
|
|
|
|
|
eventBus.emit('header:height-changed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
|
2025-09-25 23:38:17 +02:00
|
|
|
/**
|
|
|
|
|
* Calculate layout for ALL all-day events using AllDayLayoutEngine
|
|
|
|
|
* This is the correct method that processes all events together for proper overlap detection
|
|
|
|
|
*/
|
2025-10-01 21:47:05 +02:00
|
|
|
private calculateAllDayEventsLayout(events: CalendarEvent[], dayHeaders: ColumnBounds[]): EventLayout[] {
|
2025-09-28 13:25:09 +02:00
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// Store current state
|
|
|
|
|
this.currentAllDayEvents = events;
|
2025-10-01 21:47:05 +02:00
|
|
|
this.currentWeekDates = dayHeaders;
|
2025-09-28 13:25:09 +02:00
|
|
|
|
2025-09-25 23:38:17 +02:00
|
|
|
// Initialize layout engine with provided week dates
|
2025-10-01 21:47:05 +02:00
|
|
|
let layoutEngine = new AllDayLayoutEngine(dayHeaders.map(column => column.date));
|
2025-09-28 13:25:09 +02:00
|
|
|
|
2025-09-25 23:38:17 +02:00
|
|
|
// Calculate layout for all events together - AllDayLayoutEngine handles CalendarEvents directly
|
2025-09-30 22:35:07 +02:00
|
|
|
return layoutEngine.calculateLayout(events);
|
2025-09-28 13:25:09 +02:00
|
|
|
|
2025-09-25 23:38:17 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-13 00:39:56 +02:00
|
|
|
/**
|
2025-09-26 22:11:57 +02:00
|
|
|
* Handle conversion of timed event to all-day event - SIMPLIFIED
|
|
|
|
|
* During drag: Place in row 1 only, calculate column from targetDate
|
2025-09-13 00:39:56 +02:00
|
|
|
*/
|
2025-09-29 20:50:52 +02:00
|
|
|
private handleConvertToAllDay(payload: DragMouseEnterHeaderEventPayload): void {
|
2025-09-30 00:13:52 +02:00
|
|
|
|
2025-09-30 22:35:07 +02:00
|
|
|
if (payload.draggedClone?.dataset == null)
|
2025-09-30 00:13:52 +02:00
|
|
|
console.error("payload.cloneElement.dataset.eventId is null");
|
|
|
|
|
|
|
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
console.log('🔄 AllDayManager: Converting to all-day (row 1 only during drag)', {
|
2025-09-30 00:13:52 +02:00
|
|
|
eventId: payload.draggedClone.dataset.eventId,
|
2025-09-29 20:50:52 +02:00
|
|
|
targetDate: payload.targetColumn
|
2025-09-21 21:30:51 +02:00
|
|
|
});
|
2025-09-13 00:39:56 +02:00
|
|
|
|
2025-09-21 21:30:51 +02:00
|
|
|
// Get all-day container, request creation if needed
|
|
|
|
|
let allDayContainer = this.getAllDayContainer();
|
2025-09-16 23:09:56 +02:00
|
|
|
|
2025-09-25 23:38:17 +02:00
|
|
|
|
2025-09-30 00:13:52 +02:00
|
|
|
payload.draggedClone.removeAttribute('style');
|
|
|
|
|
payload.draggedClone.style.gridRow = '1';
|
|
|
|
|
payload.draggedClone.style.gridColumn = payload.targetColumn.index.toString();
|
|
|
|
|
payload.draggedClone.dataset.allday = 'true'; // Set the all-day attribute for filtering
|
2025-09-21 21:30:51 +02:00
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// Add to container
|
2025-09-30 00:13:52 +02:00
|
|
|
allDayContainer?.appendChild(payload.draggedClone);
|
2025-09-30 22:35:07 +02:00
|
|
|
|
2025-09-30 00:13:52 +02:00
|
|
|
ColumnDetectionUtils.updateColumnBoundsCache();
|
2025-09-21 22:17:24 +02:00
|
|
|
|
2025-09-21 21:30:51 +02:00
|
|
|
}
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-18 17:55:52 +02:00
|
|
|
|
2025-09-19 00:20:30 +02:00
|
|
|
/**
|
|
|
|
|
* Handle drag start for all-day events
|
|
|
|
|
*/
|
2025-09-23 20:44:15 +02:00
|
|
|
private handleDragStart(originalElement: HTMLElement, eventId: string, mouseOffset: DragOffset): void {
|
2025-09-19 00:20:30 +02:00
|
|
|
// Create clone
|
|
|
|
|
const clone = originalElement.cloneNode(true) as HTMLElement;
|
|
|
|
|
clone.dataset.eventId = `clone-${eventId}`;
|
|
|
|
|
|
|
|
|
|
// Get container
|
|
|
|
|
const container = this.getAllDayContainer();
|
|
|
|
|
if (!container) return;
|
|
|
|
|
|
|
|
|
|
// Add clone to container
|
|
|
|
|
container.appendChild(clone);
|
|
|
|
|
|
|
|
|
|
// Copy positioning from original
|
|
|
|
|
clone.style.gridColumn = originalElement.style.gridColumn;
|
|
|
|
|
clone.style.gridRow = originalElement.style.gridRow;
|
|
|
|
|
|
|
|
|
|
// Add dragging style
|
|
|
|
|
clone.classList.add('dragging');
|
|
|
|
|
clone.style.zIndex = '1000';
|
|
|
|
|
clone.style.cursor = 'grabbing';
|
|
|
|
|
|
|
|
|
|
// Make original semi-transparent
|
|
|
|
|
originalElement.style.opacity = '0.3';
|
|
|
|
|
|
|
|
|
|
console.log('✅ AllDayManager: Created drag clone for all-day event', {
|
|
|
|
|
eventId,
|
|
|
|
|
cloneId: clone.dataset.eventId,
|
|
|
|
|
gridColumn: clone.style.gridColumn,
|
|
|
|
|
gridRow: clone.style.gridRow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-26 22:11:57 +02:00
|
|
|
* Handle drag move for all-day events - SPECIALIZED FOR ALL-DAY CONTAINER
|
2025-09-19 00:20:30 +02:00
|
|
|
*/
|
2025-09-26 22:11:57 +02:00
|
|
|
private handleColumnChange(dragClone: HTMLElement, mousePosition: MousePosition): void {
|
|
|
|
|
// Get the all-day container to understand its grid structure
|
|
|
|
|
const allDayContainer = this.getAllDayContainer();
|
|
|
|
|
if (!allDayContainer) return;
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// Calculate target column using ColumnDetectionUtils
|
2025-09-28 13:25:09 +02:00
|
|
|
const targetColumn = ColumnDetectionUtils.getColumnBounds(mousePosition);
|
|
|
|
|
|
|
|
|
|
if (targetColumn == null)
|
|
|
|
|
return;
|
2025-09-26 22:11:57 +02:00
|
|
|
|
|
|
|
|
// Update clone position - ALWAYS keep in row 1 during drag
|
|
|
|
|
// Use simple grid positioning that matches all-day container structure
|
2025-09-28 13:25:09 +02:00
|
|
|
dragClone.style.gridColumn = targetColumn.index.toString();
|
2025-09-26 22:11:57 +02:00
|
|
|
dragClone.style.gridRow = '1'; // Force row 1 during drag
|
2025-09-28 13:25:09 +02:00
|
|
|
dragClone.style.gridArea = `1 / ${targetColumn.index} / 2 / ${targetColumn.index + 1}`;
|
2025-09-19 00:20:30 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-26 22:11:57 +02:00
|
|
|
* Handle drag end for all-day events - WITH DIFFERENTIAL UPDATES
|
2025-09-19 00:20:30 +02:00
|
|
|
*/
|
2025-09-28 13:25:09 +02:00
|
|
|
private handleDragEnd(dragEndEvent: DragEndEventPayload): void {
|
2025-09-26 22:11:57 +02:00
|
|
|
|
2025-09-28 13:25:09 +02:00
|
|
|
if (dragEndEvent.draggedClone == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// 2. Normalize clone ID
|
2025-10-01 18:41:28 +02:00
|
|
|
dragEndEvent.draggedClone.dataset.eventId = dragEndEvent.draggedClone.dataset.eventId?.replace('clone-', '');
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// 3. Create temporary array with existing events + the dropped event
|
2025-09-28 13:25:09 +02:00
|
|
|
let eventId = dragEndEvent.draggedClone.dataset.eventId;
|
|
|
|
|
let eventDate = dragEndEvent.finalPosition.column?.date;
|
|
|
|
|
let eventType = dragEndEvent.draggedClone.dataset.type;
|
|
|
|
|
|
|
|
|
|
if (eventDate == null || eventId == null || eventType == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
const droppedEvent: CalendarEvent = {
|
2025-09-28 13:25:09 +02:00
|
|
|
id: eventId,
|
2025-10-01 21:27:13 +02:00
|
|
|
title: dragEndEvent.draggedClone.dataset.title || '',
|
2025-09-28 13:25:09 +02:00
|
|
|
start: new Date(eventDate),
|
|
|
|
|
end: new Date(eventDate),
|
|
|
|
|
type: eventType,
|
2025-09-26 22:11:57 +02:00
|
|
|
allDay: true,
|
|
|
|
|
syncStatus: 'synced'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Use current events + dropped event for calculation
|
|
|
|
|
const tempEvents = [...this.currentAllDayEvents, droppedEvent];
|
|
|
|
|
|
|
|
|
|
// 4. Calculate new layouts for ALL events
|
2025-09-30 22:35:07 +02:00
|
|
|
this.newLayouts = this.calculateAllDayEventsLayout(tempEvents, this.currentWeekDates);
|
2025-09-26 22:11:57 +02:00
|
|
|
|
|
|
|
|
// 5. Apply differential updates - only update events that changed
|
|
|
|
|
let changedCount = 0;
|
2025-09-30 22:35:07 +02:00
|
|
|
this.newLayouts.forEach((layout) => {
|
|
|
|
|
// Find current layout for this event
|
2025-10-01 22:38:15 +02:00
|
|
|
let currentLayout = this.currentLayouts.find(old => old.calenderEvent.id === layout.calenderEvent.id);
|
2025-09-26 22:11:57 +02:00
|
|
|
|
2025-10-01 18:41:28 +02:00
|
|
|
if (currentLayout?.gridArea !== layout.gridArea) {
|
2025-09-26 22:11:57 +02:00
|
|
|
changedCount++;
|
2025-09-30 22:35:07 +02:00
|
|
|
const element = dragEndEvent.draggedClone;
|
2025-09-26 22:11:57 +02:00
|
|
|
if (element) {
|
|
|
|
|
// Add transition class for smooth animation
|
|
|
|
|
element.classList.add('transitioning');
|
2025-10-01 18:41:28 +02:00
|
|
|
element.style.gridArea = layout.gridArea;
|
2025-09-26 22:11:57 +02:00
|
|
|
element.style.gridRow = layout.row.toString();
|
|
|
|
|
element.style.gridColumn = `${layout.startColumn} / ${layout.endColumn + 1}`;
|
|
|
|
|
|
2025-10-02 15:37:01 +02:00
|
|
|
if (layout.row > ALL_DAY_CONSTANTS.MAX_COLLAPSED_ROWS)
|
2025-10-02 15:57:11 +02:00
|
|
|
element.classList.add('max-event-overflow-hide');
|
2025-10-02 15:37:01 +02:00
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// Remove transition class after animation
|
|
|
|
|
setTimeout(() => element.classList.remove('transitioning'), 200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-09-30 22:35:07 +02:00
|
|
|
if (changedCount > 0)
|
|
|
|
|
this.currentLayouts = this.newLayouts;
|
|
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// 6. Clean up drag styles from the dropped clone
|
2025-09-28 13:25:09 +02:00
|
|
|
dragEndEvent.draggedClone.classList.remove('dragging');
|
|
|
|
|
dragEndEvent.draggedClone.style.zIndex = '';
|
|
|
|
|
dragEndEvent.draggedClone.style.cursor = '';
|
|
|
|
|
dragEndEvent.draggedClone.style.opacity = '';
|
2025-09-19 00:20:30 +02:00
|
|
|
|
2025-09-26 22:11:57 +02:00
|
|
|
// 7. Restore original element opacity
|
2025-09-30 22:35:07 +02:00
|
|
|
dragEndEvent.originalElement.remove(); //TODO: this should be an event that only fade and remove if confirmed dragdrop
|
2025-09-26 22:11:57 +02:00
|
|
|
|
|
|
|
|
// 8. Check if height adjustment is needed
|
|
|
|
|
this.checkAndAnimateAllDayHeight();
|
|
|
|
|
|
2025-09-25 23:38:17 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
/**
|
|
|
|
|
* Update chevron button visibility and state
|
|
|
|
|
*/
|
|
|
|
|
private updateChevronButton(show: boolean): void {
|
|
|
|
|
const headerSpacer = this.getHeaderSpacer();
|
|
|
|
|
if (!headerSpacer) return;
|
2025-09-30 22:35:07 +02:00
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
let chevron = headerSpacer.querySelector('.allday-chevron') as HTMLElement;
|
2025-09-30 22:35:07 +02:00
|
|
|
|
2025-09-30 00:34:27 +02:00
|
|
|
if (show && !chevron) {
|
|
|
|
|
// Create chevron button
|
|
|
|
|
chevron = document.createElement('button');
|
|
|
|
|
chevron.className = 'allday-chevron collapsed';
|
|
|
|
|
chevron.innerHTML = `
|
|
|
|
|
<svg width="12" height="8" viewBox="0 0 12 8">
|
|
|
|
|
<path d="M1 1.5L6 6.5L11 1.5" stroke="currentColor" stroke-width="2" fill="none"/>
|
|
|
|
|
</svg>
|
|
|
|
|
`;
|
|
|
|
|
chevron.onclick = () => this.toggleExpanded();
|
|
|
|
|
headerSpacer.appendChild(chevron);
|
|
|
|
|
} else if (!show && chevron) {
|
|
|
|
|
// Remove chevron button
|
|
|
|
|
chevron.remove();
|
|
|
|
|
} else if (chevron) {
|
|
|
|
|
// Update chevron state
|
|
|
|
|
chevron.classList.toggle('collapsed', !this.isExpanded);
|
|
|
|
|
chevron.classList.toggle('expanded', this.isExpanded);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle between expanded and collapsed state
|
|
|
|
|
*/
|
|
|
|
|
private toggleExpanded(): void {
|
|
|
|
|
this.isExpanded = !this.isExpanded;
|
|
|
|
|
this.checkAndAnimateAllDayHeight();
|
2025-10-02 15:57:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
let elements = document.querySelectorAll('swp-allday-container swp-event');
|
|
|
|
|
elements.forEach(element: HTMLElement => {
|
|
|
|
|
|
|
|
|
|
element.classList.toggle('max-event-overflow-hide');
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-30 00:34:27 +02:00
|
|
|
|
2025-09-30 23:00:34 +02:00
|
|
|
/**
|
|
|
|
|
* Count number of events in a specific column using ColumnBounds
|
|
|
|
|
*/
|
|
|
|
|
private countEventsInColumn(columnBounds: ColumnBounds): number {
|
2025-10-02 15:57:11 +02:00
|
|
|
let columnIndex = columnBounds.index;
|
|
|
|
|
let count = 0;
|
2025-10-01 18:41:28 +02:00
|
|
|
|
2025-10-02 15:57:11 +02:00
|
|
|
this.currentLayouts.forEach((layout) => {
|
|
|
|
|
// Check if event spans this column
|
|
|
|
|
if (layout.startColumn <= columnIndex && layout.endColumn >= columnIndex) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return count;
|
|
|
|
|
}
|
2025-09-30 23:00:34 +02:00
|
|
|
|
2025-09-30 15:24:58 +02:00
|
|
|
/**
|
|
|
|
|
* Update overflow indicators for collapsed state
|
|
|
|
|
*/
|
|
|
|
|
private updateOverflowIndicators(): void {
|
2025-10-02 15:57:11 +02:00
|
|
|
const container = this.getAllDayContainer();
|
|
|
|
|
if(!container) return;
|
|
|
|
|
|
|
|
|
|
// Create overflow indicators for each column that needs them
|
|
|
|
|
let columns = ColumnDetectionUtils.getColumns();
|
|
|
|
|
|
|
|
|
|
columns.forEach((columnBounds) => {
|
|
|
|
|
let totalEventsInColumn = this.countEventsInColumn(columnBounds);
|
|
|
|
|
let overflowCount = totalEventsInColumn - ALL_DAY_CONSTANTS.MAX_COLLAPSED_ROWS
|
|
|
|
|
|
|
|
|
|
if (overflowCount > 0) {
|
|
|
|
|
// Create new overflow indicator element
|
|
|
|
|
let overflowElement = document.createElement('swp-event');
|
|
|
|
|
overflowElement.className = 'max-event-indicator';
|
|
|
|
|
overflowElement.style.gridRow = ALL_DAY_CONSTANTS.MAX_COLLAPSED_ROWS.toString();
|
|
|
|
|
overflowElement.style.gridColumn = columnBounds.index.toString();
|
|
|
|
|
overflowElement.innerHTML = `<span>+${overflowCount + 1} more</span>`;
|
|
|
|
|
overflowElement.onclick = (e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
this.toggleExpanded();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
container.appendChild(overflowElement);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-09-30 15:24:58 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear overflow indicators and restore normal state
|
|
|
|
|
*/
|
|
|
|
|
private clearOverflowIndicators(): void {
|
2025-10-02 15:57:11 +02:00
|
|
|
const container = this.getAllDayContainer();
|
|
|
|
|
if(!container) return;
|
2025-09-30 22:35:07 +02:00
|
|
|
|
2025-10-02 15:57:11 +02:00
|
|
|
// Remove all overflow indicator elements
|
|
|
|
|
container.querySelectorAll('.max-event-indicator').forEach((element) => {
|
|
|
|
|
element.remove();
|
|
|
|
|
});
|
2025-09-30 22:35:07 +02:00
|
|
|
|
2025-10-01 18:41:28 +02:00
|
|
|
|
2025-10-02 15:57:11 +02:00
|
|
|
}
|
2025-09-30 15:24:58 +02:00
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|