Wording und API
This commit is contained in:
@@ -59,7 +59,7 @@ export class CylinderArchiveComponent extends AgGridContainerComponent {
|
|||||||
|
|
||||||
async restoreCylinder(data: ICylinder) {
|
async restoreCylinder(data: ICylinder) {
|
||||||
this.gridApi.setGridOption("loading", true);
|
this.gridApi.setGridOption("loading", true);
|
||||||
await this.api.restoreCylinder(data.id);
|
await this.api.restoreCylinder(data);
|
||||||
this.loadCylinders();
|
this.loadCylinders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { MAT_DATE_LOCALE, provideNativeDateAdapter } from '@angular/material/cor
|
|||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { AsyncPipe, DatePipe } from '@angular/common';
|
import { AsyncPipe, DatePipe } from '@angular/common';
|
||||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||||
import { map, Observable, startWith, timestamp } from 'rxjs';
|
import { from, map, Observable, startWith, timestamp } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
MatBottomSheet,
|
MatBottomSheet,
|
||||||
MatBottomSheetModule,
|
MatBottomSheetModule,
|
||||||
@@ -99,7 +99,7 @@ export class HandoverDialogComponent {
|
|||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
const promises: Observable<any>[] = [
|
const promises: Observable<any>[] = [
|
||||||
this.getHandovers(),
|
this.getHandovers(),
|
||||||
this.loadCustomers()
|
from(this.loadCustomers())
|
||||||
];
|
];
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
@@ -125,20 +125,17 @@ export class HandoverDialogComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadCustomers() {
|
loadCustomers() {
|
||||||
const promise = this.api.getCustomers()
|
|
||||||
|
|
||||||
promise.subscribe({
|
return new Promise(async resolve => {
|
||||||
next: customers => {
|
const customers = await this.api.getCustomers();
|
||||||
this.customers = customers;
|
this.customers = customers;
|
||||||
this.filteredCustomers = this.handoverForm.controls.customer.valueChanges.pipe(
|
this.filteredCustomers = this.handoverForm.controls.customer.valueChanges.pipe(
|
||||||
startWith(''),
|
startWith(''),
|
||||||
map(value => this._filter(value || '')),
|
map(value => this._filter(value || '')),
|
||||||
);
|
);
|
||||||
}
|
resolve(customers)
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _filter(value: string): any[] {
|
private _filter(value: string): any[] {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { IKey } from '../../../../model/interface/key.interface';
|
|||||||
import { ApiService } from '../../../api.service';
|
import { ApiService } from '../../../api.service';
|
||||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||||
import { DeleteKeyComponent } from '../../../../modules/keys/components/delete-key/delete-key.component';
|
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 { HandoverDialogComponent } from '../../../../modules/keys/components/handover-dialog/handover-dialog.component';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||||
import { LostKeyComponent } from '../../../../modules/keys/components/lost-key/lost-key.component';
|
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 api: ApiService = inject(ApiService);
|
||||||
private dialog: MatDialog = inject(MatDialog);
|
private dialog: MatDialog = inject(MatDialog);
|
||||||
private toast = inject(HotToastService);
|
|
||||||
|
|
||||||
agInit(params: ICellRendererParams<any, any, any>): void {
|
agInit(params: ICellRendererParams<any, any, any>): void {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
@@ -69,22 +67,10 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp {
|
|||||||
// ref.componentInstance.editKey(this.key)
|
// ref.componentInstance.editKey(this.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteThisKey() {
|
async deleteThisKey() {
|
||||||
this.params.api.setGridOption("loading", true);
|
this.params.api.setGridOption("loading", true);
|
||||||
this.api.deleteKey(this.key.id).pipe(
|
await this.api.deleteKey(this.key);
|
||||||
this.toast.observe({
|
this.params.api.setGridOption("loading", false);
|
||||||
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);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,12 +101,42 @@ export class ApiService {
|
|||||||
return this.http.post('api/customer', data);
|
return this.http.post('api/customer', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCustomers(): Observable<any[]> {
|
getCustomers(): Promise<any[]> {
|
||||||
return this.http.get<any[]>('api/customer')
|
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[]> {
|
getKeyArchive(): Observable<IKey[]> {
|
||||||
@@ -159,7 +189,7 @@ export class ApiService {
|
|||||||
this.http.delete(`api/cylinder/${cylinder.id}`).pipe(
|
this.http.delete(`api/cylinder/${cylinder.id}`).pipe(
|
||||||
this.toast.observe({
|
this.toast.observe({
|
||||||
loading: `Lösche Zylinder ${cylinder.name}...`,
|
loading: `Lösche Zylinder ${cylinder.name}...`,
|
||||||
success: 'Zylinder gelöscht',
|
success: `Zylinder ${cylinder.name} wurde gelöscht.`,
|
||||||
error: 'Es ist ein Fehler aufgetreten'
|
error: 'Es ist ein Fehler aufgetreten'
|
||||||
})
|
})
|
||||||
).subscribe({
|
).subscribe({
|
||||||
@@ -171,12 +201,12 @@ export class ApiService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreCylinder(id: string): Promise<boolean> {
|
restoreCylinder(cylinder: ICylinder): Promise<boolean> {
|
||||||
return new Promise<boolean>(resolve => {
|
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({
|
this.toast.observe({
|
||||||
loading: 'Stelle wiederher...',
|
loading: `Stelle Zylinder ${cylinder.name} wieder her...`,
|
||||||
success: 'Zylinder wiederhergestellt',
|
success: `Zylinder ${cylinder.name} erfolgreich wiederhergestellt`,
|
||||||
error: 'Es ist ein Fehler aufgetreten'
|
error: 'Es ist ein Fehler aufgetreten'
|
||||||
})).subscribe({
|
})).subscribe({
|
||||||
next: () => resolve(true),
|
next: () => resolve(true),
|
||||||
|
|||||||
Reference in New Issue
Block a user