improve exception saving

This commit is contained in:
Schneider Roland
2025-12-09 07:20:55 +01:00
parent 122ddae575
commit c53c00e13c
4 changed files with 144 additions and 14 deletions

View File

@@ -1,12 +1,13 @@
import { Component, inject, input } from '@angular/core';
import { CalendarEventDto } from '../../../models/events-in-range-dto.model';
import { CalendarEventDto, EventExceptionDto } from '../../../models/events-in-range-dto.model';
import {
SingleEventDashboardEventDetailsView
SingleEventDashboardEventDetailsView,
} from '../single-event-dashboard-event-details-view/single-event-dashboard-event-details-view';
import { Button } from '@rschneider/ng-daisyui';
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';
export type ACTIVATION_TYPE = 'cancel' | 'activate';
@@ -32,32 +33,49 @@ export class SingleEventDashboardEventActivation {
protected setEventOccurrenceActivation(activated: boolean) {
const eventId =this.event()?.id!;
const event = this.event();
console.info('setEventOccurrenceActivation', event);
const eventId = this.event()?.id!;
const startTime = this.event()?.startTime!;
let payload: CreateExceptionDto | undefined = undefined;
const eventException = event?.exceptions ? event.exceptions[0] : undefined;
if (eventException) {
payload = {
...eventException,
originalStartTime: new Date(eventException.originalStartTime),
newStartTime: eventException.newStartTime ? new Date(eventException.newStartTime) : undefined,
newEndTime: eventException.newEndTime ? new Date(eventException.newEndTime) :undefined,
isCancelled: !activated,
};
} else {
payload = {
originalStartTime: new Date(startTime),
isCancelled: !activated,
};
}
this.calendarService.applyException(eventId,{
originalStartTime: new Date(startTime),
isCancelled: !activated,
}).subscribe(
this.calendarService.applyException(eventId, payload ).subscribe(
{
next: () => {
this.onAction()('close');
},
error: err => {
alert("Failed to change event");
}
}
)
alert('Failed to change event');
},
},
);
}
protected cancelEventOccurrence() {
this.setEventOccurrenceActivation(false);
this.setEventOccurrenceActivation(false);
}
protected activateEventOccurrence() {
this.setEventOccurrenceActivation(true);
}
protected closeDialog() {
this.onAction()('close')
this.onAction()('close');
}
}