diff --git a/backend/geonature/core/gn_synthese/models.py b/backend/geonature/core/gn_synthese/models.py index 15bf4f2ed2..0c360f083c 100644 --- a/backend/geonature/core/gn_synthese/models.py +++ b/backend/geonature/core/gn_synthese/models.py @@ -17,7 +17,7 @@ from pypn_habref_api.models import Habref from geonature.core.gn_meta.models import TDatasets, TAcquisitionFramework -from geonature.core.ref_geo.models import LAreas +from geonature.core.ref_geo.models import LAreas, CorAreaStatus from geonature.core.ref_geo.models import LiMunicipalities from geonature.core.gn_commons.models import THistoryActions, TValidations, TMedias from geonature.utils.env import DB @@ -350,12 +350,30 @@ class SyntheseOneRecord(VSyntheseDecodeNomenclatures): habitat = DB.relationship(Habref, lazy="joined") - source = DB.relationship(TSources) + source = DB.relationship( + "TSources", + primaryjoin=(TSources.id_source == id_source), + foreign_keys=[id_source], + ) + areas = DB.relationship( "LAreas", secondary=corAreaSynthese, ) - datasets = DB.relationship(TDatasets) + + areas_status = DB.relationship( + "CorAreaStatus", + secondary=corAreaSynthese, + primaryjoin=(CorAreaSynthese.id_synthese == id_synthese), + secondaryjoin=(CorAreaSynthese.id_area == CorAreaStatus.id_area), + ) + + datasets = DB.relationship( + "TDatasets", + primaryjoin=(TDatasets.id_dataset == id_dataset), + foreign_keys=[id_dataset], + ) + acquisition_framework = DB.relationship( "TAcquisitionFramework", uselist=False, diff --git a/backend/geonature/core/gn_synthese/routes.py b/backend/geonature/core/gn_synthese/routes.py index 2b0acda431..dc68edc904 100644 --- a/backend/geonature/core/gn_synthese/routes.py +++ b/backend/geonature/core/gn_synthese/routes.py @@ -266,48 +266,13 @@ def get_one_synthese(id_synthese): ) ) try: - data = q.one() geojson = data[0].as_geofeature( "the_geom_4326", "id_synthese", depth=2, - # fields=[ - # "unique_id_sinpsource", - # "areas", - # "areas.area_type", - # "datasets", - # "acquisition_framework", - # "cor_observers", - # "validations", - # "medias", - # "nat_obj_geo", - # "grp_typ", - # "obs_technique", - # "bio_status", - # "bio_condition", - # "naturalness", - # "exist_proof", - # "valid_status", - # "diffusion_level", - # "life_stage", - # "sex", - # "obj_count", - # "type_count", - # "sensitivity", - # "observation_status", - # "blurring", - # "source_status", - # "occ_behaviour", - # "occ_stat_biogeo" - # ] - ) + ) geojson["properties"]["actors"] = data[1] - # synthese_as_dict = data[0].as_dict( - # depth=2, - # ) - - # synthese_as_dict["actors"] = data[1] - # return jsonify(synthese_as_dict) + geojson["properties"]["areas_status"] = [d['cd_sig'] for d in synthese_as_dict["areas_status"]] return jsonify(geojson) except exc.NoResultFound: return None diff --git a/frontend/src/app/GN2CommonModule/form/data-form.service.ts b/frontend/src/app/GN2CommonModule/form/data-form.service.ts index 69d02b52df..cad7881e4f 100644 --- a/frontend/src/app/GN2CommonModule/form/data-form.service.ts +++ b/frontend/src/app/GN2CommonModule/form/data-form.service.ts @@ -143,8 +143,14 @@ export class DataFormService { }); } - getTaxonInfo(cd_nom: number) { - return this._http.get(`${AppConfig.API_TAXHUB}/taxref/${cd_nom}`); + getTaxonInfo(cd_nom: number, areasStatus?: Array) { + let query_string = new HttpParams(); + if (areasStatus) { + query_string = query_string.append('areas_status', areasStatus.join(',')); + } + return this._http.get(`${AppConfig.API_TAXHUB}/taxref/${cd_nom}`, { + params: query_string + }); } getTaxonAttributsAndMedia(cd_nom: number, id_attributs?: Array) { diff --git a/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.html b/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.html index e24b555d8f..f38a60e7ff 100644 --- a/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.html +++ b/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.html @@ -1,14 +1,7 @@ -
-
+
- - \ No newline at end of file + diff --git a/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.ts b/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.ts index e1b493bbfa..b44d693a0f 100644 --- a/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.ts +++ b/frontend/src/app/shared/syntheseSharedModule/synthese-info-obs/synthese-info-obs.component.ts @@ -131,7 +131,7 @@ export class SyntheseInfoObsComponent implements OnInit { ngOnInit() { this.loadAllInfo(this.idSynthese); console.log(this.CONFIG); - + } @@ -140,7 +140,7 @@ export class SyntheseInfoObsComponent implements OnInit { this.showValidation = true; setTimeout(() => { this._mapService.map.invalidateSize(); - }, 100); + }, 100); } @@ -190,16 +190,17 @@ export class SyntheseInfoObsComponent implements OnInit { }); this.loadValidationHistory(this.selectedObs['unique_id_sinp']); - this._gnDataService.getTaxonInfo(this.selectedObs['cd_nom']).subscribe(taxInfo => { + let cdNom = this.selectedObs['cd_nom']; + let areasStatus = this.selectedObs['areas_status']; + this._gnDataService.getTaxonInfo(cdNom, areasStatus).subscribe(taxInfo => { this.selectedObsTaxonDetail = taxInfo; if (this.selectedObs.cor_observers) { this.email = this.selectedObs.cor_observers.map(el => el.email).join(); this.mailto = this.formatMailContent(this.email); - } this._gnDataService.getProfile(taxInfo.cd_ref).subscribe(profile => { - + this.profile = profile; }); @@ -233,7 +234,7 @@ export class SyntheseInfoObsComponent implements OnInit { if (this.mailCustomSubject || this.mailCustomBody) { // Mise en forme des données - let d = { ...this.selectedObsTaxonDetail, ...this.selectedObs }; + let d = { ...this.selectedObsTaxonDetail, ...this.selectedObs }; if (this.selectedObs.source.url_source) { d['data_link'] = [ this.APP_CONFIG.URL_APPLICATION, @@ -244,13 +245,13 @@ export class SyntheseInfoObsComponent implements OnInit { else { d['data_link'] = ""; } - + d["communes"] = this.selectedObs.areas.filter( area => area.area_type.type_code == 'COM' ).map( area => area.area_name ).join(', '); - + let contentMedias = ""; if (!this.selectedObs.medias) { contentMedias = "Aucun media"; @@ -271,7 +272,7 @@ export class SyntheseInfoObsComponent implements OnInit { contentMedias += "\n"; }) } - d["medias"] = contentMedias; + d["medias"] = contentMedias; // Construction du mail if (this.mailCustomSubject !== undefined) { try { @@ -287,11 +288,10 @@ export class SyntheseInfoObsComponent implements OnInit { console.log('ERROR : unable to eval mail body'); } } - + mailto = encodeURI(mailto); mailto = mailto.replace(/,/g, '%2c'); } - return mailto; } @@ -387,4 +387,4 @@ export class SyntheseInfoObsComponent implements OnInit { backToModule(url_source, id_pk_source) { window.open(url_source + '/' + id_pk_source, '_blank'); } -} \ No newline at end of file +}