Skip to content

Commit

Permalink
feat: group field by entity in report
Browse files Browse the repository at this point in the history
Call getBibField
Match Import Data fields with response from getBibField
Create function to match object

Add one level of directive ngFor to create table as many as entity exists
Use existing type in match object function

Reviewed-by: andriacap
  • Loading branch information
andriacap committed Feb 12, 2024
1 parent c2e427b commit 5482b32
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +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 class="table table-striped table-bordered">
<thead>
<table *ngFor="let entity of tableFieldsCorresp | keyvalue " class="table table-striped table-bordered">
<caption>Entité : {{ entity.key }}</caption>
<thead>
<tr>
<th>Champ source</th>
<th>Champ cible</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let field of importData?.fieldmapping | keyvalue ">
<tr *ngFor="let field of entity?.value | keyvalue">
<td>{{ field.value }}</td>
<td>{{ field.key }}</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ img {
padding-right: 140px;
}
}

table caption {
caption-side: top;
border-collapse: collapse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import { MapService } from '@geonature_common/map/map.service';
import { DataService } from '../../services/data.service';
import { ImportProcessService } from '../import_process/import-process.service';
import {
EntitiesThemesFields,
Field,
Import,
ImportError,
Nomenclature,
NomenclatureType,
TaxaDistribution,
ThemesFields,
} from '../../models/import.model';
import { ConfigService } from '@geonature/services/config.service';
import { CsvExportService } from '../../services/csv-export.service';
import { FieldMappingValues } from '../../models/mapping.model';

interface MatchedNomenclature {
source: Nomenclature;
Expand All @@ -42,6 +46,7 @@ export class ImportReportComponent implements OnInit {
'group2_inpn',
];
public importData: Import | null;
public tableFieldsCorresp: FieldMappingValues = {}
public expansionPanelHeight: string = '60px';
public validBbox: any;
public taxaDistribution: Array<TaxaDistribution> = [];
Expand Down Expand Up @@ -92,6 +97,9 @@ export class ImportReportComponent implements OnInit {
// show line per line...
this.loadErrors();
this.setImportStatus();
this._dataService.getBibFields().subscribe((fields)=> {
this.mapFields(fields, this.tableFieldsCorresp, this.importData.fieldmapping);
})
this._dataService.getNomenclatures().subscribe((nomenclatures) => {
this.nomenclatures = nomenclatures;
});
Expand Down Expand Up @@ -258,4 +266,26 @@ export class ImportReportComponent implements OnInit {
navigateToImportList() {
this._router.navigate([this.config.IMPORT.MODULE_URL]);
}

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

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

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

}
4 changes: 2 additions & 2 deletions frontend/src/app/modules/imports/models/import.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ interface Theme {
desc_theme: string;
}

interface Field {
export interface Field {
id_field: number;
name_field: string;
fr_label: string;
Expand All @@ -123,7 +123,7 @@ interface Field {
comment: string;
}

interface ThemesFields {
export interface ThemesFields {
theme: Theme;
fields: [Field];
}
Expand Down

0 comments on commit 5482b32

Please sign in to comment.