From 9d58d07f20a6369f98196aca766ae9224b252da5 Mon Sep 17 00:00:00 2001 From: Jacques Fize <4259846+jacquesfize@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:24:08 +0200 Subject: [PATCH] [IMPORT] update import report (#3223) * feat(import, report): refact of the report design * feat(import, report): change/add condition to display certain element in the import report pdf * fix(import, report) : fix inversion between source and destination field + hide field not mapped --- .../geonature/core/imports/routes/imports.py | 11 +- .../templates/import_template_pdf.html | 370 ++++++++++-------- backend/geonature/core/imports/utils.py | 1 - .../import_report.component.html | 2 +- .../import_report/import_report.component.ts | 14 +- 5 files changed, 221 insertions(+), 177 deletions(-) diff --git a/backend/geonature/core/imports/routes/imports.py b/backend/geonature/core/imports/routes/imports.py index 3fc42e4eba..d2c60dd938 100644 --- a/backend/geonature/core/imports/routes/imports.py +++ b/backend/geonature/core/imports/routes/imports.py @@ -660,15 +660,7 @@ def export_pdf(scope, imprt): """ if not imprt.has_instance_permission(scope): raise Forbidden - ctx = imprt.as_dict( - fields=[ - "errors", - "errors.type", - "errors.entity", - "dataset.dataset_name", - "destination.statistics_labels", - ] - ) + ctx = imprt.as_dict() ctx["map"] = request.form.get("map") if ctx["map"] == "undefined": @@ -685,7 +677,6 @@ def export_pdf(scope, imprt): ctx["url"] = "/".join(url_list) ctx["statistics_formated"] = {} - for label_dict in ctx["destination"]["statistics_labels"]: key = label_dict["value"] if label_dict["key"] in ctx["statistics"]: diff --git a/backend/geonature/core/imports/templates/import_template_pdf.html b/backend/geonature/core/imports/templates/import_template_pdf.html index 989979970c..d883186b23 100644 --- a/backend/geonature/core/imports/templates/import_template_pdf.html +++ b/backend/geonature/core/imports/templates/import_template_pdf.html @@ -1,176 +1,190 @@ - - + Export rapport d'import - - - Bandeau - - - - -
-
Import ID : {{ data.id_import }}
-
Date d'import : {{ data.date_end_import }}
-
Nom du fichier d'import : {{ data.full_file_name }}
-
-
+ + + Bandeau + + + + +
+

Rapport de l'import n°{{ data.id_import }}

+

+ Fichier : {{ data.full_file_name }} - Date d'import : {{ data.date_end_import or "en cours" + }} +

-
-
-

Fiche descriptive

-
-

Identification

-

-
- Auteur : - {% if data.authors_name: %} - {{ data.authors_name }} - {% endif %} -
- SRID : - {% if data.srid: %} - {{ data.srid }} - {% endif %} -
- Encodage : - {% if data.encoding: %} - {{ data.encoding }} - {% endif %} -
- Format : - {% if data.format_source_file: %} - {{ data.format_source_file }} - {% endif %} -
- Jeux de données : - {% if data.dataset: %} - {{ data.dataset.dataset_name }} - {% endif %} -

-
+
+
+
+
Fiche Descriptive
+
+
    + {% for label, key in {"Auteur:": "authors_name", "SRID:": "srid", "Encodage:": "encoding", + "Format:": "format_source_file"}.items() %} +
  • + {{label}} + : {{data[key]}} +
  • - {% if data.keywords: %} -
    -

    Mots-clés

    -

    - {{ data.keywords }} -

    -
    - {% endif %} -
- {% if data.map %} -
-
-

Zone géographique

- + {% endfor %} + {% if data.dataset: %} +
  • Jeu de données : {{ data.dataset.dataset_name }}
  • + {% endif %} + + {% if data.keywords: %} +
    +

    Mots-clés

    +

    {{ data.keywords }}

    {% endif %} +
    -
    -
    -

    Statistiques

    -
    - - - - - - - - + + {% if data.processed %} +
    +
    Zone géographique
    + +
    + +

    +
    +
    + {% endif %} + + + {% if data.date_end_import is not none %} +
    +
    + Statistiques +
    +
    +
    ChampsValeur
    + + + + + + + {% for key, value in data.statistics_formated.items() %} - + - + {% endfor %} - -
    ChampsValeur
    {{ key|capitalize }} {{ value }}
    - {% if data.chart %} -
    -
    - + + + {% if data.chart %} +
    + +
    + {% endif %}
    - {% endif %} +
    - -
    -
    -

    Erreurs

    -
    - - - - - - - - - - + {% endif %} + {% if data.processed %} +
    +
    + Erreurs +
    +
    +
    Type d'erreurChampNombre d'erreur(s)Entité
    + + + + + + + + + {% for error in data.errors %} - - - - - - + + + + + + {% endfor %} -
    Type d'erreurChampNombre d'erreur(s)Entité
    {{ error.type.description }}{{ error.column }}{{ error.rows | length }}{{ error.entity.label if error.entity else "" }}
    {{ error.type.description }}{{ error.column }}{{ error.rows | length }}{{ error.entity.label if error.entity else "" }}
    + +
    + + {% endif %} + + - - + #description-list { + list-style: none; + } + .row{ + width: 100%; + display: inline-block; + } + diff --git a/backend/geonature/core/imports/utils.py b/backend/geonature/core/imports/utils.py index 8b85abee02..d33ada6475 100644 --- a/backend/geonature/core/imports/utils.py +++ b/backend/geonature/core/imports/utils.py @@ -412,7 +412,6 @@ def generate_pdf_from_template(template: str, data: Any) -> bytes: base_url=current_app.config["API_ENDPOINT"], encoding="utf-8", ) - return html_file.write_pdf() diff --git a/frontend/src/app/modules/imports/components/import_report/import_report.component.html b/frontend/src/app/modules/imports/components/import_report/import_report.component.html index 04147f8c75..3a138f60a6 100644 --- a/frontend/src/app/modules/imports/components/import_report/import_report.component.html +++ b/frontend/src/app/modules/imports/components/import_report/import_report.component.html @@ -151,7 +151,7 @@
    Champs ({{ (importData?.fieldmapping || {} | keyvalue).length }})
    - + {{ field.source }} {{ field.destination }} {{ field.description }} diff --git a/frontend/src/app/modules/imports/components/import_report/import_report.component.ts b/frontend/src/app/modules/imports/components/import_report/import_report.component.ts index 0b89e2a549..2dcb6f3b8a 100644 --- a/frontend/src/app/modules/imports/components/import_report/import_report.component.ts +++ b/frontend/src/app/modules/imports/components/import_report/import_report.component.ts @@ -26,9 +26,9 @@ import { finalize } from 'rxjs/operators'; import { formatRowCount } from '../../utils/format-row-count'; interface CorrespondancesField { - source: string; + source: string | string[]; description: string; - destination: string | string[]; + destination: string; } @Component({ @@ -271,9 +271,9 @@ export class ImportReportComponent implements OnInit { mapField(listField: Field[], fieldMapping: FieldMappingValues): Array { const mappedFields: Array = listField.map((field) => { return { - source: field.name_field, + source: fieldMapping[field.name_field], description: field.comment, - destination: fieldMapping[field.name_field], + destination: field.name_field, }; }); return mappedFields; @@ -282,4 +282,10 @@ export class ImportReportComponent implements OnInit { formattedRowCount(row: Import): string { return formatRowCount(row); } + + filterMappingWithoutValue(fields: Array): Array { + return fields.filter((field) => { + return field.destination != null && field.source != null; + }); + } }