Wording und API

This commit is contained in:
Bastian Wagner
2026-02-19 17:19:03 +01:00
parent 7bd6dfae27
commit c542575046
4 changed files with 54 additions and 41 deletions

View File

@@ -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();
}

View File

@@ -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<any>[] = [
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[] {

View File

@@ -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<any, any, any>): 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);
}

View File

@@ -101,12 +101,42 @@ export class ApiService {
return this.http.post('api/customer', data);
}
getCustomers(): Observable<any[]> {
return this.http.get<any[]>('api/customer')
getCustomers(): Promise<any[]> {
return new Promise(resolve => {
this.http.get<any[]>('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<boolean> {
return new Promise(resolve => {
this.http.delete<IKey>(`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<IKey[]> {
@@ -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<boolean> {
restoreCylinder(cylinder: ICylinder): Promise<boolean> {
return new Promise<boolean>(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),