2025-07-24 22:17:38 +02:00
|
|
|
import { EventBus } from '../core/EventBus';
|
|
|
|
|
import { IEventBus, CalendarEvent } from '../types/CalendarTypes';
|
|
|
|
|
import { EventTypes } from '../constants/EventTypes';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* EventManager - Administrerer event lifecycle og CRUD operationer
|
|
|
|
|
* Håndterer mock data og event synchronization
|
|
|
|
|
*/
|
|
|
|
|
export class EventManager {
|
|
|
|
|
private eventBus: IEventBus;
|
|
|
|
|
private events: CalendarEvent[] = [];
|
|
|
|
|
|
|
|
|
|
constructor(eventBus: IEventBus) {
|
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
|
this.setupEventListeners();
|
|
|
|
|
this.loadMockData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private setupEventListeners(): void {
|
|
|
|
|
this.eventBus.on(EventTypes.CALENDAR_INITIALIZED, () => {
|
|
|
|
|
this.syncEvents();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.eventBus.on(EventTypes.DATE_CHANGED, () => {
|
|
|
|
|
this.syncEvents();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.eventBus.on(EventTypes.VIEW_RENDERED, () => {
|
|
|
|
|
this.syncEvents();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private loadMockData(): void {
|
|
|
|
|
// Mock events baseret på POC data med korrekt CalendarEvent struktur
|
|
|
|
|
this.events = [
|
|
|
|
|
{
|
|
|
|
|
id: '1',
|
|
|
|
|
title: 'Team Standup',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-28T09:00:00',
|
|
|
|
|
end: '2025-07-28T09:30:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 30 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '2',
|
|
|
|
|
title: 'Client Meeting',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-28T14:00:00',
|
|
|
|
|
end: '2025-07-28T15:30:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 90 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '3',
|
|
|
|
|
title: 'Lunch',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-28T12:00:00',
|
|
|
|
|
end: '2025-07-28T13:00:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meal',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 60 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '4',
|
|
|
|
|
title: 'Deep Work Session',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-29T10:00:00',
|
|
|
|
|
end: '2025-07-29T12:00:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'work',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 120 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '5',
|
|
|
|
|
title: 'Team Standup',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-29T09:00:00',
|
|
|
|
|
end: '2025-07-29T09:30:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 30 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '6',
|
|
|
|
|
title: 'Lunch',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-29T12:30:00',
|
|
|
|
|
end: '2025-07-29T13:30:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meal',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 60 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '7',
|
|
|
|
|
title: 'Project Review',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-30T15:00:00',
|
|
|
|
|
end: '2025-07-30T16:00:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 60 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '8',
|
|
|
|
|
title: 'Lunch',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-30T12:00:00',
|
|
|
|
|
end: '2025-07-30T13:00:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meal',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 60 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '9',
|
|
|
|
|
title: 'Sprint Planning',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-31T10:00:00',
|
|
|
|
|
end: '2025-07-31T12:00:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 120 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '10',
|
|
|
|
|
title: 'Coffee Break',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-07-31T15:00:00',
|
|
|
|
|
end: '2025-07-31T15:30:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meal',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 30 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '11',
|
|
|
|
|
title: 'Documentation',
|
2025-08-02 00:28:45 +02:00
|
|
|
start: '2025-08-01T13:00:00',
|
|
|
|
|
end: '2025-08-01T16:00:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'work',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-07-26 00:00:03 +02:00
|
|
|
metadata: { duration: 180 }
|
2025-08-02 00:28:45 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '12',
|
|
|
|
|
title: 'Early Morning Workout',
|
|
|
|
|
start: '2025-07-29T06:00:00',
|
|
|
|
|
end: '2025-07-29T07:00:00',
|
|
|
|
|
type: 'work',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
|
|
|
|
metadata: { duration: 60 }
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '13',
|
|
|
|
|
title: 'Late Evening Call',
|
|
|
|
|
start: '2025-07-30T21:00:00',
|
|
|
|
|
end: '2025-07-30T22:00:00',
|
|
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
|
|
|
|
metadata: { duration: 60 }
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '14',
|
|
|
|
|
title: 'Midnight Release',
|
|
|
|
|
start: '2025-07-31T23:00:00',
|
|
|
|
|
end: '2025-08-01T01:00:00',
|
|
|
|
|
type: 'work',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
|
|
|
|
metadata: { duration: 120 }
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
console.log(`EventManager: Loaded ${this.events.length} mock events`);
|
2025-08-02 00:28:45 +02:00
|
|
|
console.log('EventManager: First event:', this.events[0]);
|
|
|
|
|
console.log('EventManager: Last event:', this.events[this.events.length - 1]);
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private syncEvents(): void {
|
|
|
|
|
// Emit events for rendering
|
|
|
|
|
this.eventBus.emit(EventTypes.EVENTS_LOADED, {
|
|
|
|
|
events: this.events
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log(`EventManager: Synced ${this.events.length} events`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getEvents(): CalendarEvent[] {
|
|
|
|
|
return [...this.events];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public getEventById(id: string): CalendarEvent | undefined {
|
|
|
|
|
return this.events.find(event => event.id === id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public addEvent(event: Omit<CalendarEvent, 'id'>): CalendarEvent {
|
|
|
|
|
const newEvent: CalendarEvent = {
|
|
|
|
|
...event,
|
|
|
|
|
id: Date.now().toString()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.events.push(newEvent);
|
|
|
|
|
this.syncEvents();
|
|
|
|
|
|
|
|
|
|
this.eventBus.emit(EventTypes.EVENT_CREATED, {
|
|
|
|
|
event: newEvent
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return newEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public updateEvent(id: string, updates: Partial<CalendarEvent>): CalendarEvent | null {
|
|
|
|
|
const eventIndex = this.events.findIndex(event => event.id === id);
|
|
|
|
|
if (eventIndex === -1) return null;
|
|
|
|
|
|
|
|
|
|
const updatedEvent = { ...this.events[eventIndex], ...updates };
|
|
|
|
|
this.events[eventIndex] = updatedEvent;
|
|
|
|
|
|
|
|
|
|
this.syncEvents();
|
|
|
|
|
|
|
|
|
|
this.eventBus.emit(EventTypes.EVENT_UPDATED, {
|
|
|
|
|
event: updatedEvent
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return updatedEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public deleteEvent(id: string): boolean {
|
|
|
|
|
const eventIndex = this.events.findIndex(event => event.id === id);
|
|
|
|
|
if (eventIndex === -1) return false;
|
|
|
|
|
|
|
|
|
|
const deletedEvent = this.events[eventIndex];
|
|
|
|
|
this.events.splice(eventIndex, 1);
|
|
|
|
|
|
|
|
|
|
this.syncEvents();
|
|
|
|
|
|
|
|
|
|
this.eventBus.emit(EventTypes.EVENT_DELETED, {
|
|
|
|
|
event: deletedEvent
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public refresh(): void {
|
|
|
|
|
this.syncEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public destroy(): void {
|
|
|
|
|
this.events = [];
|
|
|
|
|
}
|
|
|
|
|
}
|