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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue