diff --git a/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.html b/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.html index 691717c737..bf78d132cf 100644 --- a/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.html +++ b/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.html @@ -174,7 +174,7 @@
Correspondance des champs avec le modèle
[matBadge]="this.invalidEntityControls(entitythemes.entity.label)" matBadgeColor="warn" matBadgeSize="small" - [matBadgeHidden]="entitiesForms[entitythemes.entity.label].valid" + [matBadgeHidden]="this.invalidEntityControls(entitythemes.entity.label)<1" class="entity-tab-label" > {{ entitythemes.entity.label }} diff --git a/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.ts b/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.ts index 1cb3e617a7..407b9a7570 100644 --- a/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.ts +++ b/frontend/src/app/modules/imports/components/import_process/fields-mapping-step/fields-mapping-step.component.ts @@ -48,7 +48,6 @@ export class FieldsMappingStepComponent implements OnInit { public fieldMappingForm = new FormControl(); // form to select the mapping to use public mappingFormControl: FormGroup; // form group to associate each source fields to import fields public createOrRenameMappingForm = new FormControl(null, [Validators.required]); // form to add a new mapping - public entitiesForms: Record = {}; public modalCreateMappingForm = new FormControl(''); public displayAllValues: boolean = false; // checkbox to (not) show fields associated by the selected mapping @@ -151,11 +150,17 @@ export class FieldsMappingStepComponent implements OnInit { */ invalidEntityControls(entityFormLabel: string) { let result: number = 0; - let entityForm = this.entitiesForms[entityFormLabel]; - - Object.values(entityForm.controls).forEach((c) => { - result += c.invalid ? 1 : 0; - }); + console.log(this.targetFields + .find(({ entity }) => entity.label === entityFormLabel)) + this.targetFields + .find(({ entity }) => entity.label === entityFormLabel) + .themes.forEach(({ fields }) => { + fields.forEach((field) => { + let control = this.mappingFormControl.controls[field.name_field] + result += control.status === 'INVALID' ? 1 : 0; + }); + }); + console.log(result); return result; } @@ -164,7 +169,6 @@ export class FieldsMappingStepComponent implements OnInit { */ populateMappingForm() { this.targetFields.forEach((entity) => { - this.entitiesForms[entity.entity.label] = this._fb.group({}); entity.themes.forEach(({ fields }) => { fields.forEach((field) => { const { name_field, autogenerated } = field; @@ -178,7 +182,6 @@ export class FieldsMappingStepComponent implements OnInit { this.onFieldMappingChange(name_field, value); }); this.mappingFormControl.addControl(name_field, control); - this.entitiesForms[entity.entity.label].addControl(name_field, control); } else { // If a control with a given name already exists, it would not be replaced with a new one. // The existing one will be updated with a new obser. We make sure to sync the references of it.