Skip to content

Commit

Permalink
refactor(front): change the way to store bibfield
Browse files Browse the repository at this point in the history
In order to keep the 'order' json object return by
/field route we need store in array and note in object

Reviewed-by: andriac
  • Loading branch information
andriacap committed Feb 12, 2024
1 parent 569f42f commit 8e56091
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ <h3> <b>Rapport d'import:</b> {{importData?.id_import}}</h3>
<h6>Champs ({{ (importData?.fieldmapping || {} | keyvalue).length }})</h6>
</mat-panel-title>
</mat-expansion-panel-header>
<table *ngFor="let entity of tableFieldsCorresp | keyvalue " class="table table-striped table-bordered">
<caption>Entité : {{ entity.key }}</caption>
<table *ngFor="let entity of tableFieldsCorresp" class="table table-striped table-bordered">
<caption>{{ entity.entityLabel }}</caption>
<thead>
<tr>
<th>Champ source</th>
<th>Champ cible</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let field of entity?.value | keyvalue">
<tr *ngFor="let field of entity?.themes | keyvalue">
<td>{{ field.value }}</td>
<td>{{ field.key }}</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ImportReportComponent implements OnInit {
'group2_inpn',
];
public importData: Import | null;
public tableFieldsCorresp: FieldMappingValues = {};
public tableFieldsCorresp: Array<FieldMappingValues> = [];
public expansionPanelHeight: string = '60px';
public validBbox: any;
public taxaDistribution: Array<TaxaDistribution> = [];
Expand Down Expand Up @@ -98,7 +98,7 @@ export class ImportReportComponent implements OnInit {
this.loadErrors();
this.setImportStatus();
this._dataService.getBibFields().subscribe((fields) => {
this.mapFields(fields, this.tableFieldsCorresp, this.importData.fieldmapping);
this.tableFieldsCorresp = this.mapFields(fields, this.importData.fieldmapping);
});
this._dataService.getNomenclatures().subscribe((nomenclatures) => {
this.nomenclatures = nomenclatures;
Expand Down Expand Up @@ -267,28 +267,30 @@ export class ImportReportComponent implements OnInit {
this._router.navigate([this.config.IMPORT.MODULE_URL]);
}

mapFields(
fields: EntitiesThemesFields[],
tableFieldsCorresp: Object,
fieldMapping: FieldMappingValues
) {
mapFields(fields: EntitiesThemesFields[], fieldMapping: FieldMappingValues) {
const tableFieldsCorresp = [];
fields.forEach((field) => {
tableFieldsCorresp[field.entity.label] = {};
this.mapThemes(field.themes, tableFieldsCorresp[field.entity.label], fieldMapping);
const entityMapping = {
entityLabel: field.entity.label,
themes: this.mapThemes(field.themes, fieldMapping),
};
tableFieldsCorresp.push(entityMapping);
});
return tableFieldsCorresp;
}

mapThemes(themes: ThemesFields[], tableFieldsCorresp: Object, fieldMapping: FieldMappingValues) {
themes.forEach((theme) => {
this.mapField(theme.fields, tableFieldsCorresp, fieldMapping);
});
mapThemes(themes: ThemesFields[], fieldMapping: FieldMappingValues) {
const mappedThemes = themes.map((theme) => this.mapField(theme.fields, fieldMapping));
return Object.assign({}, ...mappedThemes);
}

mapField(listField: Field[], tableFieldsCorresp: Object, fieldMapping: FieldMappingValues) {
mapField(listField: Field[], fieldMapping: FieldMappingValues) {
const mappedFields = {};
listField.forEach((field) => {
if (Object.keys(fieldMapping).includes(field.name_field)) {
tableFieldsCorresp[field.name_field] = fieldMapping[field.name_field];
mappedFields[field.name_field] = fieldMapping[field.name_field];
}
});
return mappedFields;
}
}

0 comments on commit 8e56091

Please sign in to comment.