Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gestion des géométries (création/edition pour site et groupe de site) #68

Draft
wants to merge 27 commits into
base: dev-suivi-eolien
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6b0d947
feat(front): try to make breadcrumb work
May 4, 2023
c0336ef
feat(front): make breadcrumn logic inside component
andriacap May 15, 2023
21900b2
feat(wip): merge chainInput and display-data-info
andriacap May 26, 2023
f4ebd20
feat: remove unused function
andriacap May 30, 2023
849afd2
fix: put outside updateBreadCrumb in sitegp comp
andriacap May 30, 2023
0bde3ba
feat: remove onInit to mapListComponent
andriacap May 30, 2023
838db26
feat(wip): manage geometry type into form
andriacap May 30, 2023
18e312c
feat(wip) change way to manage map obj component
andriacap May 30, 2023
cf5d431
fix: rename obj Form and fix pb load confi obj
andriacap May 30, 2023
2ed2008
fix: remove unused edit site component
andriacap Jun 1, 2023
1429320
fix: loading config object site
andriacap Jun 1, 2023
5133540
fix: existing little problem
andriacap Jun 1, 2023
d4705e3
fix: problem to load specific site
andriacap Jun 1, 2023
8b630c7
feat(wip) : manage map
andriacap Jun 1, 2023
0d33303
fix: error on form with obj properties/config
andriacap Jun 1, 2023
82fb775
fix(css): height of form zone scrollable
andriacap Jun 1, 2023
a8bc1e2
fix: problem when delete site child
andriacap Jun 27, 2023
cb626ba
fix: problem adding site child by data-table comp
andriacap Jun 27, 2023
a856e4c
fix: problem redirection on delete site action
andriacap Jun 27, 2023
65303ae
fix: untracked gitlab-ci.yml
andriacap Jun 27, 2023
bb40d7a
fix: load specific properties obj
andriacap Jun 29, 2023
110d970
feat: page not found specific to monitoring
andriacap Jun 29, 2023
81df188
feat: not found working for request status 404
andriacap Jun 30, 2023
b5adc4d
fix: change format scc to css not-found comp
andriacap Jun 30, 2023
a6ed3dc
feat: display types_site label in table and prop
andriacap Jul 3, 2023
2a0969c
feat(api): return label of nomenclature type site
Jul 4, 2023
52f359e
style(config): types site attribut label
Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backend/gn_module_monitoring/monitoring/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ def serialize(self, depth):
geometry = None

monitoring_object_dict['geometry'] = geometry

if len(monitoring_object_dict['properties'].get('types_site', [])) != 0:
if hasattr(self._model, 'types_site'):
#TODO: performance?
types_site = [typ.nomenclature.label_fr for typ in self._model.types_site]
monitoring_object_dict['properties']['types_site'] = types_site
return monitoring_object_dict
2 changes: 2 additions & 0 deletions backend/gn_module_monitoring/monitoring/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MonitoringSite(MonitoringObjectGeom):
def preprocess_data(self, data):
if len(data["types_site"]) > 0 and all(isinstance(x, int) for x in data["types_site"]):
data["id_nomenclature_type_site"] = data["types_site"][0]
elif "data" in data and data["data"]["id_nomenclature_type_site"]:
data["id_nomenclature_type_site"] = data["data"]["id_nomenclature_type_site"]
else:
data["id_nomenclature_type_site"] = data["types_site"][0]["id_nomenclature_type_site"]
# TODO: A enlever une fois qu'on aura enelever le champ "id_nomenclature_type_site" du model et de la bdd
31 changes: 30 additions & 1 deletion backend/gn_module_monitoring/routes/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def create_or_update_object_api_sites_sites_group(module_code, object_type, id=N
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":
if object_type == "site" and not 'geometry' in post_data:
post_data["geometry"] = {"type": "Point", "coordinates": [2.5, 50]}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est pour tester le "coordinates": [2.5, 50] ?

post_data["type"] = "Feature"
# on rajoute id_module s'il n'est pas renseigné par défaut ??
Expand All @@ -144,6 +144,35 @@ def create_or_update_object_api_sites_sites_group(module_code, object_type, id=N
)


def get_config_object(module_code, object_type, id):
'''
renvoie un object, à partir de type de l'object et de son id

:param module_code: reference le module concerne
:param object_type: le type d'object (site, visit, obervation)
:param id : l'identifiant de l'object (de id_base_site pour site)
:type module_code: str
:type object_type: str
:type id: int

:return: renvoie l'object requis
:rtype: dict
'''

# field_name = param.get('field_name')
# value = module_code if object_type == 'module'
get_config(module_code, force=True)

depth = to_int(request.args.get('depth', 1))

return (
monitoring_definitions
.monitoring_object_instance(module_code, object_type, id)
.get(depth=depth)
# .get(value=value, field_name = field_name)
.serialize(depth)
)

# update object
@blueprint.route('object/<string:module_code>/<object_type>/<int:id>', methods=['PATCH'])
@blueprint.route(
Expand Down
15 changes: 11 additions & 4 deletions backend/gn_module_monitoring/routes/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
TNomenclatures,
)
from gn_module_monitoring.monitoring.schemas import BibTypeSiteSchema, MonitoringSitesSchema
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group, get_config_object
from gn_module_monitoring.utils.routes import (
filter_params,
geojson_query,
Expand All @@ -25,6 +25,14 @@
)


@blueprint.route("/sites/config",
defaults={'id': None, 'object_type': "site",'module_code':'generic'},
methods=["GET"])
def get_config_sites(module_code, object_type, id):
obj = get_config_object(module_code, object_type, id)
return obj['properties']


@blueprint.route("/sites/types", methods=["GET"])
def get_types_site():
params = MultiDict(request.args)
Expand Down Expand Up @@ -155,11 +163,10 @@ def post_sites():

@blueprint.route("/sites/<int:_id>", methods=["DELETE"])
def delete_site(_id):
item = TMonitoringSites.find_by_id(_id)
db.session.delete(item)
TMonitoringSites.query.filter_by(id_g=_id).delete()
db.session.commit()
return {
"success": f"Item with {item.id_g} from table {item.__tablename__} is successfully deleted"
"success": "Item is successfully deleted"
}, 200

@blueprint.route("/sites/<int:_id>", methods=["PATCH"])
Expand Down
12 changes: 10 additions & 2 deletions backend/gn_module_monitoring/routes/sites_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@
paginate,
sort,
)
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group, get_config_object
from gn_module_monitoring.utils.utils import to_int


@blueprint.route("/sites_groups/config",
defaults={'id': None, 'object_type': "sites_group",'module_code':'generic'},
methods=["GET"])
def get_config_sites_groups(module_code, object_type, id):
obj = get_config_object(module_code, object_type, id)
return obj['properties']


@blueprint.route("/sites_groups", methods=["GET"])
def get_sites_groups():
params = MultiDict(request.args)
Expand All @@ -44,7 +52,7 @@ def get_sites_groups():
@blueprint.route("/sites_groups/<int:id_sites_group>", methods=["GET"])
def get_sites_group_by_id(id_sites_group: int):
schema = MonitoringSitesGroupsSchema()
result = TMonitoringSitesGroups.find_by_id(id_sites_group)
result = TMonitoringSitesGroups.query.get_or_404(id_sites_group)
return jsonify(schema.dump(result))


Expand Down
8 changes: 5 additions & 3 deletions config/monitoring/generic/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
"last_visit",
"nb_visits",
"altitude_min",
"altitude_max"
"altitude_max",
"types_site"
],
"display_list": [
"base_site_name",
"base_site_code",
"id_nomenclature_type_site",
"last_visit",
"nb_visits"
"nb_visits",
"types_site"
],
"sorts": [
{"prop": "last_visit", "dir": "desc"}
Expand Down Expand Up @@ -95,7 +97,7 @@
},
"types_site": {
"type_widget": "datalist",
"attribut_label": "ID Type sites",
"attribut_label": "Type(s) de site",
"hidden": true,
"schema_dot_table": "gn_monitoring.t_base_sites"
}
Expand Down
60 changes: 40 additions & 20 deletions frontend/app/components/breadcrumbs/breadcrumbs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,48 @@ import { ConfigService } from "../../services/config.service";
import { MonitoringObject } from "../../class/monitoring-object";
import { Router } from "@angular/router";
import { ActivatedRoute } from "@angular/router";
import { ObjectService } from "../../services/object.service";
import { SiteSiteGroup } from "../../interfaces/objObs";
import { IBreadCrumb } from "../../interfaces/object";

export const breadCrumbElementBase: IBreadCrumb = {
"description":"Liste des groupes de site",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je rajouterai un "s" à site car un groupe est composé souvent de plusieurs sites. Ou alors un "(s)"

"label":"",
"url": "sites_group"
}

@Component({
selector: "pnx-monitoring-breadcrumbs",
templateUrl: "./breadcrumbs.component.html",
styleUrls: ["./breadcrumbs.component.css"],
})
export class BreadcrumbsComponent implements OnInit {
public breadcrumbs;

public breadcrumbs: IBreadCrumb[] =[];
@Input() bEdit: boolean;
@Output() bEditChange = new EventEmitter<boolean>();

public frontendModuleMonitoringUrl: string;

public newLabel: string;
public new_desc: string;
@Input() obj: MonitoringObject;
// Specific to the site access
siteSiteGroup: SiteSiteGroup | null = null;

constructor(
private _dataMonitoringObjectService: DataMonitoringObjectService,
private _configService: ConfigService,
private _router: Router,
private _route: ActivatedRoute
private _route: ActivatedRoute,
private _objectService: ObjectService
) {}

ngOnInit() {
// this.initBreadcrumbs();
if (this.obj === undefined) {
this._objectService.currentDataBreadCrumb.subscribe(
(breadCrumb) => (this.breadcrumbs = breadCrumb)
);
return;
}
}

initBreadcrumbs() {
Expand Down Expand Up @@ -76,22 +93,25 @@ export class BreadcrumbsComponent implements OnInit {
this.bEditChange.emit(false);
setTimeout(() => {
if (elem) {
this._router.navigate(
[
this._configService.frontendModuleMonitoringUrl(),
"object",
elem.module_code,
elem.object_type,
elem.id,
],
{
queryParams: elem.params,
}
);
if (this.obj == undefined) {
const url = [this._configService.frontendModuleMonitoringUrl(), elem.url].join('/');
this._router.navigateByUrl(url);
} else {
this._router.navigate(
[
this._configService.frontendModuleMonitoringUrl(),
'object',
elem.module_code,
elem.object_type,
elem.id,
],
{
queryParams: elem.params,
}
);
}
} else {
this._router.navigate([
this._configService.frontendModuleMonitoringUrl(),
]);
this._router.navigate([this._configService.frontendModuleMonitoringUrl()]);
}
}, 100);
}
Expand Down
18 changes: 15 additions & 3 deletions frontend/app/components/draw-form/draw-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
EventEmitter,
ViewEncapsulation,
} from "@angular/core";
import { FormControl, FormGroup } from "@angular/forms";
import { FormControl } from "@angular/forms";

import { leafletDrawOptions } from "./leaflet-draw.options";
import { CustomMarkerIcon } from "@geonature_common/map/marker/marker.component";
import { FormService } from "../../services/form.service";

@Component({
selector: "pnx-draw-form",
Expand Down Expand Up @@ -37,7 +38,7 @@ export class DrawFormComponent implements OnInit {

@Input() bEdit;

constructor() {}
constructor(private _formService: FormService) {}

ngOnInit() {
// choix du type de geometrie
Expand Down Expand Up @@ -105,7 +106,18 @@ export class DrawFormComponent implements OnInit {
// suivi composant => formControl
bindGeojsonForm(geojson) {
this.geojson = geojson;
this.parentFormControl.setValue(geojson.geometry);
if (!this.parentFormControl){
this._formService.currentFormMap.subscribe((dataForm) => {
if('geometry' in dataForm.frmGp.controls){
this.parentFormControl = dataForm.frmGp.controls['geometry'] as FormControl
this.parentFormControl.setValue(geojson.geometry);
}
})
}
else {
this.parentFormControl.setValue(geojson.geometry);
}

}

ngOnChanges(changes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ form.ng-invalid {

#form-scroll {
overflow-y: auto;
max-height: 70vh;
max-height: 60vh;
}

.btn-child {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<pnx-modal-msg [bDisplayModal]="bDeleteModal" *ngIf="obj && obj.bIsInitialized">
<h2>Attention</h2>
<p>
<p *ngIf="obj.config && obj.properties">
<!-- TODO: voir pour améliorer le passage d'informations ici -->
Vous êtes sur le point de supprimer le groupe de site
<b>Description du groupe de site</b>
Vous êtes sur le point de supprimer
{{obj.config["label"]}} : {{obj.properties[obj.config["description_field_name"]]}}
<br><b>(id :{{obj.properties[obj.config["id_field_name"]]}})</b>
</p>
<button class="btn btn-danger float-right" (click)="onDelete()">
<span
Expand All @@ -18,12 +19,12 @@ <h2>Attention</h2>
</pnx-modal-msg>

<div>
<div id="properties-form" class="cadre" *ngIf="!hideForm">
<div id="properties-form" class="cadre" *ngIf="!hideForm && obj.bIsInitialized && objFormsDefinition">
<!-- TODO: voir pour intiialisation si nécessaire à remettre dans la div du dessus -->
<!-- *ngIf="obj.bIsInitialized && objFormsDefinition" -->

<!-- TODO: Voir pour l'enchainement des saisies -->
<!-- <span
<span
*ngIf="!obj.id && obj.config['chained']"
id="toggle-btn"
class="float-right"
Expand All @@ -37,17 +38,17 @@ <h2>Attention</h2>
(change)="bChainInputChanged($event)"
>
</mat-slide-toggle>
</span> -->
</span>

<form [formGroup]="objForm">
<!-- TODO: Gérer la saisie de géometrie -->
<!-- <p
<p
class="alert alert-warning"
style="display:inline-block;"
*ngIf="obj.config['geometry_type'] && !objForm.value.geometry"
*ngIf="obj.config && obj.config['geometry_type'] && !objForm.value.geometry"
>
<span> Veuillez saisir une géométrie sur la carte </span>
</p> -->
</p>

<!-- composant choix de site select + filtre -->

Expand Down Expand Up @@ -94,14 +95,15 @@ <h2>Attention</h2>
aria-hidden="true"
></span>

<!-- <span *ngIf="bChainInput && !obj.id"
<span *ngIf="bChainInput && !obj.id"
>Valider et enchainer les saisies</span
> -->
<!-- <span *ngIf="!bChainInput || obj.id">Valider</span>
</button> -->
<span>Valider</span>
>
<span *ngIf="!bChainInput || obj.id">Valider</span>
</button>

<!-- <span>Valider</span>
</button> -->

<button class="btn btn-primary float-left" (click)="onCancelEdit()">Annuler</button>
<button class="btn btn-danger float-left" (click)="bDeleteModal = true" *ngIf="obj.id">
Supprimer
Expand Down
Loading