refactor admin to use eventbus

This commit is contained in:
Roland Schneider
2025-12-11 22:47:54 +01:00
parent 93b1fb9610
commit 453d02612c
27 changed files with 298 additions and 225 deletions

View File

@@ -1,5 +1,5 @@
import { Component, inject, input } from '@angular/core';
import { CalendarEventDto, EventExceptionDto } from '../../../models/events-in-range-dto.model';
import { CalendarEventDto } from '../../../models/events-in-range-dto.model';
import {
SingleEventDashboardEventDetailsView,
} from '../single-event-dashboard-event-details-view/single-event-dashboard-event-details-view';
@@ -8,6 +8,8 @@ import { SvgIcons } from '../../../../../svg-icons';
import { SafeHtmlPipe } from '../../../../../pipes/safe-html-pipe';
import { CalendarService } from '../../../services/calendar.service';
import { CreateExceptionDto } from '../../../models/event-exception.model';
import { EventBusService } from '../../../../../services/event-bus.service';
import { EventType } from '../../../../../../types';
export type ACTIVATION_TYPE = 'cancel' | 'activate';
@@ -23,11 +25,10 @@ export type ACTIVATION_TYPE = 'cancel' | 'activate';
})
export class SingleEventDashboardEventActivation {
eventBus = inject(EventBusService);
mode = input<ACTIVATION_TYPE>('cancel');
calendarService = inject(CalendarService);
event = input<CalendarEventDto>();
onAction = input.required<(msg: string) => void>();
protected readonly SvgIcons = SvgIcons;
@@ -37,7 +38,7 @@ export class SingleEventDashboardEventActivation {
console.info('setEventOccurrenceActivation', event);
const eventId = this.event()?.id!;
const startTime = this.event()?.startTime!;
let payload: CreateExceptionDto | undefined = undefined;
let payload: CreateExceptionDto | undefined;
const eventException = event?.exceptions?.length ? event.exceptions[0] : undefined;
if (eventException) {
payload = {
@@ -57,9 +58,10 @@ export class SingleEventDashboardEventActivation {
this.calendarService.applyException(eventId, payload ).subscribe(
{
next: () => {
this.onAction()('save-event-success');
this.eventBus.emit(EventType.CALENDAR_VIEW_EVENT_SAVED, 'Event saved')
},
error: err => {
console.error(err);
alert('Failed to change event');
},
},
@@ -75,7 +77,7 @@ export class SingleEventDashboardEventActivation {
}
protected closeDialog() {
this.onAction()('close');
this.eventBus.emit(EventType.CALENDAR_VIEW_DIALOG_CLOSED, 'Event saved')
}
}