diff --git a/backend/gn_module_monitoring/conf_schema_toml.py b/backend/gn_module_monitoring/conf_schema_toml.py index 7c9f50257..e7eae5244 100644 --- a/backend/gn_module_monitoring/conf_schema_toml.py +++ b/backend/gn_module_monitoring/conf_schema_toml.py @@ -19,9 +19,9 @@ class GnModuleSchemaConf(Schema): - DESCRIPTION_MODULE = fields.String(default="Vous trouverez ici la liste des modules") - TITLE_MODULE = fields.String(default="Module de suivi") - CODE_OBSERVERS_LIST = fields.String(default="obsocctax") + DESCRIPTION_MODULE = fields.String(load_default="Vous trouverez ici la liste des modules") + TITLE_MODULE = fields.String(load_default="Module de suivi") + CODE_OBSERVERS_LIST = fields.String(load_default="obsocctax") PERMISSION_LEVEL = fields.Dict( keys=fields.Str(), values=fields.Str(), load_default=PERMISSION_LEVEL_DEFAULT diff --git a/backend/gn_module_monitoring/config/generic/observation.json b/backend/gn_module_monitoring/config/generic/observation.json index 5788fd4a9..c15997d73 100644 --- a/backend/gn_module_monitoring/config/generic/observation.json +++ b/backend/gn_module_monitoring/config/generic/observation.json @@ -17,6 +17,13 @@ "attribut_label": "Id visite", "hidden": true }, + "id_digitiser": { + "type_widget": "text", + "attribut_label": "Numérisateur", + "required": true, + "hidden": true, + "type_util": "user" + }, "cd_nom": { "type_widget": "taxonomy", "attribut_label": "Espèce", diff --git a/backend/gn_module_monitoring/config/repositories.py b/backend/gn_module_monitoring/config/repositories.py index f54fc2a92..a35fed59f 100644 --- a/backend/gn_module_monitoring/config/repositories.py +++ b/backend/gn_module_monitoring/config/repositories.py @@ -123,6 +123,20 @@ def config_object_from_files(module_code, object_type, custom=None, is_sites_gro return config_object +def get_config_with_specific(module_code=None, force=False, complements=None): + """ + recupere la configuration pour le module monitoring + en prenant en compte les propriétés spécifiques des types de sites + """ + customConfig = {"specific": {}} + for keys in complements.keys(): + if "config" in complements[keys]: + customConfig["specific"].update( + (complements[keys].get("config", {}) or {}).get("specific", {}) + ) + get_config(module_code, force=True, customSpecConfig=customConfig) + + def get_config(module_code=None, force=False, customSpecConfig=None): """ recupere la configuration pour le module monitoring @@ -131,7 +145,6 @@ def get_config(module_code=None, force=False, customSpecConfig=None): et si aucun fichier du dossier de configuration n'a été modifié depuis le dernier appel de cette fonction alors la configuration est récupéré depuis current_app.config sinon la config est recupérée depuis les fichiers du dossier de configuration et stockée dans current_app.config - """ module_code = module_code if module_code else "generic" diff --git a/backend/gn_module_monitoring/migrations/362cf9d504ec_create_monitoring_schema.py b/backend/gn_module_monitoring/migrations/362cf9d504ec_create_monitoring_schema.py index 73f1332e8..6a0488c5e 100644 --- a/backend/gn_module_monitoring/migrations/362cf9d504ec_create_monitoring_schema.py +++ b/backend/gn_module_monitoring/migrations/362cf9d504ec_create_monitoring_schema.py @@ -33,13 +33,13 @@ def upgrade(): def downgrade(): - op.drop_table("t_module_complements", monitorings_schema) - op.drop_table("t_observation_complements", monitorings_schema) - op.drop_table("t_observation_details", monitorings_schema) - op.drop_table("t_observations", monitorings_schema) - op.drop_table("t_site_complements", monitorings_schema) - op.drop_table("t_sites_groups", monitorings_schema) - op.drop_table("t_visit_complements", monitorings_schema) + op.drop_table("t_module_complements", schema=monitorings_schema) + op.drop_table("t_observation_complements", schema=monitorings_schema) + op.drop_table("t_observation_details", schema=monitorings_schema) + op.drop_table("t_observations", schema=monitorings_schema) + op.drop_table("t_site_complements", schema=monitorings_schema) + op.drop_table("t_sites_groups", schema=monitorings_schema) + op.drop_table("t_visit_complements", schema=monitorings_schema) # Remove all GNM related objects statement = sa.delete(TObjects).where(TObjects.code_object.like("GNM_%")) diff --git a/backend/gn_module_monitoring/migrations/a5dce2633e4c_add_id_digitiser_to_t_observations.py b/backend/gn_module_monitoring/migrations/a5dce2633e4c_add_id_digitiser_to_t_observations.py index b576d0568..2ffdd8643 100644 --- a/backend/gn_module_monitoring/migrations/a5dce2633e4c_add_id_digitiser_to_t_observations.py +++ b/backend/gn_module_monitoring/migrations/a5dce2633e4c_add_id_digitiser_to_t_observations.py @@ -59,7 +59,7 @@ def upgrade(): def downgrade(): statement = sa.text( f""" - ALTER TABLE {monitorings_schema}.{table} DROP CONSTRAINT fk_t_sites_groups_id_digitiser; + ALTER TABLE {monitorings_schema}.{table} DROP CONSTRAINT fk_{table}_{column}; """ ) op.execute(statement) diff --git a/backend/gn_module_monitoring/migrations/fc90d31c677f_declare_available_permissions.py b/backend/gn_module_monitoring/migrations/fc90d31c677f_declare_available_permissions.py index 5da908d4b..eb42ddf0e 100644 --- a/backend/gn_module_monitoring/migrations/fc90d31c677f_declare_available_permissions.py +++ b/backend/gn_module_monitoring/migrations/fc90d31c677f_declare_available_permissions.py @@ -123,3 +123,12 @@ def downgrade(): module_code = 'MONITORINGS' """ ) + + op.execute( + """ + DELETE FROM + gn_permissions.t_objects + WHERE code_object = 'TYPES_SITES' + ; + """ + ) diff --git a/backend/gn_module_monitoring/routes/monitoring.py b/backend/gn_module_monitoring/routes/monitoring.py index 3c4f2d97c..2371991d2 100644 --- a/backend/gn_module_monitoring/routes/monitoring.py +++ b/backend/gn_module_monitoring/routes/monitoring.py @@ -30,7 +30,7 @@ from ..monitoring.definitions import monitoring_definitions from ..modules.repositories import get_module from ..utils.utils import to_int -from ..config.repositories import get_config +from ..config.repositories import get_config, get_config_with_specific from gn_module_monitoring.utils.routes import ( query_all_types_site_from_site_id, ) @@ -118,7 +118,7 @@ def get_monitoring_object_api(scope, module_code=None, object_type="module", id= ] customConfig = {"specific": {}} for specific_config in list_types_sites_dict: - customConfig["specific"].update(specific_config["specific"]) + customConfig["specific"].update((specific_config or {}).get("specific", {})) get_config(module_code, force=True, customSpecConfig=customConfig) else: @@ -183,14 +183,12 @@ def create_or_update_object_api_sites_sites_group(module_code, object_type, id=N # recupération des données post post_data = dict(request.get_json()) + if module_code != "generic": module = get_module("module_code", module_code) else: module = {"id_module": "generic"} - # TODO : A enlever une fois que le post_data contiendra geometry et type depuis le front - if object_type == "site" and not "geometry" in post_data: - post_data["geometry"] = {"type": "Point", "coordinates": [2.5, 50]} - post_data["type"] = "Feature" + # on rajoute id_module s'il n'est pas renseigné par défaut ?? if "id_module" not in post_data["properties"]: module["id_module"] = "generic" @@ -254,15 +252,9 @@ def update_object_api(scope, module_code, object_type, id): if not object._model.has_instance_permission(scope=scope): raise Forbidden(f"User {g.current_user} cannot update {object_type} {object._id}") - customConfig = {"specific": {}} post_data = dict(request.get_json()) if "dataComplement" in post_data: - for keys in post_data["dataComplement"].keys(): - if "config" in post_data["dataComplement"][keys]: - customConfig["specific"].update( - post_data["dataComplement"][keys]["config"]["specific"] - ) - get_config(module_code, force=True, customSpecConfig=customConfig) + get_config_with_specific(module_code, force=True, complements=post_data["dataComplement"]) else: get_config(module_code, force=True) return create_or_update_object_api(module_code, object_type, id) @@ -280,15 +272,9 @@ def update_object_api(scope, module_code, object_type, id): @check_cruved_scope("C") @json_resp def create_object_api(module_code, object_type, id): - customConfig = {"specific": {}} post_data = dict(request.get_json()) if "dataComplement" in post_data: - for keys in post_data["dataComplement"].keys(): - if "config" in post_data["dataComplement"][keys]: - customConfig["specific"].update( - post_data["dataComplement"][keys]["config"]["specific"] - ) - get_config(module_code, force=True, customSpecConfig=customConfig) + get_config_with_specific(module_code, force=True, complements=post_data["dataComplement"]) else: get_config(module_code, force=True) return create_or_update_object_api(module_code, object_type, id) diff --git a/backend/gn_module_monitoring/routes/site.py b/backend/gn_module_monitoring/routes/site.py index b37032cc7..baf3b3355 100644 --- a/backend/gn_module_monitoring/routes/site.py +++ b/backend/gn_module_monitoring/routes/site.py @@ -12,7 +12,7 @@ from geonature.core.gn_permissions import decorators as permissions from pypnusershub.db.models import User from gn_module_monitoring.blueprint import blueprint -from gn_module_monitoring.config.repositories import get_config +from gn_module_monitoring.config.repositories import get_config, get_config_with_specific from gn_module_monitoring.monitoring.models import ( BibTypeSite, TMonitoringModules, @@ -212,14 +212,10 @@ def get_module_sites(module_code: str): def post_sites(object_type): module_code = "generic" object_type = "site" - customConfig = {"specific": {}} post_data = dict(request.get_json()) - for keys in post_data["dataComplement"].keys(): - if "config" in post_data["dataComplement"][keys]: - customConfig["specific"].update( - post_data["dataComplement"][keys]["config"]["specific"] - ) - get_config(module_code, force=True, customSpecConfig=customConfig) + + get_config_with_specific(module_code, force=True, complements=post_data["dataComplement"]) + return create_or_update_object_api_sites_sites_group(module_code, object_type), 201 @@ -245,15 +241,8 @@ def patch_sites(scope, _id, object_type): if not site.has_instance_permission(scope=scope): raise Forbidden(f"User {g.current_user} cannot update site {site.id_base_site}") module_code = "generic" - customConfig = {"specific": {}} post_data = dict(request.get_json()) - # TODO: vérifier si utile et si oui mettre dans route POST - if "geometry" in post_data: - post_data["geometry"] = json.dumps(post_data["geometry"]) - for keys in post_data["dataComplement"].keys(): - if "config" in post_data["dataComplement"][keys]: - customConfig["specific"].update( - post_data["dataComplement"][keys]["config"]["specific"] - ) - get_config(module_code, force=True, customSpecConfig=customConfig) + + get_config_with_specific(module_code, force=True, complements=post_data["dataComplement"]) + return create_or_update_object_api_sites_sites_group(module_code, object_type, _id), 201 diff --git a/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts b/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts index b1f79b376..f34d53122 100644 --- a/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts +++ b/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts @@ -72,7 +72,7 @@ export class MonitoringDatatableComponent implements OnInit { initPermission() { // TODO: Attention ici l'ajout avec l'icon ne se fait que sur un enfant (si plusieurs enfants au même niveau , le premier sera pris pour le moment) const childrenType = this.child0.config.children_types[0]; - this.canCreateChild = this.currentUser?.moduleCruved[childrenType]['C']; + this.canCreateChild = !!childrenType && this.currentUser?.moduleCruved[childrenType]['C']; this.canDeleteObj = !['site', 'sites_group'].includes(this.child0.objectType); } diff --git a/frontend/app/components/monitoring-form/monitoring-form.component.ts b/frontend/app/components/monitoring-form/monitoring-form.component.ts index a5a310410..1339292c3 100644 --- a/frontend/app/components/monitoring-form/monitoring-form.component.ts +++ b/frontend/app/components/monitoring-form/monitoring-form.component.ts @@ -467,10 +467,12 @@ export class MonitoringFormComponent implements OnInit { for (const typeSite of typeSiteObj) { this.idsTypesSite.push(typeSite.id_nomenclature_type_site); this.typesSiteConfig[typeSite.label] = typeSite; - keysConfigToExclude.push( - ...Object.keys(this.typesSiteConfig[typeSite.label].config.specific) - ); - Object.assign(this.schemaUpdate, this.typesSiteConfig[typeSite.label].config.specific); + if (this.typesSiteConfig[typeSite.label].config?.specific) { + keysConfigToExclude.push( + ...Object.keys(this.typesSiteConfig[typeSite.label].config.specific) + ); + Object.assign(this.schemaUpdate, this.typesSiteConfig[typeSite.label].config.specific); + } } if (!this.obj.id) { this.schemaUpdate = keysConfigToExclude diff --git a/frontend/app/components/monitoring-map-list/monitoring-map-list.component.html b/frontend/app/components/monitoring-map-list/monitoring-map-list.component.html index 0c8e0ec5a..6cf25a5ed 100644 --- a/frontend/app/components/monitoring-map-list/monitoring-map-list.component.html +++ b/frontend/app/components/monitoring-map-list/monitoring-map-list.component.html @@ -1,7 +1,9 @@ -
-
+
- +
-
-
-
-
- - - -
+
+ + +
-
+ diff --git a/frontend/app/components/monitoring-map-list/monitoring-map-list.component.ts b/frontend/app/components/monitoring-map-list/monitoring-map-list.component.ts index a64919a8d..8a369c965 100644 --- a/frontend/app/components/monitoring-map-list/monitoring-map-list.component.ts +++ b/frontend/app/components/monitoring-map-list/monitoring-map-list.component.ts @@ -6,7 +6,9 @@ import { FormService } from '../../services/form.service'; import { ApiGeomService } from '../../services/api-geom.service'; import { ConfigJsonService } from '../../services/config-json.service'; import { ObjectService } from '../../services/object.service'; +import { CommonService } from '@geonature_common/service/common.service'; import { FormGroup } from '@angular/forms'; + @Component({ selector: 'monitoring-map-list.component', templateUrl: './monitoring-map-list.component.html', @@ -17,11 +19,26 @@ export class MonitoringMapListComponent { obj: any; bEdit: boolean; objForm: FormGroup; + heightMap: string="80vh"; // displayMap: boolean = true; siteSiteGroup: SiteSiteGroup | null = null; apiService: ApiGeomService; - constructor(private _formService: FormService) {} + + constructor( + private _formService: FormService, + private _commonService: CommonService + ) {} + + ngAfterViewInit() { + const container = document.getElementById('object'); + const height = this._commonService.calcCardContentHeight(); + container.style.height = height - 40 + 'px'; + setTimeout(() => { + this.heightMap = height - 80 + 'px'; + }); + + } onActivate(component) { this._formService.currentFormMap diff --git a/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.html b/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.html index fa0ca2450..4a5ab7915 100644 --- a/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.html +++ b/frontend/app/components/monitoring-properties-g/monitoring-properties-g.component.html @@ -42,7 +42,7 @@
- +