Lost Keys

This commit is contained in:
Bastian Wagner
2025-01-03 13:39:47 +01:00
parent c8c2ee18cb
commit 92f0c10bd8
35 changed files with 569 additions and 42 deletions

View File

@@ -0,0 +1,11 @@
<h2 mat-dialog-title>Verlorene Schlüssel</h2>
<mat-dialog-content>
<ag-grid-angular
style="width: 100%; height: 100%;"
(gridReady)="onGridReady($event)"
[gridOptions]="gridOptions!"
/>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="dataChanged">Schließen</button>
</mat-dialog-actions>

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LostKeysComponent } from './lost-keys.component';
describe('LostKeysComponent', () => {
let component: LostKeysComponent;
let fixture: ComponentFixture<LostKeysComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LostKeysComponent]
})
.compileComponents();
fixture = TestBed.createComponent(LostKeysComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,95 @@
import { CommonModule, DatePipe } from '@angular/common';
import { Component, inject } from '@angular/core';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { HotToastService } from '@ngxpert/hot-toast';
import { GridApi, GridOptions, GridReadyEvent } from 'ag-grid-community';
import { ICylinder } from '../../../../model/interface/cylinder.interface';
import { IKey } from '../../../../model/interface/key.interface';
import { ApiService } from '../../../../shared/api.service';
import { HELPER } from '../../../../shared/helper.service';
import { AgGridAngular } from 'ag-grid-angular';
import { LostKeyComponent } from '../lost-key/lost-key.component';
import { MatButtonModule } from '@angular/material/button';
@Component({
selector: 'app-lost-keys',
standalone: true,
imports: [MatDialogModule, AgGridAngular, CommonModule, MatButtonModule],
providers: [DatePipe],
templateUrl: './lost-keys.component.html',
styleUrl: './lost-keys.component.scss'
})
export class LostKeysComponent {
private api: ApiService = inject(ApiService);
private datePipe = inject(DatePipe);
private dialog: MatDialog = inject(MatDialog);
private toast = inject(HotToastService);
gridApi!: GridApi;
dataChanged = false;
gridOptions: GridOptions = HELPER.getGridOptions();
constructor() {
this.gridOptions.columnDefs = [
{ colId: 'name', field: 'name', headerName: 'Name', sort: 'asc', flex: 1, filter: true },
{ colId: 'nr', field: 'nr', headerName: 'Schlüsselnummer', flex: 1, filter: true },
{ colId: 'cylinder', field: 'cylinder', headerName: 'Zylinder', flex: 1, filter: true,
cellRenderer: (data: any) => data.value?.map((m: ICylinder) => m.name).join(', ')
},
{
colId: 'customer', field: 'customer.name', headerName: 'Kunde', flex: 1, filter: true,
},
{ colId: 'keyLost', field: 'keyLost', headerName: 'Verloren seit', width: 100,
cellRenderer: (data: any) => this.datePipe.transform(new Date(data.value), 'dd.MM.yyyy'),
},
{
colId: 'actions',
headerName: 'Aktionen',
width: 100,
tooltipValueGetter: () => 'Als gefunden markieren',
cellRenderer: (params: any) => `<div class="icon magnifying-glass icon-btn-sm"></div>`,
onCellClicked: (event: any) => {
if (event.colDef.colId === 'actions') {
this.markAsFound(event.data);
}
}
}
];
this.gridOptions.overlayNoRowsTemplate = 'Bisher wurden keine Schlüssel als verloren gemeldet. Sobald dies der Fall ist, werden sie hier angezeigt.';
}
onGridReady(params: GridReadyEvent) {
this.gridApi = params.api;
this.loadLostKeys();
}
loadLostKeys() {
this.gridApi?.setGridOption("loading", true);
this.api.getLostKeys().subscribe({
next: keys => {
this.gridApi.setGridOption("rowData", keys);
this.gridApi.setGridOption("loading", false);
}
});
}
markAsFound(key: IKey) {
this.dialog.open(LostKeyComponent, { data: key, autoFocus: false }).afterClosed().subscribe({
next: (result) => {
if (result == "") {
key.keyLost = null;
this.api.updateKey(key).subscribe({
next: () => {
this.toast.success('Schlüssel als gefunden markiert');
this.loadLostKeys();
}
});
this.dataChanged = true;
}
}
})
}
}