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 {
|
2025-08-02 23:59:52 +02:00
|
|
|
// Mock events for current week (July 27 - August 2, 2025)
|
2025-07-24 22:17:38 +02:00
|
|
|
this.events = [
|
2025-08-02 23:59:52 +02:00
|
|
|
// Sunday July 27, 2025
|
2025-07-24 22:17:38 +02:00
|
|
|
{
|
|
|
|
|
id: '1',
|
2025-08-02 23:59:52 +02:00
|
|
|
title: 'Weekend Planning',
|
|
|
|
|
start: '2025-07-27T10:00:00',
|
|
|
|
|
end: '2025-07-27T11:00:00',
|
|
|
|
|
type: 'work',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
|
|
|
|
metadata: { duration: 60 }
|
|
|
|
|
},
|
|
|
|
|
// Monday July 28, 2025
|
|
|
|
|
{
|
|
|
|
|
id: '2',
|
2025-07-24 22:17:38 +02:00
|
|
|
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
|
|
|
},
|
|
|
|
|
{
|
2025-08-02 23:59:52 +02:00
|
|
|
id: '3',
|
|
|
|
|
title: 'Project Kickoff',
|
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
|
|
|
},
|
2025-08-02 23:59:52 +02:00
|
|
|
// Tuesday July 29, 2025
|
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',
|
2025-08-02 23:59:52 +02:00
|
|
|
title: 'Lunch Meeting',
|
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
|
|
|
},
|
2025-08-02 23:59:52 +02:00
|
|
|
// Wednesday July 30, 2025
|
2025-07-24 22:17:38 +02:00
|
|
|
{
|
2025-08-02 23:59:52 +02:00
|
|
|
id: '6',
|
|
|
|
|
title: 'Client 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
|
|
|
},
|
2025-08-02 23:59:52 +02:00
|
|
|
// Thursday July 31, 2025
|
2025-07-24 22:17:38 +02:00
|
|
|
{
|
2025-08-02 23:59:52 +02:00
|
|
|
id: '7',
|
2025-07-24 22:17:38 +02:00
|
|
|
title: 'Sprint Planning',
|
2025-08-02 23:59:52 +02:00
|
|
|
start: '2025-07-31T09:00:00',
|
|
|
|
|
end: '2025-07-31T10:30:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-08-02 23:59:52 +02:00
|
|
|
metadata: { duration: 90 }
|
2025-07-24 22:17:38 +02:00
|
|
|
},
|
|
|
|
|
{
|
2025-08-02 23:59:52 +02:00
|
|
|
id: '8',
|
|
|
|
|
title: 'Code Review',
|
|
|
|
|
start: '2025-07-31T14:00:00',
|
|
|
|
|
end: '2025-07-31T15:00:00',
|
2025-07-24 22:17:38 +02:00
|
|
|
type: 'work',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-08-02 23:59:52 +02:00
|
|
|
metadata: { duration: 60 }
|
2025-08-02 00:28:45 +02:00
|
|
|
},
|
2025-08-02 23:59:52 +02:00
|
|
|
// Friday August 1, 2025
|
2025-08-02 00:28:45 +02:00
|
|
|
{
|
2025-08-02 23:59:52 +02:00
|
|
|
id: '9',
|
|
|
|
|
title: 'Team Standup',
|
|
|
|
|
start: '2025-08-01T09:00:00',
|
|
|
|
|
end: '2025-08-01T09:30:00',
|
|
|
|
|
type: 'meeting',
|
2025-08-02 00:28:45 +02:00
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-08-02 23:59:52 +02:00
|
|
|
metadata: { duration: 30 }
|
2025-08-02 00:28:45 +02:00
|
|
|
},
|
|
|
|
|
{
|
2025-08-02 23:59:52 +02:00
|
|
|
id: '10',
|
|
|
|
|
title: 'Client Meeting',
|
|
|
|
|
start: '2025-08-01T14:00:00',
|
|
|
|
|
end: '2025-08-01T15:30:00',
|
2025-08-02 00:28:45 +02:00
|
|
|
type: 'meeting',
|
|
|
|
|
allDay: false,
|
|
|
|
|
syncStatus: 'synced',
|
2025-08-02 23:59:52 +02:00
|
|
|
metadata: { duration: 90 }
|
2025-08-02 00:28:45 +02:00
|
|
|
},
|
2025-08-02 23:59:52 +02:00
|
|
|
// Saturday August 2, 2025
|
2025-08-02 00:28:45 +02:00
|
|
|
{
|
2025-08-02 23:59:52 +02:00
|
|
|
id: '11',
|
|
|
|
|
title: 'Weekend Project',
|
|
|
|
|
start: '2025-08-02T10:00:00',
|
|
|
|
|
end: '2025-08-02T12:00:00',
|
2025-08-02 00:28:45 +02: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 = [];
|
|
|
|
|
}
|
|
|
|
|
}
|