From c542575046406825c15baf9a8fd8592142784644 Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Thu, 19 Feb 2026 17:19:03 +0100 Subject: [PATCH] Wording und API --- .../cylinder-archive.component.ts | 2 +- .../handover-dialog.component.ts | 25 +++++----- .../ag-key-actions.component.ts | 20 ++------ client/src/app/shared/api.service.ts | 48 +++++++++++++++---- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/client/src/app/modules/cylinder/components/cylinder-archive/cylinder-archive.component.ts b/client/src/app/modules/cylinder/components/cylinder-archive/cylinder-archive.component.ts index c95b2cb..16fc643 100644 --- a/client/src/app/modules/cylinder/components/cylinder-archive/cylinder-archive.component.ts +++ b/client/src/app/modules/cylinder/components/cylinder-archive/cylinder-archive.component.ts @@ -59,7 +59,7 @@ export class CylinderArchiveComponent extends AgGridContainerComponent { async restoreCylinder(data: ICylinder) { this.gridApi.setGridOption("loading", true); - await this.api.restoreCylinder(data.id); + await this.api.restoreCylinder(data); this.loadCylinders(); } diff --git a/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts b/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts index 0ea794b..4ce5416 100644 --- a/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts +++ b/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts @@ -10,7 +10,7 @@ import { MAT_DATE_LOCALE, provideNativeDateAdapter } from '@angular/material/cor import { MatButtonModule } from '@angular/material/button'; import { AsyncPipe, DatePipe } from '@angular/common'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; -import { map, Observable, startWith, timestamp } from 'rxjs'; +import { from, map, Observable, startWith, timestamp } from 'rxjs'; import { MatBottomSheet, MatBottomSheetModule, @@ -99,7 +99,7 @@ export class HandoverDialogComponent { this.isLoading = true; const promises: Observable[] = [ this.getHandovers(), - this.loadCustomers() + from(this.loadCustomers()) ]; Promise.all(promises).then(() => { @@ -125,20 +125,17 @@ export class HandoverDialogComponent { } loadCustomers() { - const promise = this.api.getCustomers() - - promise.subscribe({ - next: customers => { - this.customers = customers; - this.filteredCustomers = this.handoverForm.controls.customer.valueChanges.pipe( + + + return new Promise(async resolve => { + const customers = await this.api.getCustomers(); + this.customers = customers; + this.filteredCustomers = this.handoverForm.controls.customer.valueChanges.pipe( startWith(''), map(value => this._filter(value || '')), - ); - } - }); - - return promise; - + ); + resolve(customers) + }); } private _filter(value: string): any[] { diff --git a/client/src/app/shared/ag-grid/components/ag-key-actions/ag-key-actions.component.ts b/client/src/app/shared/ag-grid/components/ag-key-actions/ag-key-actions.component.ts index 585e9ab..728f6ff 100644 --- a/client/src/app/shared/ag-grid/components/ag-key-actions/ag-key-actions.component.ts +++ b/client/src/app/shared/ag-grid/components/ag-key-actions/ag-key-actions.component.ts @@ -5,7 +5,6 @@ import { IKey } from '../../../../model/interface/key.interface'; import { ApiService } from '../../../api.service'; import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { DeleteKeyComponent } from '../../../../modules/keys/components/delete-key/delete-key.component'; -import { HotToastService } from '@ngxpert/hot-toast'; import { HandoverDialogComponent } from '../../../../modules/keys/components/handover-dialog/handover-dialog.component'; import { MatTooltipModule } from '@angular/material/tooltip'; import { LostKeyComponent } from '../../../../modules/keys/components/lost-key/lost-key.component'; @@ -23,7 +22,6 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp { private api: ApiService = inject(ApiService); private dialog: MatDialog = inject(MatDialog); - private toast = inject(HotToastService); agInit(params: ICellRendererParams): void { this.params = params; @@ -69,22 +67,10 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp { // ref.componentInstance.editKey(this.key) } - deleteThisKey() { + async deleteThisKey() { this.params.api.setGridOption("loading", true); - this.api.deleteKey(this.key.id).pipe( - this.toast.observe({ - loading: 'Lösche Schlüssel ' + this.key.name, - success: 'Schlüssel ' + this.key.name + ' gelöscht', - error: 'Konnte nicht gelöscht werden' - }) - ).subscribe({ - next: () => { - this.api.refreshKeys(); - }, - error: () => { - this.params.api.setGridOption("loading", false); - } - }) + await this.api.deleteKey(this.key); + this.params.api.setGridOption("loading", false); } diff --git a/client/src/app/shared/api.service.ts b/client/src/app/shared/api.service.ts index 70cefe6..bdaa8e7 100644 --- a/client/src/app/shared/api.service.ts +++ b/client/src/app/shared/api.service.ts @@ -101,12 +101,42 @@ export class ApiService { return this.http.post('api/customer', data); } - getCustomers(): Observable { - return this.http.get('api/customer') + getCustomers(): Promise { + return new Promise(resolve => { + this.http.get('api/customer').subscribe({ + next: (customers) => resolve(customers), + error: (err) => { + this.toast.error('Fehler beim Laden der Kunden'); + resolve([]); + } + + }) + }) } - deleteKey(id: string) { - return this.http.delete(`api/key/${id}`); + /** + * Löscht einen Schlüssel und gibt Meldungen aus. + * Aktualisiert die Schlüssel danach + * @param key zu löschen + * @returns true wenn gelöscht, false wenn nicht + */ + deleteKey(key: IKey): Promise { + return new Promise(resolve => { + this.http.delete(`api/key/${key.id}`).pipe( + this.toast.observe({ + loading: `Lösche Schlüssel ${key.name}...`, + success: `Schlüssel ${key.name} wurde gelöscht.`, + error: 'Es ist ein Fehler aufgetreten' + })).subscribe({ + next: () => { + return resolve(true); + }, + error: () => resolve(false), + complete: () => { + this.refreshKeys(); + } + }) + }) } getKeyArchive(): Observable { @@ -159,7 +189,7 @@ export class ApiService { this.http.delete(`api/cylinder/${cylinder.id}`).pipe( this.toast.observe({ loading: `Lösche Zylinder ${cylinder.name}...`, - success: 'Zylinder gelöscht', + success: `Zylinder ${cylinder.name} wurde gelöscht.`, error: 'Es ist ein Fehler aufgetreten' }) ).subscribe({ @@ -171,12 +201,12 @@ export class ApiService { }) } - restoreCylinder(id: string): Promise { + restoreCylinder(cylinder: ICylinder): Promise { return new Promise(resolve => { - this.http.put(`api/cylinder/${id}/restore`, null).pipe( + this.http.put(`api/cylinder/${cylinder.id}/restore`, null).pipe( this.toast.observe({ - loading: 'Stelle wiederher...', - success: 'Zylinder wiederhergestellt', + loading: `Stelle Zylinder ${cylinder.name} wieder her...`, + success: `Zylinder ${cylinder.name} erfolgreich wiederhergestellt`, error: 'Es ist ein Fehler aufgetreten' })).subscribe({ next: () => resolve(true),