improve exception saving

This commit is contained in:
Schneider Roland
2025-12-11 07:01:17 +01:00
parent fb31f0813a
commit 93b1fb9610
5 changed files with 30 additions and 11 deletions

View File

@@ -57,7 +57,7 @@ export class SingleEventDashboardEventActivation {
this.calendarService.applyException(eventId, payload ).subscribe( this.calendarService.applyException(eventId, payload ).subscribe(
{ {
next: () => { next: () => {
this.onAction()('close'); this.onAction()('save-event-success');
}, },
error: err => { error: err => {
alert('Failed to change event'); alert('Failed to change event');

View File

@@ -7,7 +7,7 @@
} }
<div class="flex gap-2 mt-3"> <div class="flex gap-2 mt-3">
<rs-daisy-button variant="error"> <rs-daisy-button variant="error" (click)="doDelete()">
<span [outerHTML]="SvgIcons.heroTrash | safeHtml"></span> <span [outerHTML]="SvgIcons.heroTrash | safeHtml"></span>
Törlés Törlés
</rs-daisy-button> </rs-daisy-button>

View File

@@ -1,9 +1,10 @@
import { Component, effect, input, output } from '@angular/core'; import { Component, effect, inject, input, output } from '@angular/core';
import { CalendarEventDto } from '../../../models/events-in-range-dto.model'; import { CalendarEventDto } from '../../../models/events-in-range-dto.model';
import { DetailView, DetailViewConfig } from '../../../../../components/detail-view/detail-view'; import { DetailView, DetailViewConfig } from '../../../../../components/detail-view/detail-view';
import { SvgIcons } from '../../../../../svg-icons'; import { SvgIcons } from '../../../../../svg-icons';
import { SafeHtmlPipe } from '../../../../../pipes/safe-html-pipe'; import { SafeHtmlPipe } from '../../../../../pipes/safe-html-pipe';
import { Button } from '@rschneider/ng-daisyui'; import { Button } from '@rschneider/ng-daisyui';
import { CalendarService } from '../../../services/calendar.service';
@Component({ @Component({
selector: 'app-single-event-dashboard-event-delete', selector: 'app-single-event-dashboard-event-delete',
@@ -18,6 +19,7 @@ import { Button } from '@rschneider/ng-daisyui';
}) })
export class SingleEventDashboardEventDelete { export class SingleEventDashboardEventDelete {
calendarService = inject(CalendarService);
event = input<CalendarEventDto>(); event = input<CalendarEventDto>();
// Define an input that expects a function // Define an input that expects a function
onAction = input.required<(msg: string) => void>(); onAction = input.required<(msg: string) => void>();
@@ -59,6 +61,16 @@ export class SingleEventDashboardEventDelete {
this.onAction()('close'); this.onAction()('close');
} }
doDelete() {
this.calendarService.deleteEvent(this.event()!.id).subscribe(
{
next: ( ) => {
this.onAction()('save-event-success');
}
}
)
// Call the function passed from the parent
}
protected readonly SvgIcons = SvgIcons; protected readonly SvgIcons = SvgIcons;
} }

View File

@@ -25,6 +25,7 @@ export class SingleEventDashboardEventEdit {
* proxy to ready event from form to parent * proxy to ready event from form to parent
*/ */
protected triggerAction(action: string) { protected triggerAction(action: string) {
console.info("event details dashboard", action)
this.onAction()(action) this.onAction()(action)
} }
} }

View File

@@ -9,17 +9,18 @@ import { CreateExceptionDto } from '../models/event-exception.model';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class CalendarService { export class CalendarService {
private readonly apiUrl: string; private readonly apiUrl: string;
constructor( constructor(
private http: HttpClient, private http: HttpClient,
private configService: ConfigurationService private configService: ConfigurationService,
) { ) {
this.apiUrl = `${this.configService.getApiUrl()}/calendar`; this.apiUrl = `${this.configService.getApiUrl()}/calendar`;
} }
/** /**
* get events in range * get events in range
*/ */
@@ -27,21 +28,26 @@ export class CalendarService {
const params = new HttpParams() const params = new HttpParams()
.set('startDate', eventsInRangeDto.startTime!.toISOString()) .set('startDate', eventsInRangeDto.startTime!.toISOString())
.set('endDate', eventsInRangeDto.endTime!.toISOString()); .set('endDate', eventsInRangeDto.endTime!.toISOString());
return this.http.get<CalendarEventDto[]>(this.apiUrl+'', { params }); return this.http.get<CalendarEventDto[]>(this.apiUrl + '', { params });
} }
/** /**
* Create a new record. * Create a new record.
*/ */
public create(data: EventFormDTO): Observable<Event> { public create(data: EventFormDTO): Observable<Event> {
return this.http.post<Event>(this.apiUrl+'/events', data); return this.http.post<Event>(this.apiUrl + '/events', data);
} }
public update(id: number,data: UpdateEventFormDTO): Observable<Event> { public update(id: number, data: UpdateEventFormDTO): Observable<Event> {
return this.http.patch<Event>(this.apiUrl+'/events/'+id, data); return this.http.patch<Event>(this.apiUrl + '/events/' + id, data);
} }
public applyException(eventId: number, eventException: CreateExceptionDto){ public applyException(eventId: number, eventException: CreateExceptionDto) {
return this.http.post(this.apiUrl+`/events/${eventId}/exceptions`, eventException); return this.http.post(this.apiUrl + `/events/${eventId}/exceptions`, eventException);
} }
public deleteEvent(id: number): Observable<void> {
return this.http.delete<void>(this.apiUrl + '/events/' + id);
}
} }