feat: neuen Receiver-Input-Komponente mit Autocomplete und Tabellenanzeige hinzufügen

- Implementierung der `ReceiverInputComponent` mit Angular Material Autocomplete und Tabelle
- Abruf und Filterung von E-Mail-Adressen aus `ReceiverService`
- Anzeige des E-Mail-Inputs mit Autocomplete-Optionen und einer Datentabelle
- Integration der `ReceiverInputComponent` in den `envelope-creation` Formularschritt
This commit is contained in:
Developer 02 2024-08-22 17:04:46 +02:00
parent ddc0c9c6f3
commit cd32ae2a35
6 changed files with 137 additions and 13 deletions

View File

@ -2,6 +2,7 @@
<mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Titel & Vertragstyp</ng-template>
<receiver-input></receiver-input>
<mat-form-field>
<mat-label>Titel</mat-label>
<input matInput placeholder="Arbeitsvertrag" formControlName="firstCtrl" required>
@ -21,11 +22,8 @@
</mat-step>
<mat-step [stepControl]="secondFormGroup">
<form [formGroup]="secondFormGroup">
<ng-template matStepLabel>Fill out your address</ng-template>
<mat-form-field>
<mat-label>Address</mat-label>
<input matInput formControlName="secondCtrl" placeholder="Ex. 1 Main St, New York, NY" required>
</mat-form-field>
<ng-template matStepLabel>Empfänger</ng-template>
<receiver-input></receiver-input>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>

View File

@ -5,7 +5,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatStepperModule } from '@angular/material/stepper';
import { MatButtonModule } from '@angular/material/button';
import { MatSelectModule } from '@angular/material/select';
import { ReceiverService } from '../../services/receiver.service';
import { ReceiverInputComponent } from "./receiver-input/receiver-input.component";
@Component({
selector: 'app-envelope-creation',
@ -17,16 +17,14 @@ import { ReceiverService } from '../../services/receiver.service';
ReactiveFormsModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule
],
MatSelectModule,
ReceiverInputComponent
],
templateUrl: './envelope-creation.component.html',
styleUrl: './envelope-creation.component.scss'
})
export class EnvelopeCreationComponent {
constructor(private receiverService: ReceiverService) {
}
ngOnInit() {
this.selectedType = this.types[0].value;
}
@ -43,8 +41,8 @@ export class EnvelopeCreationComponent {
selectedType: string = "Mietvertrag"
types: any[] = [
{ value: 0, viewValue: 'Mietvertrag' },
{ value: 1, viewValue: 'Kaufvertrag' }
{value: 0, viewValue: 'Mietvertrag'},
{value: 1, viewValue: 'Kaufvertrag'}
];
typeControl = new FormControl('Mietvertrag', [Validators.required]);
}

View File

@ -0,0 +1,34 @@
<table mat-table [dataSource]="receiverData" class="mat-elevation-z8">
<ng-container matColumnDef="email">
<th mat-header-cell *matHeaderCellDef> Email </th>
<td mat-cell *matCellDef="let element">
<form class="example-form">
<mat-form-field class="example-full-width">
<mat-label>Email</mat-label>
<input type="text" aria-label="Email" matInput [formControl]="control"
[matAutocomplete]="auto">
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
@for (option of filteredOptions | async; track option) {
<mat-option [value]="option">{{option}}</mat-option>
}
</mat-autocomplete>
</mat-form-field>
</form>
</td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Anrede Email </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<ng-container matColumnDef="accessCode">
<th mat-header-cell *matHeaderCellDef> Zugriffscode </th>
<td mat-cell *matCellDef="let element"> {{element.accessCode}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>

View File

@ -0,0 +1,7 @@
.mat-stepper-vertical {
margin-top: 8px;
}
.mat-mdc-form-field {
margin-top: 16px;
}

View File

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

View File

@ -0,0 +1,64 @@
import { Component, OnInit } from '@angular/core';
import { Validators, FormsModule, ReactiveFormsModule, FormControl } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatTableModule } from '@angular/material/table';
import { Observable } from 'rxjs';
import { startWith, map } from 'rxjs/operators';
import { AsyncPipe } from '@angular/common';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatFormFieldModule } from '@angular/material/form-field';
import { ReceiverService } from '../../../services/receiver.service'
@Component({
selector: 'receiver-input',
standalone: true,
imports: [
MatTableModule,
FormsModule,
MatFormFieldModule,
MatInputModule,
MatAutocompleteModule,
ReactiveFormsModule,
AsyncPipe
],
templateUrl: './receiver-input.component.html',
styleUrl: './receiver-input.component.scss'
})
export class ReceiverInputComponent implements OnInit {
constructor(private receiverService: ReceiverService) { }
async ngOnInit() {
this.receiverService.getReceiver().subscribe({
next: (receivers) => {
this.options = receivers.map((r: any) => r.emailAddress);
this.filteredOptions = this.control.valueChanges.pipe(
startWith(''),
map(value => this._filter(value || '')),
);
}
})
}
typeControl = new FormControl('Mietvertrag', [Validators.required]);
control = new FormControl('');
options: string[] = [];
filteredOptions!: Observable<string[]>;
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.options.filter(option => option.toLowerCase().includes(filterValue));
}
//table
receiverData: { email: string; name: string; accessCode: string }[] = [
{ email: "", name: "", accessCode: "" }
];
displayedColumns: string[] = ['email', 'name', 'accessCode'];
}