From 5e2b900b1837f9e8ffee59e1082738697777d64e Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Fri, 18 Oct 2024 17:26:36 +0200 Subject: [PATCH] create angefangen --- .../modules/keys/create/create.component.html | 28 +++++++++ .../modules/keys/create/create.component.scss | 4 ++ .../keys/create/create.component.spec.ts | 23 +++++++ .../modules/keys/create/create.component.ts | 60 +++++++++++++++++++ .../src/app/modules/keys/keys.component.html | 4 +- .../src/app/modules/keys/keys.component.scss | 5 ++ client/src/app/modules/keys/keys.component.ts | 17 ++++-- client/src/app/shared/api.service.ts | 3 +- 8 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 client/src/app/modules/keys/create/create.component.html create mode 100644 client/src/app/modules/keys/create/create.component.scss create mode 100644 client/src/app/modules/keys/create/create.component.spec.ts create mode 100644 client/src/app/modules/keys/create/create.component.ts diff --git a/client/src/app/modules/keys/create/create.component.html b/client/src/app/modules/keys/create/create.component.html new file mode 100644 index 0000000..7910add --- /dev/null +++ b/client/src/app/modules/keys/create/create.component.html @@ -0,0 +1,28 @@ +

Schlüssel anlegen

+ +
+ + + Name + + + + + Schlüsselnummer + + + + + Schließzylinder + + @for (item of cylinders; track $index) { + {{ item.name }} + } + + +
+
+ + + + \ No newline at end of file diff --git a/client/src/app/modules/keys/create/create.component.scss b/client/src/app/modules/keys/create/create.component.scss new file mode 100644 index 0000000..df8ee7a --- /dev/null +++ b/client/src/app/modules/keys/create/create.component.scss @@ -0,0 +1,4 @@ +form { + display: flex; + flex-direction: column; +} \ No newline at end of file diff --git a/client/src/app/modules/keys/create/create.component.spec.ts b/client/src/app/modules/keys/create/create.component.spec.ts new file mode 100644 index 0000000..b3e2e4e --- /dev/null +++ b/client/src/app/modules/keys/create/create.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateKeyComponent } from './create.component'; + +describe('CreateComponent', () => { + let component: CreateKeyComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [CreateKeyComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(CreateKeyComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/modules/keys/create/create.component.ts b/client/src/app/modules/keys/create/create.component.ts new file mode 100644 index 0000000..a3b3073 --- /dev/null +++ b/client/src/app/modules/keys/create/create.component.ts @@ -0,0 +1,60 @@ +import { Component, inject } from '@angular/core'; +import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { MatDialogModule } from '@angular/material/dialog'; +import { ApiService } from '../../../shared/api.service'; +import { MatAutocompleteModule } from '@angular/material/autocomplete'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { map, Observable, startWith } from 'rxjs'; +import { MatSelectModule } from '@angular/material/select'; + +@Component({ + selector: 'app-create', + standalone: true, + imports: [MatDialogModule, MatButtonModule, ReactiveFormsModule, FormsModule, MatFormFieldModule, MatInputModule, MatSelectModule], + templateUrl: './create.component.html', + styleUrl: './create.component.scss' +}) +export class CreateKeyComponent { + + private api: ApiService = inject(ApiService); + + createForm = new FormGroup({ + name: new FormControl(null, Validators.required), + nr: new FormControl(null, Validators.required), + cylinder: new FormControl(null, Validators.required), + }) + + cylinders: any[] = []; + filteredCylinders!: Observable; + + ngOnInit(): void { + this.loadCylinders(); + + this.filteredCylinders = this.createForm.controls.cylinder.valueChanges.pipe( + startWith(''), + map(value => this._filter(value || '')), + ); + } + + private _filter(value: string): string[] { + const filterValue = value.toLowerCase(); + + return this.cylinders.filter(option => option.name.toLowerCase().includes(filterValue)); + } + + loadCylinders() { + this.api.getCylinders().subscribe({ + next: n => { + this.cylinders = n; + this.createForm.controls.cylinder.patchValue(null); + } + }) + } + + save() { + console.log(this.createForm.value) + this.api.createKey(this.createForm.value as any) + } +} diff --git a/client/src/app/modules/keys/keys.component.html b/client/src/app/modules/keys/keys.component.html index e87e1ba..a53fd3b 100644 --- a/client/src/app/modules/keys/keys.component.html +++ b/client/src/app/modules/keys/keys.component.html @@ -4,4 +4,6 @@ (gridReady)="onGridReady($event)" [gridOptions]="gridOptions!" /> -} \ No newline at end of file +} + + \ No newline at end of file diff --git a/client/src/app/modules/keys/keys.component.scss b/client/src/app/modules/keys/keys.component.scss index e69de29..1472c97 100644 --- a/client/src/app/modules/keys/keys.component.scss +++ b/client/src/app/modules/keys/keys.component.scss @@ -0,0 +1,5 @@ +.btn-create { + position: absolute; + bottom: 12px; + right: 12px; +} \ No newline at end of file diff --git a/client/src/app/modules/keys/keys.component.ts b/client/src/app/modules/keys/keys.component.ts index 70e0739..7672826 100644 --- a/client/src/app/modules/keys/keys.component.ts +++ b/client/src/app/modules/keys/keys.component.ts @@ -6,11 +6,14 @@ 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'; +import { MatButtonModule } from '@angular/material/button'; +import { MatDialog, MatDialogModule } from '@angular/material/dialog'; +import { CreateKeyComponent } from './create/create.component'; @Component({ selector: 'app-keys', standalone: true, - imports: [AgGridAngular], + imports: [AgGridAngular, MatButtonModule, MatDialogModule], providers: [DatePipe], templateUrl: './keys.component.html', styleUrl: './keys.component.scss' @@ -19,6 +22,7 @@ export class KeysComponent { private api: ApiService = inject(ApiService); private datePipe = inject(DatePipe); private toast: HotToastService = inject(HotToastService); + private dialog: MatDialog = inject(MatDialog); cylinders: any[] = [{name: 'dummy'}]; @@ -54,7 +58,7 @@ export class KeysComponent { , headerName: 'Geändert' , width: 120 , type: 'date' - , cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value), 'medium') : '-' + , cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value)) : '-' , tooltipValueGetter: (data: any) => this.datePipe.transform(new Date(data.value), 'medium') }, ], @@ -100,13 +104,14 @@ export class KeysComponent { error: 'Änderungen konnten nicht gespeichert werden!' }) ).subscribe({ - next: () => { - - this.gridApi.setGridOption("loading", false); - }, + next: () => {this.gridApi.setGridOption("loading", false);}, error: () => { this.loadKeys(); } }) } + + openCreateKey() { + this.dialog.open(CreateKeyComponent) + } } diff --git a/client/src/app/shared/api.service.ts b/client/src/app/shared/api.service.ts index f512457..714c9c0 100644 --- a/client/src/app/shared/api.service.ts +++ b/client/src/app/shared/api.service.ts @@ -37,7 +37,8 @@ export class ApiService { return this.http.get('api/key/cylinder'); } - postKey(key: IKey) {} + createKey(key: any) { + } postKeySystem(keySystem: any) { return this.http.post('api/key/system', keySystem);