From 64ef6d223a5f88a437649c244aea5a835d88890a Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Tue, 17 Dec 2024 16:02:10 +0100 Subject: [PATCH] feat: add dataset destination management in fieldmapping service + migration --- ...7ac1_monitorings_adjust_gn_imports_bib_.py | 65 +++++++++++++++++++ .../mappings/field-mapping.service.ts | 4 ++ 2 files changed, 69 insertions(+) create mode 100644 backend/geonature/migrations/versions/imports/a43842db7ac1_monitorings_adjust_gn_imports_bib_.py diff --git a/backend/geonature/migrations/versions/imports/a43842db7ac1_monitorings_adjust_gn_imports_bib_.py b/backend/geonature/migrations/versions/imports/a43842db7ac1_monitorings_adjust_gn_imports_bib_.py new file mode 100644 index 0000000000..aaf82162a9 --- /dev/null +++ b/backend/geonature/migrations/versions/imports/a43842db7ac1_monitorings_adjust_gn_imports_bib_.py @@ -0,0 +1,65 @@ +"""[monitorings] Adjust gn.imports bib_fields id_dataset and unique_id_dataset values + +Revision ID: a43842db7ac1 +Revises: 2b0b3bd0248c +Create Date: 2024-12-17 11:18:07.806852 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'a43842db7ac1' +down_revision = '2b0b3bd0248c' +branch_labels = None +depends_on = None + +def upgrade(): + op.execute( + """ + UPDATE gn_imports.bib_fields + SET display = TRUE, + mandatory = TRUE, + optional_conditions = '{"unique_dataset_id"}', + type_field = 'dataset', + type_field_params = '{"bind_value": "id_dataset"}' + WHERE name_field = 'id_dataset' + """ + ) + op.execute( + """ + UPDATE gn_imports.bib_fields + SET display = TRUE, + mandatory = TRUE, + optional_conditions = '{"id_dataset"}', + type_field = 'dataset', + type_field_params = '{"bind_value": "unique_dataset_id"}' + WHERE name_field = 'unique_dataset_id' + """ + ) + + +def downgrade(): + op.execute( + """ + UPDATE gn_imports.bib_fields + SET display = FALSE, + mandatory = FALSE, + optional_conditions = NULL, + type_field = 'text', + type_field_params = NULL + WHERE name_field = 'id_dataset' + """ + ) + op.execute( + """ + UPDATE gn_imports.bib_fields + SET display = FALSE, + mandatory = FALSE, + optional_conditions = NULL, + type_field = 'text', + type_field_params = NULL + WHERE name_field = 'unique_dataset_id' + """ + ) diff --git a/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts b/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts index 3101ee6b86..8f6ad5cb75 100644 --- a/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts +++ b/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts @@ -513,6 +513,10 @@ export class FieldMappingService { type_widget: 'textarea', }; } + if(field.type_field == 'dataset'){ + const module_code = this._importProcessService.getImportData().destination?.module.module_code; + def.creatable_in_module = module_code, + } return { ...def,