feat: ReceiverInputComponent zu ReceiverTableComponent hinzufügen
- `ReceiverInputComponent` für E-Mail-Eingabe mit Autocomplete erstellt - `ReceiverInputComponent` in `ReceiverTableComponent` integriert - `ReceiverInputComponent` mit Eingabeoptionen für E-Mail-Adressen konfiguriert
This commit is contained in:
parent
10ac34a9f7
commit
6a8baf08ed
@ -0,0 +1,12 @@
|
|||||||
|
<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>
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
.mat-stepper-vertical {
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mat-mdc-form-field {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
||||||
|
import { ReactiveFormsModule, FormControl } from '@angular/forms';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
|
import { Observable, map, startWith } from 'rxjs';
|
||||||
|
import { AsyncPipe } from '@angular/common';
|
||||||
|
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'receiver-input',
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
MatInputModule,
|
||||||
|
MatAutocompleteModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
AsyncPipe
|
||||||
|
],
|
||||||
|
templateUrl: './receiver-input.component.html',
|
||||||
|
styleUrl: './receiver-input.component.scss'
|
||||||
|
})
|
||||||
|
export class ReceiverInputComponent implements OnInit, OnChanges {
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.setupFiltering();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if (changes['options']) {
|
||||||
|
this.setupFiltering();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
control = new FormControl('');
|
||||||
|
filteredOptions!: Observable<string[]>;
|
||||||
|
|
||||||
|
@Input() options: string[] = [];
|
||||||
|
@Input() filter: (value: string) => string[] = value => {
|
||||||
|
const filterValue = value.toLowerCase();
|
||||||
|
return this.options.filter(option => option.toLowerCase().includes(filterValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupFiltering(): void {
|
||||||
|
this.filteredOptions = this.control.valueChanges.pipe(
|
||||||
|
startWith(''),
|
||||||
|
map(value => this.filter(value || '')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,21 +1,8 @@
|
|||||||
<table mat-table [dataSource]="receiverData" class="mat-elevation-z8">
|
<table mat-table [dataSource]="receiverData" class="mat-elevation-z8">
|
||||||
|
|
||||||
<ng-container matColumnDef="email">
|
<ng-container matColumnDef="email">
|
||||||
<th mat-header-cell *matHeaderCellDef> Email </th>
|
<th mat-header-cell *matHeaderCellDef> Email </th>
|
||||||
<td mat-cell *matCellDef="let element">
|
<td mat-cell *matCellDef="let element">
|
||||||
<form class="example-form">
|
<receiver-input [options]="receiver_mails"></receiver-input>
|
||||||
<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>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
.mat-stepper-vertical {
|
|
||||||
margin-top: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mat-mdc-form-field {
|
|
||||||
margin-top: 16px;
|
|
||||||
}
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { Validators, FormsModule, ReactiveFormsModule, FormControl } from '@angular/forms';
|
import { FormsModule, ReactiveFormsModule, FormControl } from '@angular/forms';
|
||||||
import { MatInputModule } from '@angular/material/input';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { MatTableModule } from '@angular/material/table';
|
import { MatTableModule } from '@angular/material/table';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
@ -8,9 +8,10 @@ import { AsyncPipe } from '@angular/common';
|
|||||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
import { ReceiverService } from '../../services/receiver.service'
|
import { ReceiverService } from '../../services/receiver.service'
|
||||||
|
import { ReceiverInputComponent } from '../receiver-input/receiver-input.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'receiver-input',
|
selector: 'receiver-table',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [
|
imports: [
|
||||||
MatTableModule,
|
MatTableModule,
|
||||||
@ -19,7 +20,8 @@ import { ReceiverService } from '../../services/receiver.service'
|
|||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatAutocompleteModule,
|
MatAutocompleteModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
AsyncPipe
|
AsyncPipe,
|
||||||
|
ReceiverInputComponent
|
||||||
],
|
],
|
||||||
templateUrl: './receiver-table.component.html',
|
templateUrl: './receiver-table.component.html',
|
||||||
styleUrl: './receiver-table.component.scss'
|
styleUrl: './receiver-table.component.scss'
|
||||||
@ -29,32 +31,17 @@ export class ReceiverTableComponent implements OnInit {
|
|||||||
constructor(private receiverService: ReceiverService) { }
|
constructor(private receiverService: ReceiverService) { }
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.receiverService.getReceiver().subscribe({
|
this.receiver_mails = await this.receiverService.getReceiverAsync().then((receivers: any[]) => receivers.map(r => r.emailAddress));
|
||||||
next: (receivers) => {
|
|
||||||
this.options = receivers.map((r: any) => r.emailAddress);
|
|
||||||
|
|
||||||
this.filteredOptions = this.control.valueChanges.pipe(
|
|
||||||
startWith(''),
|
|
||||||
map(value => {
|
|
||||||
console.log(value);
|
|
||||||
return this._filter(value || '');
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typeControl = new FormControl('Mietvertrag', [Validators.required]);
|
|
||||||
|
|
||||||
control = new FormControl('');
|
control = new FormControl('');
|
||||||
options: string[] = [];
|
receiver_mails: string[] = [];
|
||||||
filteredOptions!: Observable<string[]>;
|
filteredOptions!: Observable<string[]>;
|
||||||
|
|
||||||
|
receiver_filter(value: string): string[] {
|
||||||
private _filter(value: string): string[] {
|
|
||||||
const filterValue = value.toLowerCase();
|
const filterValue = value.toLowerCase();
|
||||||
|
|
||||||
return this.options.filter(option => option.toLowerCase().includes(filterValue));
|
return this.receiver_mails.filter(option => option.toLowerCase().includes(filterValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
//table
|
//table
|
||||||
@ -63,5 +50,4 @@ export class ReceiverTableComponent implements OnInit {
|
|||||||
];
|
];
|
||||||
|
|
||||||
displayedColumns: string[] = ['email', 'name', 'accessCode'];
|
displayedColumns: string[] = ['email', 'name', 'accessCode'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user