Remove resource calendar mode support
Simplifies calendar configuration and removes resource-specific code paths Eliminates complexity around resource-based calendar rendering by: - Removing ResourceCalendarData type - Removing resource-specific renderers and managers - Streamlining event and grid management logic - Consolidating to single date-based calendar implementation
This commit is contained in:
parent
349e1e8293
commit
cda201301c
16 changed files with 65 additions and 323 deletions
|
|
@ -1,8 +1,7 @@
|
|||
import { IEventBus, CalendarEvent, ResourceCalendarData } from '../types/CalendarTypes';
|
||||
import { IEventBus, CalendarEvent } from '../types/CalendarTypes';
|
||||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
import { CalendarConfig } from '../core/CalendarConfig';
|
||||
import { DateService } from '../utils/DateService';
|
||||
import { ResourceData } from '../types/ManagerTypes';
|
||||
|
||||
interface RawEventData {
|
||||
id: string;
|
||||
|
|
@ -22,7 +21,7 @@ interface RawEventData {
|
|||
export class EventManager {
|
||||
|
||||
private events: CalendarEvent[] = [];
|
||||
private rawData: ResourceCalendarData | RawEventData[] | null = null;
|
||||
private rawData: RawEventData[] | null = null;
|
||||
private eventCache = new Map<string, CalendarEvent[]>(); // Cache for period queries
|
||||
private lastCacheKey: string = '';
|
||||
private dateService: DateService;
|
||||
|
|
@ -52,46 +51,28 @@ export class EventManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Optimized mock data loading with better resource handling
|
||||
* Optimized mock data loading
|
||||
*/
|
||||
private async loadMockData(): Promise<void> {
|
||||
const calendarType = this.config.getCalendarMode();
|
||||
const jsonFile = calendarType === 'resource'
|
||||
? '/data/mock-resource-events.json'
|
||||
: '/data/mock-events.json';
|
||||
|
||||
const jsonFile = 'data/mock-events.json';
|
||||
|
||||
const response = await fetch(jsonFile);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load mock events: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
|
||||
// Store raw data and process in one operation
|
||||
this.rawData = data;
|
||||
this.events = this.processCalendarData(calendarType, data);
|
||||
this.events = this.processCalendarData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimized data processing with better type safety
|
||||
*/
|
||||
private processCalendarData(calendarType: string, data: ResourceCalendarData | RawEventData[]): CalendarEvent[] {
|
||||
if (calendarType === 'resource') {
|
||||
const resourceData = data as ResourceCalendarData;
|
||||
return resourceData.resources.flatMap(resource =>
|
||||
resource.events.map(event => ({
|
||||
...event,
|
||||
start: new Date(event.start),
|
||||
end: new Date(event.end),
|
||||
resourceName: resource.name,
|
||||
resourceDisplayName: resource.displayName,
|
||||
resourceEmployeeId: resource.employeeId
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
const eventData = data as RawEventData[];
|
||||
return eventData.map((event): CalendarEvent => ({
|
||||
private processCalendarData(data: RawEventData[]): CalendarEvent[] {
|
||||
return data.map((event): CalendarEvent => ({
|
||||
...event,
|
||||
start: new Date(event.start),
|
||||
end: new Date(event.end),
|
||||
|
|
@ -116,30 +97,6 @@ export class EventManager {
|
|||
return copy ? [...this.events] : this.events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw resource data for resource calendar mode
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimized event lookup with early return
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue