keys
This commit is contained in:
@@ -6,11 +6,13 @@ import { LoginComponent } from './modules/auth/login/login.component';
|
||||
import { LayoutComponent } from './core/layout/layout.component';
|
||||
import { DashboardComponent } from './modules/dashboard/dashboard.component';
|
||||
import { AllUsersComponent } from './modules/admin/all-users/all-users.component';
|
||||
import { KeysComponent } from './modules/keys/keys.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: '', component: LayoutComponent, canActivate: [AuthenticatedGuard], children: [
|
||||
{ path: '', component: DashboardComponent },
|
||||
{ path: 'users', component: AllUsersComponent }
|
||||
{ path: 'users', component: AllUsersComponent },
|
||||
{ path: 'keys', component: KeysComponent }
|
||||
]},
|
||||
{ path: 'login', component: LoginComponent},
|
||||
];
|
||||
|
||||
@@ -32,7 +32,6 @@ export class AuthService {
|
||||
}
|
||||
|
||||
get isAdmin(): boolean {
|
||||
console.log(this.user, this.user.role == 'admin')
|
||||
return this.user != null && this.user.role == 'admin';
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<mat-drawer-container class="example-container" autosize>
|
||||
<mat-drawer #drawer class="main_sidenav" mode="side" opened="true">
|
||||
<button mat-button routerLink="/">Home</button>
|
||||
<button mat-button routerLink="/keys">Schlüssel</button>
|
||||
<button mat-button routerLink="/users">Alle User</button>
|
||||
</mat-drawer>
|
||||
|
||||
|
||||
9
client/src/app/model/interface/key.interface.ts
Normal file
9
client/src/app/model/interface/key.interface.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface IKey {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
handedOut: boolean;
|
||||
cylinder: any;
|
||||
nr: number;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ export class AllUsersComponent {
|
||||
, cellRenderer: (data: any) => this.datePipe.transform(new Date(data.value))
|
||||
, tooltipValueGetter: (data: any) => this.datePipe.transform(new Date(data.value), 'medium')
|
||||
},
|
||||
{
|
||||
{
|
||||
field: 'lastLogin'
|
||||
, headerName: 'Letzter Login'
|
||||
, width: 170
|
||||
@@ -61,6 +61,7 @@ export class AllUsersComponent {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +70,7 @@ export class AllUsersComponent {
|
||||
next: n => {
|
||||
this.gridApi.setGridOption("rowData", n)
|
||||
this.gridApi.setGridOption("loading", false);
|
||||
n.filter(u => u.username == 'mail@bastian-wagner.de').map((u: any) => { console.log(u['lastLogin'])})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
7
client/src/app/modules/keys/keys.component.html
Normal file
7
client/src/app/modules/keys/keys.component.html
Normal file
@@ -0,0 +1,7 @@
|
||||
@if (gridOptions || true) {
|
||||
<ag-grid-angular
|
||||
style="width: 100%; height: 100%;"
|
||||
(gridReady)="onGridReady($event)"
|
||||
[gridOptions]="gridOptions!"
|
||||
/>
|
||||
}
|
||||
0
client/src/app/modules/keys/keys.component.scss
Normal file
0
client/src/app/modules/keys/keys.component.scss
Normal file
23
client/src/app/modules/keys/keys.component.spec.ts
Normal file
23
client/src/app/modules/keys/keys.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { KeysComponent } from './keys.component';
|
||||
|
||||
describe('KeysComponent', () => {
|
||||
let component: KeysComponent;
|
||||
let fixture: ComponentFixture<KeysComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [KeysComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(KeysComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
112
client/src/app/modules/keys/keys.component.ts
Normal file
112
client/src/app/modules/keys/keys.component.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { AG_GRID_LOCALE_DE } from '@ag-grid-community/locale';
|
||||
import { AgGridAngular } from 'ag-grid-angular';
|
||||
import { GridOptions,GridApi, GridReadyEvent, CellEditingStoppedEvent, ICellEditorParams } from 'ag-grid-community';
|
||||
import { CommonModule, DatePipe } from '@angular/common';
|
||||
import { ApiService } from '../../shared/api.service';
|
||||
import { IKey } from '../../model/interface/key.interface';
|
||||
import { HotToastService } from '@ngxpert/hot-toast';
|
||||
|
||||
@Component({
|
||||
selector: 'app-keys',
|
||||
standalone: true,
|
||||
imports: [AgGridAngular],
|
||||
providers: [DatePipe],
|
||||
templateUrl: './keys.component.html',
|
||||
styleUrl: './keys.component.scss'
|
||||
})
|
||||
export class KeysComponent {
|
||||
private api: ApiService = inject(ApiService);
|
||||
private datePipe = inject(DatePipe);
|
||||
private toast: HotToastService = inject(HotToastService);
|
||||
|
||||
cylinders: any[] = [{name: 'dummy'}];
|
||||
|
||||
gridApi!: GridApi;
|
||||
|
||||
gridOptions: GridOptions = {
|
||||
localeText: AG_GRID_LOCALE_DE,
|
||||
rowData: [],
|
||||
columnDefs: [
|
||||
{ field: 'handedOut' , headerName: 'Ausgegeben', width: 100,editable: true, filter: true, headerTooltip: 'Ausgegeben' },
|
||||
{ field: 'name' , headerName: 'Name', flex: 1, editable: true, sort: 'asc', filter: true },
|
||||
{ field: 'nr' , headerName: 'Schlüsselnummer', flex: 1, editable: true, filter: true },
|
||||
{ field: 'cylinder' , headerName: 'Zylinder', flex: 1, editable: true, filter: true, cellRenderer: (data: any) => {return data.value?.name}, cellEditor: 'agSelectCellEditor',
|
||||
cellEditorParams: () => {
|
||||
return {
|
||||
values: this.cylinders,
|
||||
}
|
||||
},
|
||||
valueFormatter: (val) => {
|
||||
return val.value?.name;
|
||||
}
|
||||
},
|
||||
{ field: 'cylinder.system' , headerName: 'Schließanlage', flex: 1, editable: false, filter: true, cellRenderer: (data: any) => {return data.value?.name} },
|
||||
{
|
||||
field: 'createdAt'
|
||||
, headerName: 'Erstellt'
|
||||
, width: 120
|
||||
, type: 'date'
|
||||
, cellRenderer: (data: any) => this.datePipe.transform(new Date(data.value))
|
||||
, tooltipValueGetter: (data: any) => this.datePipe.transform(new Date(data.value), 'medium')
|
||||
},{
|
||||
field: 'updatedAt'
|
||||
, headerName: 'Geändert'
|
||||
, width: 120
|
||||
, type: 'date'
|
||||
, cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value), 'medium') : '-'
|
||||
, tooltipValueGetter: (data: any) => this.datePipe.transform(new Date(data.value), 'medium')
|
||||
},
|
||||
],
|
||||
loading: true,
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.api.getCylinders().subscribe({
|
||||
next: n => {
|
||||
this.cylinders = n;
|
||||
}
|
||||
})
|
||||
this.api.postKeySystem({ name: 'Development' }).subscribe()
|
||||
}
|
||||
|
||||
loadKeys() {
|
||||
this.gridApi.setGridOption("loading", true);
|
||||
this.api.getKeys().subscribe(res => {
|
||||
this.gridApi.setGridOption("rowData", res);
|
||||
this.gridApi.setGridOption("loading", false);
|
||||
res.map((r: any) => console.log(r.updatedAt))
|
||||
})
|
||||
}
|
||||
|
||||
onGridReady(params: GridReadyEvent) {
|
||||
this.gridApi = params.api;
|
||||
this.gridApi.addEventListener("cellEditingStopped", evt => this.cellEditEnd(evt))
|
||||
this.loadKeys();
|
||||
}
|
||||
|
||||
cellEditEnd(event: CellEditingStoppedEvent) {
|
||||
const key: IKey = event.data;
|
||||
console.log(event)
|
||||
|
||||
if (!event.valueChanged || event.newValue == event.oldValue) { return; }
|
||||
|
||||
this.gridApi.setGridOption("loading", true);
|
||||
this.api.updateKey(key)
|
||||
.pipe(
|
||||
this.toast.observe({
|
||||
loading: 'speichern...',
|
||||
success: 'Änderungen gespeichert',
|
||||
error: 'Änderungen konnten nicht gespeichert werden!'
|
||||
})
|
||||
).subscribe({
|
||||
next: () => {
|
||||
|
||||
this.gridApi.setGridOption("loading", false);
|
||||
},
|
||||
error: () => {
|
||||
this.loadKeys();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { IUser } from '../model/interface/user.interface';
|
||||
import { IKey } from '../model/interface/key.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -23,4 +24,22 @@ export class ApiService {
|
||||
getRoles(): Observable<{id: string, name: string}[]> {
|
||||
return this.http.get<{id: string, name: string}[]>('/api/role');
|
||||
}
|
||||
|
||||
getKeys(): Observable<IKey[]> {
|
||||
return this.http.get<IKey[]>('api/key')
|
||||
}
|
||||
|
||||
updateKey(key: IKey): Observable<IKey> {
|
||||
return this.http.put<IKey>('api/key', key);
|
||||
}
|
||||
|
||||
getCylinders(): Observable<any[]> {
|
||||
return this.http.get<any[]>('api/key/cylinder');
|
||||
}
|
||||
|
||||
postKey(key: IKey) {}
|
||||
|
||||
postKeySystem(keySystem: any) {
|
||||
return this.http.post('api/key/system', keySystem);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user