Api umgebaut
This commit is contained in:
@@ -22,7 +22,7 @@ import { LogModule } from './modules/log/log.module';
|
|||||||
envFilePath: ['.env'],
|
envFilePath: ['.env'],
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
}),
|
}),
|
||||||
CacheModule.register({ ttl: 5000, isGlobal: true }),
|
CacheModule.register({ ttl: 1000, isGlobal: true }),
|
||||||
DatabaseModule,
|
DatabaseModule,
|
||||||
AuthModule,
|
AuthModule,
|
||||||
UserModule,
|
UserModule,
|
||||||
|
|||||||
@@ -45,17 +45,19 @@ export class CylinderComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadCylinders() {
|
loadCylinders() {
|
||||||
this.api.getCylinders().subscribe({
|
this.gridApi.setGridOption("loading", true);
|
||||||
next: n => {
|
this.api.refreshCylinders();
|
||||||
this.gridApi.setGridOption("rowData", n);
|
|
||||||
this.gridApi.setGridOption("loading", false);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGridReady(params: GridReadyEvent) {
|
onGridReady(params: GridReadyEvent) {
|
||||||
this.gridApi = params.api;
|
this.gridApi = params.api;
|
||||||
this.loadCylinders();
|
this.loadCylinders();
|
||||||
|
this.api.cylinders.asObservable().subscribe({
|
||||||
|
next: (data) => {
|
||||||
|
this.gridApi.setGridOption("rowData", data);
|
||||||
|
this.gridApi.setGridOption("loading", false);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
openCreateCylinder() {
|
openCreateCylinder() {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Datum der Übergabe</mat-label>
|
<mat-label>Datum der Übergabe</mat-label>
|
||||||
<input matInput [matDatepicker]="picker" formControlName="timestamp">
|
<input matInput [matDatepicker]="picker" formControlName="timestamp">
|
||||||
<mat-hint>TT/MM/JJJJ</mat-hint>
|
<mat-hint>TT.MM.JJJJ (Beispiel: {{ exampleDate | date:'dd.MM.yyyy'}})</mat-hint>
|
||||||
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
|
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
|
||||||
<mat-datepicker #picker></mat-datepicker>
|
<mat-datepicker #picker></mat-datepicker>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
</mat-dialog-content>
|
</mat-dialog-content>
|
||||||
<mat-dialog-actions>
|
<mat-dialog-actions>
|
||||||
<button matButton mat-dialog-close class="btn-warning">Schließen</button>
|
<button matButton mat-dialog-close class="btn-warning">Schließen</button>
|
||||||
<button matButton="elevated" (click)="save()" class="btn-primary" [disabled]="handoverForm.invalid || handoverForm.pristine">
|
<button matButton="elevated" (click)="save()" class="btn-primary" [disabled]="handoverForm.invalid">
|
||||||
<mat-icon>save</mat-icon>
|
<mat-icon>save</mat-icon>
|
||||||
Speichern
|
Speichern
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { MatIconModule } from '@angular/material/icon';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-handover-dialog',
|
selector: 'app-handover-dialog',
|
||||||
imports: [FormsModule, MatTabsModule, AgGridAngular, ReactiveFormsModule, MatDatepickerModule, MatFormFieldModule, MatInputModule, MatButtonModule, MatDialogModule, MatAutocompleteModule, MatProgressSpinnerModule, MatRadioModule, AsyncPipe, MatIconModule],
|
imports: [FormsModule, MatTabsModule, AgGridAngular, ReactiveFormsModule, MatDatepickerModule, MatFormFieldModule, MatInputModule, MatButtonModule, MatDialogModule, MatAutocompleteModule, MatProgressSpinnerModule, MatRadioModule, AsyncPipe, MatIconModule, DatePipe],
|
||||||
providers: [
|
providers: [
|
||||||
provideNativeDateAdapter(),
|
provideNativeDateAdapter(),
|
||||||
{ provide: LOCALE_ID, useValue: 'de-DE' },
|
{ provide: LOCALE_ID, useValue: 'de-DE' },
|
||||||
@@ -47,6 +47,8 @@ export class HandoverDialogComponent {
|
|||||||
private datePipe = inject(DatePipe);
|
private datePipe = inject(DatePipe);
|
||||||
private toast: HotToastService = inject(HotToastService);
|
private toast: HotToastService = inject(HotToastService);
|
||||||
|
|
||||||
|
public exampleDate = new Date();
|
||||||
|
|
||||||
gridApi!: GridApi;
|
gridApi!: GridApi;
|
||||||
gridOptions: GridOptions = {
|
gridOptions: GridOptions = {
|
||||||
localeText: AG_GRID_LOCALE_DE,
|
localeText: AG_GRID_LOCALE_DE,
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ export class CreateKeyComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async doSetup() {
|
async doSetup() {
|
||||||
|
this.api.cylinders.subscribe({
|
||||||
|
next: data => {
|
||||||
|
this.cylinders = data;
|
||||||
|
this.createForm.controls.cylinder.patchValue(null);
|
||||||
|
}
|
||||||
|
})
|
||||||
await this.loadCylinders();
|
await this.loadCylinders();
|
||||||
|
|
||||||
this.filteredCylinders = this.createForm.controls.cylinder.valueChanges.pipe(
|
this.filteredCylinders = this.createForm.controls.cylinder.valueChanges.pipe(
|
||||||
@@ -63,15 +69,7 @@ export class CreateKeyComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadCylinders() {
|
loadCylinders() {
|
||||||
return new Promise(resolve => {
|
return this.api.refreshCylinders();
|
||||||
this.api.getCylinders().subscribe({
|
|
||||||
next: n => {
|
|
||||||
this.cylinders = n;
|
|
||||||
this.createForm.controls.cylinder.patchValue(null);
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class KeysComponent {
|
|||||||
private dialog: MatDialog = inject(MatDialog);
|
private dialog: MatDialog = inject(MatDialog);
|
||||||
private route: ActivatedRoute = inject(ActivatedRoute)
|
private route: ActivatedRoute = inject(ActivatedRoute)
|
||||||
|
|
||||||
cylinders: any[] = [];
|
// cylinders: any[] = [];
|
||||||
|
|
||||||
gridApi!: GridApi;
|
gridApi!: GridApi;
|
||||||
|
|
||||||
@@ -93,7 +93,6 @@ export class KeysComponent {
|
|||||||
, width: 140
|
, width: 140
|
||||||
, cellRenderer: AgKeyActionsComponent
|
, cellRenderer: AgKeyActionsComponent
|
||||||
, sortable: false
|
, sortable: false
|
||||||
// , onCellClicked: (event) => { this.deleteKey(event.data.id)}
|
|
||||||
,valueFormatter: (data: any) => { return data; },
|
,valueFormatter: (data: any) => { return data; },
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -103,30 +102,15 @@ export class KeysComponent {
|
|||||||
pagination: true,
|
pagination: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
deleteKey(id: string) {
|
|
||||||
this.api.deleteKey(id).subscribe()
|
|
||||||
}
|
|
||||||
|
|
||||||
editKey(id: string) {
|
editKey(id: string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.api.getCylinders().subscribe({
|
|
||||||
next: n => {
|
|
||||||
this.cylinders = n;
|
|
||||||
|
|
||||||
this.setFilterToParams();
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.cylinders = [];
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private setFilterToParams() {
|
private setFilterToParams() {
|
||||||
console.log(this.route.snapshot.queryParams);
|
|
||||||
const params = this.route.snapshot.queryParams;
|
const params = this.route.snapshot.queryParams;
|
||||||
|
|
||||||
if (Object.keys(params).includes('handedOut')) {
|
if (Object.keys(params).includes('handedOut')) {
|
||||||
@@ -143,23 +127,21 @@ export class KeysComponent {
|
|||||||
|
|
||||||
loadKeys() {
|
loadKeys() {
|
||||||
this.gridApi.setGridOption("loading", true);
|
this.gridApi.setGridOption("loading", true);
|
||||||
this.api.getKeys().subscribe({
|
this.api.refreshKeys();
|
||||||
next: n => {
|
|
||||||
this.gridApi.setGridOption("rowData", n);
|
|
||||||
this.gridApi.setGridOption("loading", false);
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.gridApi.setGridOption("loading", false);
|
|
||||||
// set error in grid
|
|
||||||
this.toast.error('Fehler beim Laden der Schlüssel')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGridReady(params: GridReadyEvent) {
|
onGridReady(params: GridReadyEvent) {
|
||||||
this.gridApi = params.api;
|
this.gridApi = params.api;
|
||||||
this.gridApi.addEventListener("cellEditingStopped", evt => this.cellEditEnd(evt))
|
this.gridApi.addEventListener("cellEditingStopped", evt => this.cellEditEnd(evt));
|
||||||
|
this.api.keys.asObservable().subscribe({
|
||||||
|
next: keys => {
|
||||||
|
console.log(keys)
|
||||||
|
this.gridApi.setGridOption("rowData", keys);
|
||||||
|
this.gridApi.setGridOption("loading", false);
|
||||||
|
}
|
||||||
|
})
|
||||||
this.loadKeys();
|
this.loadKeys();
|
||||||
|
this.setFilterToParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
cellEditEnd(event: CellEditingStoppedEvent) {
|
cellEditEnd(event: CellEditingStoppedEvent) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp {
|
|||||||
})
|
})
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
this.setData();
|
this.api.refreshKeys();
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.params.api.setGridOption("loading", false);
|
this.params.api.setGridOption("loading", false);
|
||||||
@@ -99,6 +99,7 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp {
|
|||||||
if (n != null) {
|
if (n != null) {
|
||||||
this.key.handedOut = n;
|
this.key.handedOut = n;
|
||||||
this.params.api.refreshCells();
|
this.params.api.refreshCells();
|
||||||
|
this.api.refreshKeys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -111,24 +112,17 @@ export class AgKeyActionsComponent implements ICellRendererAngularComp {
|
|||||||
maxWidth: '100vw',
|
maxWidth: '100vw',
|
||||||
maxHeight: '100vh'
|
maxHeight: '100vh'
|
||||||
}).afterClosed().subscribe({
|
}).afterClosed().subscribe({
|
||||||
next: n => {
|
next: async n => {
|
||||||
if (n != null) {
|
if (n != null) {
|
||||||
if (n == "") {
|
if (n == "") {
|
||||||
n = null;
|
n = null;
|
||||||
}
|
}
|
||||||
this.key.keyLost = n;
|
this.key.keyLost = n;
|
||||||
this.params.api.refreshCells();
|
this.params.api.refreshCells();
|
||||||
this.api.updateKey(this.key).subscribe();
|
await this.api.updateKey(this.key).subscribe();
|
||||||
this.setData();
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { inject, Injectable } from '@angular/core';
|
import { inject, Injectable } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { IUser } from '../model/interface/user.interface';
|
import { IUser } from '../model/interface/user.interface';
|
||||||
import { IKey } from '../model/interface/key.interface';
|
import { IKey } from '../model/interface/key.interface';
|
||||||
import { ICylinder } from '../model/interface/cylinder.interface';
|
import { ICylinder } from '../model/interface/cylinder.interface';
|
||||||
|
import { HotToastService } from '@ngxpert/hot-toast';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class ApiService {
|
export class ApiService {
|
||||||
private http: HttpClient = inject(HttpClient);
|
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() { }
|
constructor() { }
|
||||||
|
|
||||||
@@ -26,10 +33,21 @@ export class ApiService {
|
|||||||
return this.http.get<{id: string, name: string}[]>('/api/role');
|
return this.http.get<{id: string, name: string}[]>('/api/role');
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeys(): Observable<IKey[]> {
|
private getKeys(): Observable<IKey[]> {
|
||||||
return this.http.get<IKey[]>('api/key')
|
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[]> {
|
getLostKeys(): Observable<IKey[]> {
|
||||||
return this.http.get<IKey[]>('api/key/lost')
|
return this.http.get<IKey[]>('api/key/lost')
|
||||||
}
|
}
|
||||||
@@ -82,10 +100,29 @@ export class ApiService {
|
|||||||
return this.http.put(`api/key/${id}/restore`, null);
|
return this.http.put(`api/key/${id}/restore`, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCylinders(): Observable<ICylinder[]> {
|
private getCylinders(): Observable<ICylinder[]> {
|
||||||
return this.http.get<ICylinder[]>('api/cylinder');
|
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> {
|
deleteCylinder(cylinder: ICylinder): Observable<any> {
|
||||||
return this.http.delete(`api/cylinder/${cylinder.id}`)
|
return this.http.delete(`api/cylinder/${cylinder.id}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user