Api umgebaut

This commit is contained in:
Bastian Wagner
2026-02-18 13:56:29 +01:00
parent 40e3ac187e
commit dd59a62e96
8 changed files with 78 additions and 63 deletions

View File

@@ -79,7 +79,7 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp {
})
).subscribe({
next: () => {
this.setData();
this.api.refreshKeys();
},
error: () => {
this.params.api.setGridOption("loading", false);
@@ -99,6 +99,7 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp {
if (n != null) {
this.key.handedOut = n;
this.params.api.refreshCells();
this.api.refreshKeys();
}
}
})
@@ -111,24 +112,17 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp {
maxWidth: '100vw',
maxHeight: '100vh'
}).afterClosed().subscribe({
next: n => {
next: async n => {
if (n != null) {
if (n == "") {
n = null;
}
this.key.keyLost = n;
this.params.api.refreshCells();
this.api.updateKey(this.key).subscribe();
this.setData();
await this.api.updateKey(this.key).subscribe();
this.api.refreshKeys();
}
}
})
}
private setData() {
let data = this.params.api.getGridOption("rowData");
data = data?.filter(d => d.id != this.key.id);
this.params.api.setGridOption("rowData", data);
this.params.api.setGridOption("loading", false);
}
}

View File

@@ -1,15 +1,22 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';
import { IUser } from '../model/interface/user.interface';
import { IKey } from '../model/interface/key.interface';
import { ICylinder } from '../model/interface/cylinder.interface';
import { HotToastService } from '@ngxpert/hot-toast';
@Injectable({
providedIn: 'root'
})
export class ApiService {
private http: HttpClient = inject(HttpClient);
private toast: HotToastService = inject(HotToastService);
public keys: BehaviorSubject<IKey[]> = new BehaviorSubject<IKey[]>([]);
public cylinders: BehaviorSubject<ICylinder[]> = new BehaviorSubject<ICylinder[]>([]);
constructor() { }
@@ -26,10 +33,21 @@ export class ApiService {
return this.http.get<{id: string, name: string}[]>('/api/role');
}
getKeys(): Observable<IKey[]> {
private getKeys(): Observable<IKey[]> {
return this.http.get<IKey[]>('api/key')
}
refreshKeys(): void{
this.getKeys().subscribe({
next: keys => {
this.keys.next(keys);
},
error: () => {
this.toast.error('Fehler beim Laden der Schlüssel')
}
})
}
getLostKeys(): Observable<IKey[]> {
return this.http.get<IKey[]>('api/key/lost')
}
@@ -82,10 +100,29 @@ export class ApiService {
return this.http.put(`api/key/${id}/restore`, null);
}
getCylinders(): Observable<ICylinder[]> {
private getCylinders(): Observable<ICylinder[]> {
return this.http.get<ICylinder[]>('api/cylinder');
}
/**
* Aktualisiert die Zylinder im Behaviour Subject
* cylinders
* @returns Promise wenn geladen
*/
refreshCylinders(): Promise<void> {
return new Promise<void>(resolve => {
this.getCylinders().subscribe({
next: data => {
this.cylinders.next(data);
},
error: () => {
this.toast.error('Fehler beim Laden der Zylinder')
},
complete: () => resolve()
})
})
}
deleteCylinder(cylinder: ICylinder): Observable<any> {
return this.http.delete(`api/cylinder/${cylinder.id}`)
}