Skip to content

Commit

Permalink
(fix) badge computation no longer block the from validation process
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Mar 18, 2024
1 parent 6a7262f commit c184308
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ <h5 class="card-title mb-0">Correspondance des champs avec le modèle</h5>
[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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FormGroup> = {};
public modalCreateMappingForm = new FormControl('');

public displayAllValues: boolean = false; // checkbox to (not) show fields associated by the selected mapping
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit c184308

Please sign in to comment.