Skip to content

Commit

Permalink
Merge pull request #265 from PnX-SI/dev-suivi-eolien-rebased-debug
Browse files Browse the repository at this point in the history
Dev suivi eolien rebased debug
  • Loading branch information
amandine-sahl authored Dec 8, 2023
2 parents c710880 + 4147be4 commit 2ed9184
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 75 deletions.
6 changes: 3 additions & 3 deletions backend/gn_module_monitoring/conf_schema_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions backend/gn_module_monitoring/config/generic/observation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion backend/gn_module_monitoring/config/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_%"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,12 @@ def downgrade():
module_code = 'MONITORINGS'
"""
)

op.execute(
"""
DELETE FROM
gn_permissions.t_objects
WHERE code_object = 'TYPES_SITES'
;
"""
)
26 changes: 6 additions & 20 deletions backend/gn_module_monitoring/routes/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 7 additions & 18 deletions backend/gn_module_monitoring/routes/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="row">
<div class="col-6">
<div class="flex-container" id="object">
<div id="geometry" class="monitoring-map-container" class="cadre" *ngIf="displayMap">
<pnx-map height="80vh" [ngClass]="{ 'hide-draw-form': !(bEdit && obj) }">
<pnx-map
*ngIf="heightMap"
[height]="heightMap"
[ngClass]="{ 'hide-draw-form': !(bEdit && obj) }">
<pnx-draw-form
[parentFormControl]="objForm && objForm.controls && objForm.controls['geometry']"
[geometryType]="obj && obj.config && obj.config['geometry_type']"
Expand All @@ -11,14 +13,10 @@
></pnx-draw-form>
</pnx-map>
</div>
</div>
<div [ngClass]="displayMap ? 'col-6' : 'col-12'">
<div class="mr-3">
<div id="monitoring-elem-container" class="cadre scroll">
<pnx-monitoring-breadcrumbs></pnx-monitoring-breadcrumbs>
<!-- <button (click)="displayMap = !displayMap">HIDE MAP</button> -->
<router-outlet (activate)="onActivate($event)"></router-outlet>
</div>
<div id="monitoring-elem-container" class="cadre scroll">
<pnx-monitoring-breadcrumbs></pnx-monitoring-breadcrumbs>
<!-- <button (click)="displayMap = !displayMap">HIDE MAP</button> -->
<router-outlet (activate)="onActivate($event)"></router-outlet>
</div>
</div>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
</mat-tab>
<!-- TODO: tester l'ajout de médias et voir le comportement de obj.properties -->
<!-- <mat-tab
<mat-tab
*ngIf="obj.properties['medias'] && obj.properties['medias'].length"
label="Médias ({{(obj.properties['medias'] && obj.properties['medias'].length) || 0}})"
>
Expand All @@ -68,7 +68,7 @@
</div>
</div>
</ng-container>
</mat-tab> -->
</mat-tab>
</mat-tab-group>

<div class="tab-content" id="nav-tabContent" [ngStyle]="{ 'background-color': color }">
Expand Down Expand Up @@ -174,11 +174,11 @@
role="status"
aria-hidden="true"
></span>
Mettre à jour la synthèse
<mat-icon>sync</mat-icon>
</button>
<button
mat-stroked-button
*ngIf="obj.template['export_csv']"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class MonitoringVisitsComponent extends MonitoringGeomComponent implement
let schemaTypeMerged = {};
let keyHtmlToPop = '';
for (let type_site of this.types_site) {
if ('specific' in type_site['config']) {
if ('specific' in (type_site['config'] || {})) {
for (const prop in type_site['config']['specific']) {
if (
'type_widget' in type_site['config']['specific'][prop] &&
Expand Down
3 changes: 1 addition & 2 deletions frontend/app/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ export class ConfigService {
let schemaSpecificType = {};
let schemaTypeMerged = {};
let keyHtmlToPop = '';
console.log(types_site);
for (let type_site of types_site) {
if ('specific' in type_site['config']) {
if (type_site['config'] && 'specific' in type_site['config']) {
for (const prop in type_site['config']['specific']) {
if (
'type_widget' in type_site['config']['specific'][prop] &&
Expand Down

0 comments on commit 2ed9184

Please sign in to comment.