Major refactor into type safe TS
With a risk oof rolling it all back
This commit is contained in:
parent
c08fa02c29
commit
48d1fd681c
19 changed files with 449 additions and 81 deletions
|
|
@ -10,6 +10,7 @@ import {
|
|||
DragMoveEventPayload,
|
||||
DragEndEventPayload
|
||||
} from '../types/EventTypes';
|
||||
import { DragOffset, MousePosition } from '../types/DragDropTypes';
|
||||
|
||||
/**
|
||||
* AllDayManager - Handles all-day row height animations and management
|
||||
|
|
@ -102,7 +103,7 @@ export class AllDayManager {
|
|||
|
||||
|
||||
console.log('🎯 AllDayManager: Ending drag for all-day event', { eventId });
|
||||
this.handleDragEnd(draggedElement, dragClone as HTMLElement, finalPosition.column);
|
||||
this.handleDragEnd(draggedElement, dragClone as HTMLElement, { column: finalPosition.column || '', y: 0 });
|
||||
});
|
||||
|
||||
// Listen for drag cancellation to recalculate height
|
||||
|
|
@ -374,7 +375,7 @@ export class AllDayManager {
|
|||
/**
|
||||
* Handle drag start for all-day events
|
||||
*/
|
||||
private handleDragStart(originalElement: HTMLElement, eventId: string, mouseOffset: any): void {
|
||||
private handleDragStart(originalElement: HTMLElement, eventId: string, mouseOffset: DragOffset): void {
|
||||
// Create clone
|
||||
const clone = originalElement.cloneNode(true) as HTMLElement;
|
||||
clone.dataset.eventId = `clone-${eventId}`;
|
||||
|
|
@ -409,7 +410,7 @@ export class AllDayManager {
|
|||
/**
|
||||
* Handle drag move for all-day events
|
||||
*/
|
||||
private handleDragMove(dragClone: HTMLElement, mousePosition: any): void {
|
||||
private handleDragMove(dragClone: HTMLElement, mousePosition: MousePosition): void {
|
||||
// Calculate grid column based on mouse position
|
||||
const dayHeaders = document.querySelectorAll('swp-day-header');
|
||||
let targetColumn = 1;
|
||||
|
|
@ -434,7 +435,7 @@ export class AllDayManager {
|
|||
/**
|
||||
* Handle drag end for all-day events
|
||||
*/
|
||||
private handleDragEnd(originalElement: HTMLElement, dragClone: HTMLElement, finalPosition: any): void {
|
||||
private handleDragEnd(originalElement: HTMLElement, dragClone: HTMLElement, finalPosition: { column: string; y: number }): void {
|
||||
|
||||
// Normalize clone
|
||||
const cloneId = dragClone.dataset.eventId;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
import { EventBus } from '../core/EventBus.js';
|
||||
import { CoreEvents } from '../constants/CoreEvents.js';
|
||||
import { calendarConfig } from '../core/CalendarConfig.js';
|
||||
import { CalendarEvent, CalendarView, IEventBus } from '../types/CalendarTypes.js';
|
||||
import { EventManager } from './EventManager.js';
|
||||
import { GridManager } from './GridManager.js';
|
||||
import { HeaderManager } from './HeaderManager.js';
|
||||
import { EventRenderingService } from '../renderers/EventRendererManager.js';
|
||||
import { ScrollManager } from './ScrollManager.js';
|
||||
import { DateCalculator } from '../utils/DateCalculator.js';
|
||||
import { EventFilterManager } from './EventFilterManager.js';
|
||||
import { EventBus } from '../core/EventBus';
|
||||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
import { calendarConfig } from '../core/CalendarConfig';
|
||||
import { CalendarEvent, CalendarView, IEventBus } from '../types/CalendarTypes';
|
||||
import { EventManager } from './EventManager';
|
||||
import { GridManager } from './GridManager';
|
||||
import { HeaderManager } from './HeaderManager';
|
||||
import { EventRenderingService } from '../renderers/EventRendererManager';
|
||||
import { ScrollManager } from './ScrollManager';
|
||||
import { DateCalculator } from '../utils/DateCalculator';
|
||||
import { EventFilterManager } from './EventFilterManager';
|
||||
import { InitializationReport } from '../types/ManagerTypes';
|
||||
|
||||
/**
|
||||
* CalendarManager - Main coordinator for all calendar managers
|
||||
|
|
@ -65,7 +66,7 @@ export class CalendarManager {
|
|||
// Step 2: Pass data to GridManager and render grid structure
|
||||
if (calendarType === 'resource') {
|
||||
const resourceData = this.eventManager.getResourceData();
|
||||
this.gridManager.setResourceData(resourceData);
|
||||
this.gridManager.setResourceData(this.eventManager.getRawData() as import('../types/CalendarTypes').ResourceCalendarData);
|
||||
}
|
||||
await this.gridManager.render();
|
||||
|
||||
|
|
@ -211,12 +212,17 @@ export class CalendarManager {
|
|||
/**
|
||||
* Get initialization report for debugging
|
||||
*/
|
||||
public getInitializationReport(): any {
|
||||
public getInitializationReport(): InitializationReport {
|
||||
return {
|
||||
isInitialized: this.isInitialized,
|
||||
currentView: this.currentView,
|
||||
currentDate: this.currentDate,
|
||||
initializationTime: 'N/A - simple initialization'
|
||||
initialized: this.isInitialized,
|
||||
timestamp: Date.now(),
|
||||
managers: {
|
||||
calendar: { initialized: this.isInitialized },
|
||||
event: { initialized: true },
|
||||
grid: { initialized: true },
|
||||
header: { initialized: true },
|
||||
scroll: { initialized: true }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,19 @@ import { CalendarEvent } from '../types/CalendarTypes';
|
|||
// Import Fuse.js from npm
|
||||
import Fuse from 'fuse.js';
|
||||
|
||||
interface FuseResult {
|
||||
item: CalendarEvent;
|
||||
refIndex: number;
|
||||
score?: number;
|
||||
}
|
||||
|
||||
export class EventFilterManager {
|
||||
private searchInput: HTMLInputElement | null = null;
|
||||
private allEvents: CalendarEvent[] = [];
|
||||
private matchingEventIds: Set<string> = new Set();
|
||||
private isFilterActive: boolean = false;
|
||||
private frameRequest: number | null = null;
|
||||
private fuse: any = null;
|
||||
private fuse: Fuse<CalendarEvent> | null = null;
|
||||
|
||||
constructor() {
|
||||
// Wait for DOM to be ready before initializing
|
||||
|
|
@ -119,7 +125,7 @@ export class EventFilterManager {
|
|||
|
||||
// Extract matching event IDs
|
||||
this.matchingEventIds.clear();
|
||||
results.forEach((result: any) => {
|
||||
results.forEach((result: FuseResult) => {
|
||||
if (result.item && result.item.id) {
|
||||
this.matchingEventIds.add(result.item.id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,17 @@ import { IEventBus, CalendarEvent, ResourceCalendarData } from '../types/Calenda
|
|||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
import { calendarConfig } from '../core/CalendarConfig';
|
||||
import { DateCalculator } from '../utils/DateCalculator';
|
||||
import { ResourceData } from '../types/ManagerTypes';
|
||||
|
||||
interface RawEventData {
|
||||
id: string;
|
||||
title: string;
|
||||
start: string | Date;
|
||||
end: string | Date;
|
||||
color?: string;
|
||||
allDay?: boolean;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* EventManager - Optimized event lifecycle and CRUD operations
|
||||
|
|
@ -11,7 +22,7 @@ import { DateCalculator } from '../utils/DateCalculator';
|
|||
export class EventManager {
|
||||
private eventBus: IEventBus;
|
||||
private events: CalendarEvent[] = [];
|
||||
private rawData: any = null;
|
||||
private rawData: ResourceCalendarData | RawEventData[] | null = null;
|
||||
private eventCache = new Map<string, CalendarEvent[]>(); // Cache for period queries
|
||||
private lastCacheKey: string = '';
|
||||
|
||||
|
|
@ -57,7 +68,7 @@ export class EventManager {
|
|||
/**
|
||||
* Optimized data processing with better type safety
|
||||
*/
|
||||
private processCalendarData(calendarType: string, data: any): CalendarEvent[] {
|
||||
private processCalendarData(calendarType: string, data: ResourceCalendarData | RawEventData[]): CalendarEvent[] {
|
||||
if (calendarType === 'resource') {
|
||||
const resourceData = data as ResourceCalendarData;
|
||||
return resourceData.resources.flatMap(resource =>
|
||||
|
|
@ -72,10 +83,14 @@ export class EventManager {
|
|||
);
|
||||
}
|
||||
|
||||
return data.map((event: any) => ({
|
||||
const eventData = data as RawEventData[];
|
||||
return eventData.map((event): CalendarEvent => ({
|
||||
...event,
|
||||
start: new Date(event.start),
|
||||
end: new Date(event.end)
|
||||
end: new Date(event.end),
|
||||
type: 'event',
|
||||
allDay: event.allDay || false,
|
||||
syncStatus: 'synced' as const
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +112,24 @@ export class EventManager {
|
|||
/**
|
||||
* Get raw resource data for resource calendar mode
|
||||
*/
|
||||
public getResourceData(): any {
|
||||
public getResourceData(): ResourceData | null {
|
||||
if (!this.rawData || !('resources' in this.rawData)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
resources: this.rawData.resources.map(r => ({
|
||||
id: r.employeeId || r.name, // Use employeeId as id, fallback to name
|
||||
name: r.name,
|
||||
type: r.employeeId ? 'employee' : 'resource',
|
||||
color: 'blue' // Default color since Resource interface doesn't have color
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw data for compatibility
|
||||
*/
|
||||
public getRawData(): ResourceCalendarData | RawEventData[] | null {
|
||||
return this.rawData;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ export class GridManager {
|
|||
/**
|
||||
* Get layout config for current view
|
||||
*/
|
||||
private getLayoutConfig(): any {
|
||||
private getLayoutConfig(): { columnCount: number; type: string } {
|
||||
switch (this.currentView) {
|
||||
case 'week':
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { IEventBus } from '../types/CalendarTypes.js';
|
||||
import { EventRenderingService } from '../renderers/EventRendererManager.js';
|
||||
import { DateCalculator } from '../utils/DateCalculator.js';
|
||||
import { CoreEvents } from '../constants/CoreEvents.js';
|
||||
import { NavigationRenderer } from '../renderers/NavigationRenderer.js';
|
||||
import { calendarConfig } from '../core/CalendarConfig.js';
|
||||
import { IEventBus } from '../types/CalendarTypes';
|
||||
import { EventRenderingService } from '../renderers/EventRendererManager';
|
||||
import { DateCalculator } from '../utils/DateCalculator';
|
||||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
import { NavigationRenderer } from '../renderers/NavigationRenderer';
|
||||
import { calendarConfig } from '../core/CalendarConfig';
|
||||
|
||||
/**
|
||||
* NavigationManager handles calendar navigation (prev/next/today buttons)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue