queryparams aus url

This commit is contained in:
Bastian Wagner
2026-02-17 15:38:38 +01:00
parent a292b29cb1
commit 40e3ac187e
4 changed files with 33 additions and 13 deletions

View File

@@ -4,6 +4,7 @@
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve",
"start:remote": "ng serve --configuration remote",
"build": "ng build", "build": "ng build",
"watch": "ng build --watch --configuration development", "watch": "ng build --watch --configuration development",
"test": "jest", "test": "jest",

View File

@@ -1,11 +1,8 @@
{ {
"/api": { "/api": {
"target": "http://keyvaultpro.de:3701", "target": "https://keyvaultpro.de",
"secure": false, "secure": true,
"logLevel": "debug", "changeOrigin": true,
"changeOrigin": true, "logLevel": "debug"
"pathRewrite": { }
"^/api": ""
}
}
} }

View File

@@ -59,7 +59,7 @@
<p>Derzeit ausgegebene Schlüssel</p> <p>Derzeit ausgegebene Schlüssel</p>
</mat-card-content> </mat-card-content>
<mat-card-actions> <mat-card-actions>
<button matButton routerLink="/keys">Verwalten</button> <button matButton routerLink="/keys" [queryParams]="{handedOut: true }">Verwalten</button>
</mat-card-actions> </mat-card-actions>
</mat-card> </mat-card>
</div> </div>

View File

@@ -1,7 +1,7 @@
import { Component, inject } from '@angular/core'; import { Component, inject } from '@angular/core';
import { AG_GRID_LOCALE_DE } from '@ag-grid-community/locale'; import { AG_GRID_LOCALE_DE } from '@ag-grid-community/locale';
import { AgGridAngular } from 'ag-grid-angular'; import { AgGridAngular } from 'ag-grid-angular';
import { GridOptions,GridApi, GridReadyEvent, CellEditingStoppedEvent, ICellEditorParams } from 'ag-grid-community'; import { GridOptions,GridApi, GridReadyEvent, CellEditingStoppedEvent, ICellEditorParams, FilterActionParams, FilterAction } from 'ag-grid-community';
import { DatePipe } from '@angular/common'; import { DatePipe } from '@angular/common';
import { ApiService } from '../../shared/api.service'; import { ApiService } from '../../shared/api.service';
import { IKey } from '../../model/interface/key.interface'; import { IKey } from '../../model/interface/key.interface';
@@ -18,11 +18,13 @@ import { ICylinder } from '../../model/interface/cylinder.interface';
import { LostKeysComponent } from './components/lost-keys/lost-keys.component'; import { LostKeysComponent } from './components/lost-keys/lost-keys.component';
import { MatTooltipModule } from '@angular/material/tooltip'; import { MatTooltipModule } from '@angular/material/tooltip';
import { SelectKeyCylinderComponent } from './create/select-key-cylinder/select-key-cylinder.component'; import { SelectKeyCylinderComponent } from './create/select-key-cylinder/select-key-cylinder.component';
import { ActivatedRoute, Route } from '@angular/router';
import { ModuleRegistry } from 'ag-grid-community';
@Component({ @Component({
selector: 'app-keys', selector: 'app-keys',
imports: [AgGridAngular, MatButtonModule, MatDialogModule, MatIconModule, MatTooltipModule], imports: [AgGridAngular, MatButtonModule, MatDialogModule, MatIconModule, MatTooltipModule],
providers: [DatePipe], providers: [DatePipe, ModuleRegistry],
templateUrl: './keys.component.html', templateUrl: './keys.component.html',
styleUrl: './keys.component.scss' styleUrl: './keys.component.scss'
}) })
@@ -31,6 +33,7 @@ export class KeysComponent {
private datePipe = inject(DatePipe); private datePipe = inject(DatePipe);
private toast: HotToastService = inject(HotToastService); private toast: HotToastService = inject(HotToastService);
private dialog: MatDialog = inject(MatDialog); private dialog: MatDialog = inject(MatDialog);
private route: ActivatedRoute = inject(ActivatedRoute)
cylinders: any[] = []; cylinders: any[] = [];
@@ -83,7 +86,7 @@ export class KeysComponent {
, cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value)) : '-' , cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value)) : '-'
, tooltipValueGetter: (data: any) => this.datePipe.transform(new Date(data.value), 'medium') , tooltipValueGetter: (data: any) => this.datePipe.transform(new Date(data.value), 'medium')
}, },
{ colId: 'handedOut', field: 'handedOut' , headerName: 'Ausgegeben', width: 100, editable: false, filter: false, headerTooltip: 'Ausgegeben' }, { colId: 'handedOut', field: 'handedOut' , headerName: 'Ausgegeben', width: 100, editable: false, filter: true, headerTooltip: 'Ausgegeben' },
{ {
colId: 'actions' colId: 'actions'
, headerName: 'Aktionen' , headerName: 'Aktionen'
@@ -100,6 +103,7 @@ export class KeysComponent {
pagination: true, pagination: true,
} }
deleteKey(id: string) { deleteKey(id: string) {
this.api.deleteKey(id).subscribe() this.api.deleteKey(id).subscribe()
} }
@@ -112,6 +116,8 @@ export class KeysComponent {
this.api.getCylinders().subscribe({ this.api.getCylinders().subscribe({
next: n => { next: n => {
this.cylinders = n; this.cylinders = n;
this.setFilterToParams();
}, },
error: () => { error: () => {
this.cylinders = []; this.cylinders = [];
@@ -119,6 +125,22 @@ export class KeysComponent {
}) })
} }
private setFilterToParams() {
console.log(this.route.snapshot.queryParams);
const params = this.route.snapshot.queryParams;
if (Object.keys(params).includes('handedOut')) {
this.gridApi.setFilterModel({
handedOut: {
filterType: 'text',
type: params['handedOut']
}
})
}
}
loadKeys() { loadKeys() {
this.gridApi.setGridOption("loading", true); this.gridApi.setGridOption("loading", true);
this.api.getKeys().subscribe({ this.api.getKeys().subscribe({