diff --git a/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-input/receiver-input.component.ts b/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-input/receiver-input.component.ts index e01eb995..376cb002 100644 --- a/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-input/receiver-input.component.ts +++ b/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-input/receiver-input.component.ts @@ -37,19 +37,19 @@ export class ReceiverInputComponent implements OnInit, OnChanges { private setupFiltering(): void { this.filteredOptions = this.control.valueChanges.pipe( startWith(''), - map(value => this.filter(value || '', this.options)), + map(value => this.filter(value || '', this.options, this.index)), ); } control = new FormControl(''); filteredOptions!: Observable; - @Input() options: string[] = []; - @Input() filter: (value: string, options: string[]) => string[] = value => { + @Input() filter: (value: string, options: string[], index?: number) => string[] = value => { const filterValue = value.toLowerCase(); return this.options.filter(option => option.toLowerCase().includes(filterValue)); } + @Input() index?: number; public get text(): string { return this.control.value || ''; diff --git a/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.html b/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.html index a7b69ac5..b439f39e 100644 --- a/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.html +++ b/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.html @@ -1,8 +1,8 @@ - diff --git a/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.ts b/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.ts index b45d343c..d637f715 100644 --- a/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.ts +++ b/EnvelopeGenerator.GeneratorAPI/ClientApp/envelope-generator-ui/src/app/components/receiver-table/receiver-table.component.ts @@ -34,24 +34,39 @@ export class ReceiverTableComponent implements OnInit { constructor(private receiverService: ReceiverService) { } async ngOnInit() { - this.receiver_mails = await this.receiverService.getReceiverAsync().then((receivers: any[]) => receivers.map(r => r.emailAddress)); + const receivers = await this.receiverService.getReceiverAsync(); + this.receiver_mails = receivers.map((r: any) => r.emailAddress); + this.last_used_name = receivers.reduce((acc: any, r: any) => { + acc[r.emailAddress] = r.lastUsedName; + return acc; + }, {} as { [key: string]: string | null }); } - receiver_filter: (value: string, options: string[]) => string[] = (value, options) => { + receiver_filter: (value: string, options: string[], index?: number) => string[] = (value, options, index) => { const filterValue = value.toLowerCase(); + // set the name if it is used befor + const name = this.last_used_name[value]; + if (name && index) + this.receiverData.at(index)!.name = name + + // !!! do not allow email duplication !!! + var similarMails = this.receiver_mails.filter(m => m.toLocaleLowerCase() === value.toLocaleLowerCase() && m !== value) + if (similarMails.length > 0 && index != undefined) { + this.receiverInputs[index].text = similarMails[0]; + } + console.log(this.receiverInputs.length + " - " + index) // if added into last row if (value.length > 0 && (this.receiverInputs.at(-1)?.lenght ?? 0) > 0) { this.receiverData.at(-1)!.accessCode = generateAccessCode(); this.receiverData.push({ email: "", name: "", accessCode: "" }); this.update(); } - else if (value.length == 0) { - for (var i = 0; i < this.receiverInputs.length - 1; i++) { - if (this.receiverInputs[i].lenght === 0) { - this.receiverData.splice(i, 1); - this.update(); - } + // delete the row with out mail + else if (value.length === 0 && this.receiverInputs.length - 1 !== index) { + if ( this.receiverInputs.length > 1 && this.receiverInputs[index!]?.lenght === 0) { + this.receiverData.splice(index!, 1); + this.update(); } } @@ -59,6 +74,7 @@ export class ReceiverTableComponent implements OnInit { } receiver_mails: string[] = []; + last_used_name: { [key: string]: string | null } = {}; @ViewChildren(ReceiverInputComponent) receiverInputsQueryList!: QueryList; get receiverInputs(): ReceiverInputComponent[] {
Email - + +