diff --git a/contrib/occtax/backend/occtax/blueprint.py b/contrib/occtax/backend/occtax/blueprint.py index 3e97744f9b..74a0d9e1ba 100644 --- a/contrib/occtax/backend/occtax/blueprint.py +++ b/contrib/occtax/backend/occtax/blueprint.py @@ -26,6 +26,7 @@ from geonature.utils.env import DB, db, ROOT_DIR from geonature.utils import filemanager +from geonature.utils.config import config from .models import ( TRelevesOccurrence, TOccurrencesOccurrence, @@ -65,6 +66,11 @@ def set_current_module(endpoint, values): g.current_module = TModules.query.filter_by(module_code=requested_module).first_or_404( f"No module name {requested_module}" ) + g.module_config = ( + config["OCCTAX"]["DEFAULT"] + if requested_module == "OCCTAX" + else config["OCCTAX"][requested_module] + ) @blueprint.route("//releves", methods=["GET"]) @@ -562,12 +568,12 @@ def export(scope): :query str format: format of the export ('csv', 'geojson', 'shapefile', 'gpkg') """ - export_view_name = blueprint.config["export_view_name"] - export_geom_column = blueprint.config["export_geom_columns_name"] - export_columns = blueprint.config["export_columns"] - export_srid = blueprint.config["export_srid"] + export_view_name = g.module_config["export_view_name"] + export_geom_column = g.module_config["export_geom_columns_name"] + export_columns = g.module_config["export_columns"] + export_srid = g.module_config["export_srid"] export_format = request.args["format"] if "format" in request.args else "geojson" - export_col_name_additional_data = blueprint.config["export_col_name_additional_data"] + export_col_name_additional_data = g.module_config["export_col_name_additional_data"] export_view = GenericTableGeo( tableName=export_view_name, @@ -589,10 +595,10 @@ def export(scope): export_view, q, from_generic_table=True, - obs_txt_column=blueprint.config["export_observer_txt_column"], + obs_txt_column=g.module_config["export_observer_txt_column"], ) - if current_app.config["OCCTAX"]["ADD_MEDIA_IN_EXPORT"]: + if g.module_config["ADD_MEDIA_IN_EXPORT"]: q, columns = releve_repository.add_media_in_export(q, columns) data = q.all() diff --git a/contrib/occtax/backend/occtax/conf_schema_toml.py b/contrib/occtax/backend/occtax/conf_schema_toml.py index 60fb82ff66..7e8f165ff0 100644 --- a/contrib/occtax/backend/occtax/conf_schema_toml.py +++ b/contrib/occtax/backend/occtax/conf_schema_toml.py @@ -204,13 +204,9 @@ class OcctaxSchemaConf(Schema): config_fields = OcctaxSchemaConf().fields -if len(submodules) > 0: - submodules.append("DEFAULT") - dict_nested = {} - for sub in submodules: - dict_nested[sub] = fields.Nested(config_fields, load_default=OcctaxSchemaConf().load({})) +submodules.append("DEFAULT") +dict_nested = {} +for sub in submodules: + dict_nested[sub] = fields.Nested(config_fields, load_default=OcctaxSchemaConf().load({})) - GnModuleSchemaConf = type("GnModuleSchemaConf", (Schema,), dict_nested) - -else: - GnModuleSchemaConf = type("GnModuleSchemaConf", (Schema,), config_fields) +GnModuleSchemaConf = type("GnModuleSchemaConf", (Schema,), dict_nested) diff --git a/contrib/occtax/frontend/app/occtax-form/counting/counting.component.html b/contrib/occtax/frontend/app/occtax-form/counting/counting.component.html index 4e59278cd2..5955625f68 100644 --- a/contrib/occtax/frontend/app/occtax-form/counting/counting.component.html +++ b/contrib/occtax/frontend/app/occtax-form/counting/counting.component.html @@ -1,6 +1,6 @@
{{ 'Counting.NumberMin' | translate }} @@ -52,7 +52,7 @@
{{ 'Counting.NumberMax' | translate }} @@ -74,7 +74,7 @@
@@ -143,7 +143,7 @@
[parentFormControl]="form.controls.medias" [sizeMax]="config.MEDIAS.MEDIAS_SIZE_MAX" [default]="defaultsMedia()" - [details]="config.OCCTAX.MEDIA_FIELDS_DETAILS" + [details]="moduleConfig.MEDIA_FIELDS_DETAILS" [disabled]="!taxref" disabledTxt="Veuillez choisir un taxon avant de renseigner les médias" > diff --git a/contrib/occtax/frontend/app/occtax-form/counting/counting.component.ts b/contrib/occtax/frontend/app/occtax-form/counting/counting.component.ts index 40e90f6aa0..578325ee05 100644 --- a/contrib/occtax/frontend/app/occtax-form/counting/counting.component.ts +++ b/contrib/occtax/frontend/app/occtax-form/counting/counting.component.ts @@ -1,23 +1,31 @@ -import { Component, OnInit, Input, OnDestroy, Output, EventEmitter } from '@angular/core'; -import { UntypedFormGroup, UntypedFormArray } from '@angular/forms'; -import { Subscription } from 'rxjs'; -import { filter } from 'rxjs/operators'; +import { + Component, + OnInit, + Input, + OnDestroy, + Output, + EventEmitter, +} from "@angular/core"; +import { UntypedFormGroup, UntypedFormArray } from "@angular/forms"; +import { Subscription } from "rxjs"; +import { filter } from "rxjs/operators"; -import { OcctaxFormService } from '../occtax-form.service'; -import { OcctaxFormOccurrenceService } from '../occurrence/occurrence.service'; -import { OcctaxFormCountingService } from './counting.service'; -import { ConfigService } from '@geonature/services/config.service'; +import { OcctaxFormService } from "../occtax-form.service"; +import { OcctaxFormOccurrenceService } from "../occurrence/occurrence.service"; +import { OcctaxFormCountingService } from "./counting.service"; +import { ConfigService } from "@geonature/services/config.service"; +import { OcctaxDataService } from "../../services/occtax-data.service"; @Component({ - selector: 'pnx-occtax-form-counting', - templateUrl: './counting.component.html', - styleUrls: ['./counting.component.scss'], + selector: "pnx-occtax-form-counting", + templateUrl: "./counting.component.html", + styleUrls: ["./counting.component.scss"], providers: [OcctaxFormCountingService], }) export class OcctaxFormCountingComponent implements OnInit, OnDestroy { public data: any; - @Input('value') + @Input("value") set counting(value: any) { this.occtaxFormCountingService.counting.next(value); } @@ -25,6 +33,7 @@ export class OcctaxFormCountingComponent implements OnInit, OnDestroy { @Output() lifeStageChange = new EventEmitter(); form: UntypedFormGroup; + public moduleConfig; get additionalFieldsForm(): any[] { return this.occtaxFormCountingService.additionalFieldsForm; } @@ -33,27 +42,37 @@ export class OcctaxFormCountingComponent implements OnInit, OnDestroy { public occtaxFormService: OcctaxFormService, public occtaxFormOccurrenceService: OcctaxFormOccurrenceService, private occtaxFormCountingService: OcctaxFormCountingService, - public config: ConfigService + public config: ConfigService, + private _ds: OcctaxDataService, ) {} ngOnInit() { + this.moduleConfig = this._ds.moduleConfig; this.form = this.occtaxFormCountingService.form; this.sub = this.form - .get('id_nomenclature_life_stage') - .valueChanges.pipe(filter((idNomenclatureLifeStage) => idNomenclatureLifeStage !== null)) + .get("id_nomenclature_life_stage") + .valueChanges.pipe( + filter((idNomenclatureLifeStage) => idNomenclatureLifeStage !== null), + ) .subscribe((idNomenclatureLifeStage) => { - this.occtaxFormOccurrenceService.lifeStage.next(idNomenclatureLifeStage); + this.occtaxFormOccurrenceService.lifeStage.next( + idNomenclatureLifeStage, + ); }); } ngOnDestroy() { //delete elem from form.get('cor_counting_occtax') const idx = ( - this.occtaxFormOccurrenceService.form.get('cor_counting_occtax') as UntypedFormArray + this.occtaxFormOccurrenceService.form.get( + "cor_counting_occtax", + ) as UntypedFormArray ).controls.findIndex((elem) => elem === this.form); if (idx !== -1) { ( - this.occtaxFormOccurrenceService.form.get('cor_counting_occtax') as UntypedFormArray + this.occtaxFormOccurrenceService.form.get( + "cor_counting_occtax", + ) as UntypedFormArray ).removeAt(idx); } } @@ -73,20 +92,26 @@ export class OcctaxFormCountingComponent implements OnInit, OnDestroy { }; } - const observers = (occtaxData && occtaxData.releve.properties.observers) || []; - const author = observers.map((o) => o.nom_complet).join(', '); + const observers = + (occtaxData && occtaxData.releve.properties.observers) || []; + const author = observers.map((o) => o.nom_complet).join(", "); - const date_min = (occtaxData && occtaxData.releve.properties.date_min) || null; + const date_min = + (occtaxData && occtaxData.releve.properties.date_min) || null; - const cd_nom = String(taxref && taxref.cd_nom) || ''; - const lb_nom = (taxref && `${taxref.lb_nom}`) || ''; - const date_txt = date_min ? `${date_min.year}_${date_min.month}_${date_min.day}` : ''; - const date_txt2 = date_min ? `${date_min.day}/${date_min.month}/${date_min.year}` : ''; + const cd_nom = String(taxref && taxref.cd_nom) || ""; + const lb_nom = (taxref && `${taxref.lb_nom}`) || ""; + const date_txt = date_min + ? `${date_min.year}_${date_min.month}_${date_min.day}` + : ""; + const date_txt2 = date_min + ? `${date_min.day}/${date_min.month}/${date_min.year}` + : ""; return { displayDetails: false, author: author, - title_fr: `${date_txt}_${lb_nom.replace(' ', '_')}_${cd_nom}`, + title_fr: `${date_txt}_${lb_nom.replace(" ", "_")}_${cd_nom}`, description_fr: `${lb_nom} observé le ${date_txt2}`, }; } diff --git a/contrib/occtax/frontend/app/occtax-form/form-param/form-param.dialog.html b/contrib/occtax/frontend/app/occtax-form/form-param/form-param.dialog.html index 010e0a5434..193ffb346c 100644 --- a/contrib/occtax/frontend/app/occtax-form/form-param/form-param.dialog.html +++ b/contrib/occtax/frontend/app/occtax-form/form-param/form-param.dialog.html @@ -120,7 +120,7 @@