From c266e840b15c5345f7c7b54a91373867d2d695d0 Mon Sep 17 00:00:00 2001 From: Pierre Narcisi Date: Tue, 2 Apr 2024 16:56:00 +0200 Subject: [PATCH] Feat(areas) add param to remove geom from query --- backend/dependencies/RefGeo | 2 +- .../form/areas/areas.component.ts | 16 ++++++++++++---- .../GN2CommonModule/form/data-form.service.ts | 18 +++++++++--------- .../synthese-form/synthese-form.component.html | 1 + 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/backend/dependencies/RefGeo b/backend/dependencies/RefGeo index 01ae4f86ae..f0c09f46eb 160000 --- a/backend/dependencies/RefGeo +++ b/backend/dependencies/RefGeo @@ -1 +1 @@ -Subproject commit 01ae4f86ae2967941318cf067af366a3662419be +Subproject commit f0c09f46eb4598ad93b5635f5ce63e289a5df75c diff --git a/frontend/src/app/GN2CommonModule/form/areas/areas.component.ts b/frontend/src/app/GN2CommonModule/form/areas/areas.component.ts index 6dd1bee68b..1867ac5d34 100644 --- a/frontend/src/app/GN2CommonModule/form/areas/areas.component.ts +++ b/frontend/src/app/GN2CommonModule/form/areas/areas.component.ts @@ -51,6 +51,10 @@ export class AreasComponent extends GenericFormComponent implements OnInit { * `type_code` indiqués dans cet attribut. */ @Input() typeCodes: Array = []; // Areas type_code + /** + * Do not get the geom from the getArea call, for performances + */ + @Input() withoutGeom: Boolean = false; /** * Nom du champ à utiliser pour déterminer la valeur à utiliser pour le * contenu du `FormControl`. @@ -90,6 +94,7 @@ export class AreasComponent extends GenericFormComponent implements OnInit { areas_input$ = new Subject(); areas: Observable; loading = false; + params = {}; constructor(private dataService: DataFormService) { super(); @@ -97,6 +102,8 @@ export class AreasComponent extends GenericFormComponent implements OnInit { ngOnInit() { super.ngOnInit(); + this.params['type_code'] = this.typeCodes; + this.params['without_geom'] = this.withoutGeom; this.valueFieldName = this.valueFieldName === undefined ? 'id_area' : this.valueFieldName; this.getAreas(); @@ -105,9 +112,9 @@ export class AreasComponent extends GenericFormComponent implements OnInit { /** * Merge initial 100 areas + default values (for update) */ - initalAreas(): Observable { + initialAreas(): Observable { return zip( - this.dataService.getAreas(this.typeCodes).pipe(map((data) => this.formatAreas(data))), // Default items + this.dataService.getAreas(this.params).pipe(map((data) => this.formatAreas(data))), // Default items of(this.defaultItems) // Default items in update mode ).pipe( map((areasArrays) => { @@ -130,14 +137,15 @@ export class AreasComponent extends GenericFormComponent implements OnInit { getAreas() { this.areas = concat( - this.initalAreas(), + this.initialAreas(), this.areas_input$.pipe( debounceTime(200), distinctUntilChanged(), tap(() => (this.loading = true)), switchMap((term) => { + this.params['area_name'] = term; return term && term.length >= 2 - ? this.dataService.getAreas(this.typeCodes, term).pipe( + ? this.dataService.getAreas(this.params).pipe( map((data) => this.formatAreas(data)), catchError(() => of([])), // Empty list on error tap(() => (this.loading = false)) diff --git a/frontend/src/app/GN2CommonModule/form/data-form.service.ts b/frontend/src/app/GN2CommonModule/form/data-form.service.ts index af2bb8404e..4adeb7e89f 100644 --- a/frontend/src/app/GN2CommonModule/form/data-form.service.ts +++ b/frontend/src/app/GN2CommonModule/form/data-form.service.ts @@ -316,18 +316,18 @@ export class DataFormService { }); } - getAreas(area_type_list: Array, area_name?) { - let params: HttpParams = new HttpParams(); - - area_type_list.forEach((id_type) => { - params = params.append('type_code', id_type.toString()); - }); + getAreas(params: {}) { + let queryString: HttpParams = new HttpParams(); - if (area_name) { - params = params.set('area_name', area_name); + for (let key in params) { + let param = params[key]; + if (Array.isArray(param)) { + param = param.join(','); + } + queryString = queryString.set(key, param); } - return this._http.get(`${this.config.API_ENDPOINT}/geo/areas`, { params: params }); + return this._http.get(`${this.config.API_ENDPOINT}/geo/areas`, { params: queryString }); } getAreasTypes() { diff --git a/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.component.html b/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.component.html index ae7798e7b4..95ca05bef2 100644 --- a/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.component.html +++ b/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.component.html @@ -306,6 +306,7 @@

Champs avancé(s) sélectionné(s) :

[parentFormControl]="area.control" [label]="area.label" [typeCodes]="area.type_code_array" + [withoutGeom]="true" >