From 071cd0f30b51655d565664ec57865d3a267972cc Mon Sep 17 00:00:00 2001 From: Andria Capai Date: Wed, 22 Jan 2025 18:03:28 +0100 Subject: [PATCH] refact: add logic to check if import is done - Add method and accessor get to check if import is completed - Replace code where checking if import is completed Reviewed-by: andriacap --- .../components/import_list/import-list.component.ts | 2 +- .../import_process/import-process.service.ts | 13 +++++++++++++ .../import-step/import-step.component.ts | 2 +- .../upload-file-step/upload-file-step.component.ts | 4 ---- .../import_report/import_report.component.html | 2 +- .../import_report/import_report.component.ts | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/modules/imports/components/import_list/import-list.component.ts b/frontend/src/app/modules/imports/components/import_list/import-list.component.ts index f2d6564d38..ecc1091b20 100644 --- a/frontend/src/app/modules/imports/components/import_list/import-list.component.ts +++ b/frontend/src/app/modules/imports/components/import_list/import-list.component.ts @@ -186,7 +186,7 @@ export class ImportListComponent implements OnInit { // Prépare les données de la modale en fonction de l'action if (actionType === 'edit') { let additionalMessage:string; - if(!!this.selectedRow.date_end_import) { + if(this.importProcessService.checkImportDone(this.selectedRow)) { additionalMessage = 'Attention : Vous vous apprêtez à modifier un import terminé. Toute modification entraînera la suppression des données importées.' } else { additionalMessage = 'Attention : à chaque confirmation de chaque étape de cet import en cours , les données seront écrasées.' diff --git a/frontend/src/app/modules/imports/components/import_process/import-process.service.ts b/frontend/src/app/modules/imports/components/import_process/import-process.service.ts index fa69769471..5913430092 100644 --- a/frontend/src/app/modules/imports/components/import_process/import-process.service.ts +++ b/frontend/src/app/modules/imports/components/import_process/import-process.service.ts @@ -98,4 +98,17 @@ export class ImportProcessService { this.importData = importData; this.navigateToStep(this.getLastAvailableStep()); } + + + checkImportDone(importData: Import): boolean { + return !!importData?.date_end_import; + } + + + get isImportCompleted(): boolean { + return this.importData ? this.checkImportDone(this.importData) : false; + } + + + } diff --git a/frontend/src/app/modules/imports/components/import_process/import-step/import-step.component.ts b/frontend/src/app/modules/imports/components/import_process/import-step/import-step.component.ts index 407994e677..d2cbde3ab3 100644 --- a/frontend/src/app/modules/imports/components/import_process/import-step/import-step.component.ts +++ b/frontend/src/app/modules/imports/components/import_process/import-step/import-step.component.ts @@ -199,7 +199,7 @@ export class ImportStepComponent implements OnInit { } checkBeforeNextStep(){ - if (!!this.importData?.date_end_import) { + if (this.importProcessService.isImportCompleted) { this.openModal(this.editModal); return; } diff --git a/frontend/src/app/modules/imports/components/import_process/upload-file-step/upload-file-step.component.ts b/frontend/src/app/modules/imports/components/import_process/upload-file-step/upload-file-step.component.ts index 45d944ca21..88578cf008 100644 --- a/frontend/src/app/modules/imports/components/import_process/upload-file-step/upload-file-step.component.ts +++ b/frontend/src/app/modules/imports/components/import_process/upload-file-step/upload-file-step.component.ts @@ -8,9 +8,6 @@ import { Step } from '../../../models/enums.model'; import { Destination, Import } from '../../../models/import.model'; import { ImportProcessService } from '../import-process.service'; import { ConfigService } from '@geonature/services/config.service'; -import { switchMap } from 'rxjs/operators'; -import { FieldMappingValues } from '@geonature/modules/imports/models/mapping.model'; -import { formatQueryParams } from '@geonature/modules/imports/utils/format-to-fieldsmapping'; import { NgbModal } from '@librairies/@ng-bootstrap/ng-bootstrap'; import { ModalData } from '@geonature/modules/imports/models/modal-data.model'; @@ -34,7 +31,6 @@ export class UploadFileStepComponent implements OnInit { public maxFileNameLength: number = 255; public acceptedExtensions: string = null; public destination: Destination = null; - public paramsFieldMapping: FieldMappingValues; public modalData:ModalData; constructor( 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 d36189cdb9..93668bbb6d 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 @@ -428,7 +428,7 @@
Périmètre géographique des données importées Afficher dans {{ this.importData.destination.label }} 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 0b0c937261..5517848185 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 @@ -118,7 +118,7 @@ export class ImportReportComponent implements OnInit { */ loadValidData(importData: Import | null) { if (importData) { - if (importData.date_end_import && importData.id_source) { + if (this.importProcessService.isImportCompleted && importData.id_source) { this._dataService.getBbox(importData.id_source).subscribe((data) => { this.validBbox = data; }); @@ -224,7 +224,7 @@ export class ImportReportComponent implements OnInit { if (this.importData?.task_progress === -1) { this.importStatus = 'EN ERREUR'; this.importStatusClass = 'inerror'; - } else if (this.importData?.date_end_import) { + } else if (this.importProcessService.isImportCompleted) { this.importStatus = 'TERMINE'; this.importStatusClass = 'importdone'; }