From b7f75fa5328149c0c724b5d346b909290a2a43e3 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Thu, 29 Oct 2020 11:59:42 +0100 Subject: [PATCH] FEAT #15296 TIME 2 fix bug select empty + disabled state criteria duplicate contacts --- .../contact-duplicate.component.ts | 1 - .../select-search/select-search.component.ts | 73 +++++++++++++------ 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/frontend/app/administration/contact/contact-duplicate/contact-duplicate.component.ts b/src/frontend/app/administration/contact/contact-duplicate/contact-duplicate.component.ts index cf82361b169..83b7cfe78ff 100644 --- a/src/frontend/app/administration/contact/contact-duplicate/contact-duplicate.component.ts +++ b/src/frontend/app/administration/contact/contact-duplicate/contact-duplicate.component.ts @@ -22,7 +22,6 @@ export class ContactDuplicateComponent implements OnInit { @ViewChild('adminMenuTemplate', { static: true }) adminMenuTemplate: TemplateRef<any>; - loading: boolean = true; subMenus: any[] = [ diff --git a/src/frontend/plugins/select-search/select-search.component.ts b/src/frontend/plugins/select-search/select-search.component.ts index 0f465b3710b..b58ec6bceb8 100755 --- a/src/frontend/plugins/select-search/select-search.component.ts +++ b/src/frontend/plugins/select-search/select-search.component.ts @@ -3,7 +3,8 @@ import { Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, QueryList, ViewChild, Renderer2, - Output + Output, + DoCheck } from '@angular/core'; import { ControlValueAccessor, FormControl } from '@angular/forms'; import { MatOption } from '@angular/material/core'; @@ -22,7 +23,7 @@ import { FunctionsService } from '@service/functions.service'; styleUrls: ['select-search.component.scss', '../../app/indexation/indexing-form/indexing-form.component.scss'], providers: [SortPipe] }) -export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterViewInit, ControlValueAccessor { +export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterViewInit, ControlValueAccessor, DoCheck { /** Label of the search placeholder */ @Input() placeholderLabel = this.translate.instant('lang.chooseValue'); @@ -76,6 +77,9 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView public filteredDatasMulti: ReplaySubject<any[]> = new ReplaySubject<any[]>(1); + datasClone: any = []; + isModelModified: boolean = false; + /** Reference to the MatSelect options */ public _options: QueryList<MatOption>; @@ -169,30 +173,57 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView } }); }); - setTimeout(() => { - let group = ''; - let index = 1; - this.datas = JSON.parse(JSON.stringify(this.datas)); - this.datas.forEach((element: any) => { - if (element.isTitle) { - group = `group_${index}`; - element.id = group; - index++; - } else { - element.group = group; - } - }); + let group = ''; + let index = 1; + this.datasClone = JSON.parse(JSON.stringify(this.datas)); + this.datasClone.forEach((element: any) => { + if (element.isTitle) { + group = `group_${index}`; + element.id = group; + index++; + } else { + element.group = group; + } + }); + + this.filteredDatas = this.formControlSearch.valueChanges + .pipe( + startWith(''), + map(value => this._filter(value)) + ); + // this.initMultipleHandling(); + + } + + // To resfresh filteredDatas if data is modfied + ngDoCheck(): void { + if (JSON.stringify(this.datas) !== JSON.stringify(this.datasClone) && !this.isModelModified) { + this.isModelModified = true; + + // if more data => contruct title again + if (this.datasClone.length !== this.datas.length) { + let group = ''; + let index = 1; + this.datasClone.forEach((element: any) => { + if (element.isTitle) { + group = `group_${index}`; + element.id = group; + index++; + } else { + element.group = group; + } + }); + } + + this.datasClone = JSON.parse(JSON.stringify(this.datas)); this.filteredDatas = this.formControlSearch.valueChanges .pipe( startWith(''), map(value => this._filter(value)) ); - }, 200); - - - // this.initMultipleHandling(); - + this.isModelModified = false; + } } initOptGroups() { @@ -415,6 +446,6 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView } emptyData() { - return this.returnValue === 'id' ? null : {id: null, label : this.translate.instant('lang.emptyValue')}; + return this.returnValue === 'id' ? null : { id: null, label: this.translate.instant('lang.emptyValue') }; } } -- GitLab