Initial commit: Calendar Plantempus project setup with TypeScript, ASP.NET Core, and event-driven architecture
This commit is contained in:
commit
f06c02121c
38 changed files with 8233 additions and 0 deletions
227
src/managers/EventManager.ts
Normal file
227
src/managers/EventManager.ts
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
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',
|
||||
start: '2024-01-15T09:00:00',
|
||||
end: '2024-01-15T09:30:00',
|
||||
type: 'meeting',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 1, duration: 30 }
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
title: 'Client Meeting',
|
||||
start: '2024-01-15T14:00:00',
|
||||
end: '2024-01-15T15:30:00',
|
||||
type: 'meeting',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 1, duration: 90 }
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
title: 'Lunch',
|
||||
start: '2024-01-15T12:00:00',
|
||||
end: '2024-01-15T13:00:00',
|
||||
type: 'meal',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 1, duration: 60 }
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
title: 'Deep Work Session',
|
||||
start: '2024-01-16T10:00:00',
|
||||
end: '2024-01-16T12:00:00',
|
||||
type: 'work',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 2, duration: 120 }
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
title: 'Team Standup',
|
||||
start: '2024-01-16T09:00:00',
|
||||
end: '2024-01-16T09:30:00',
|
||||
type: 'meeting',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 2, duration: 30 }
|
||||
},
|
||||
{
|
||||
id: '6',
|
||||
title: 'Lunch',
|
||||
start: '2024-01-16T12:30:00',
|
||||
end: '2024-01-16T13:30:00',
|
||||
type: 'meal',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 2, duration: 60 }
|
||||
},
|
||||
{
|
||||
id: '7',
|
||||
title: 'Project Review',
|
||||
start: '2024-01-17T15:00:00',
|
||||
end: '2024-01-17T16:00:00',
|
||||
type: 'meeting',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 3, duration: 60 }
|
||||
},
|
||||
{
|
||||
id: '8',
|
||||
title: 'Lunch',
|
||||
start: '2024-01-17T12:00:00',
|
||||
end: '2024-01-17T13:00:00',
|
||||
type: 'meal',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 3, duration: 60 }
|
||||
},
|
||||
{
|
||||
id: '9',
|
||||
title: 'Sprint Planning',
|
||||
start: '2024-01-18T10:00:00',
|
||||
end: '2024-01-18T12:00:00',
|
||||
type: 'meeting',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 4, duration: 120 }
|
||||
},
|
||||
{
|
||||
id: '10',
|
||||
title: 'Coffee Break',
|
||||
start: '2024-01-18T15:00:00',
|
||||
end: '2024-01-18T15:30:00',
|
||||
type: 'meal',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 4, duration: 30 }
|
||||
},
|
||||
{
|
||||
id: '11',
|
||||
title: 'Documentation',
|
||||
start: '2024-01-19T13:00:00',
|
||||
end: '2024-01-19T16:00:00',
|
||||
type: 'work',
|
||||
allDay: false,
|
||||
syncStatus: 'synced',
|
||||
metadata: { day: 5, duration: 180 }
|
||||
}
|
||||
];
|
||||
|
||||
console.log(`EventManager: Loaded ${this.events.length} mock events`);
|
||||
}
|
||||
|
||||
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 getEventsByDay(day: number): CalendarEvent[] {
|
||||
return this.events.filter(event => event.metadata?.day === day);
|
||||
}
|
||||
|
||||
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 = [];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue