From b8b5c6b7740c59dee903ece081efb69556573ab8 Mon Sep 17 00:00:00 2001 From: Julien Corny Date: Tue, 10 Sep 2024 12:48:31 +0200 Subject: [PATCH 1/8] fix(backend): hierarchy filter herrors --- backend/gn_module_zh/search.py | 2 +- .../components/zh-hierarchy-search-table.component.html | 2 +- .../zh-hierarchy-search/zh-hierarchy-search.component.html | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/gn_module_zh/search.py b/backend/gn_module_zh/search.py index c111c761..076b0fd0 100644 --- a/backend/gn_module_zh/search.py +++ b/backend/gn_module_zh/search.py @@ -105,7 +105,7 @@ def main_search(query, json): # --- Hierarchy search hierarchy = json.get("hierarchy") if hierarchy is not None and basin is not None: - query = filter_hierarchy(query, json=hierarchy, basin=basin[0].get("name")) + query = filter_hierarchy(query, json=hierarchy, basin=basin["name"]) return query diff --git a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html index 1ffed925..e0f00478 100644 --- a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html +++ b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html @@ -60,7 +60,7 @@
Attribut
[parentFormControl]="localForm.controls.attributes" keyLabel="attribut" (onChange)="attributesChanged($event)" - [multiple]="knowledges.length" + [multiple]="attributes.length" />
diff --git a/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html b/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html index 59998786..d5f49519 100644 --- a/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html +++ b/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html @@ -8,12 +8,12 @@

Recherche hiérarchisation

From 6859fffa71c0d5b5eff1da883958adbecff0eb8b Mon Sep 17 00:00:00 2001 From: Julien Corny Date: Thu, 26 Sep 2024 11:52:46 +0200 Subject: [PATCH 2/8] fix: 'connaissance' values display in frontend table of hierarchy filters --- backend/gn_module_zh/hierarchy.py | 6 ++-- .../zh-hierarchy-search-table.component.ts | 30 ++++++++++++------- frontend/app/zh-search/zh-search.component.ts | 2 ++ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/backend/gn_module_zh/hierarchy.py b/backend/gn_module_zh/hierarchy.py index 70b670ed..3397895d 100644 --- a/backend/gn_module_zh/hierarchy.py +++ b/backend/gn_module_zh/hierarchy.py @@ -859,14 +859,14 @@ def __get_rule_name(self): try: return ( DB.session.execute( - select(TRules, BibHierCategories) + select(TRules, BibHierSubcategories) .join(TRules) .where(TRules.rule_id == self.rule_id) ) .all()[0] - .BibHierCategories.label.capitalize() + .BibHierSubcategories.label.capitalize() ) - except NoResultFound: + except: pass return ( DB.session.execute( diff --git a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts index 2121607f..c7f0d0f7 100644 --- a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts +++ b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts @@ -7,7 +7,7 @@ import { HierarchyField, HierarchyFields, Note, RiverBasin } from '../../models/ import { TableColumn } from '../../commonComponents/table/table-interface'; type Data = { - kownledges: string[]; + knowledges: string[]; field: string; attributes: string; }; @@ -62,7 +62,7 @@ export class ZhHierarchySearchTableComponent implements OnInit { private _zhService: ZhDataService, private _toastr: ToastrService, private _error: ErrorTranslatorService - ) {} + ) { } get data() { return this.form.controls['hierarchy'] as FormArray; @@ -87,7 +87,7 @@ export class ZhHierarchySearchTableComponent implements OnInit { this.fields = []; this.notes = []; }) - .finally(() => {}); + .finally(() => { }); } } @@ -119,7 +119,7 @@ export class ZhHierarchySearchTableComponent implements OnInit { (item.rubrique == event && item.sousrubrique == null) || item.sousrubrique == event ); - + // Creates kind of a Set to have unique objects this.attributes = filteredNotes.filter( (v, i, a) => a.findIndex((v2) => ['attribut'].every((k) => v2[k] === v[k])) === i @@ -130,12 +130,12 @@ export class ZhHierarchySearchTableComponent implements OnInit { if (this.attributes.length > 0) { this.knowledges = this.getKnowledge(this.attributes[0]); } - + if (this.attributes.length > 0) { - this.localForm.controls['attributes'].setValue([this.attributes[0]]); + this.localForm.controls["attributes"].setValue([this.attributes[0]]); } if (this.knowledges.length > 0) { - this.localForm.controls['knowledges'].setValue([this.knowledges[0]]); + this.localForm.controls["knowledges"].setValue([this.knowledges]); } } @@ -170,10 +170,18 @@ export class ZhHierarchySearchTableComponent implements OnInit { const form = this.initialForm(); form.patchValue(this.localForm.value); this.data.push(form); - // Reset all form data - this.reset(); - } - } + let knowledges_array = [] + this.data.value.forEach(element => { + if ((element['knowledges'] !== null) && (!(Array.isArray(element['knowledges'])))) { + // avoid object object in 'connaissance' column of the frontend table + knowledges_array.push(element['knowledges']); + element['knowledges'] = knowledges_array; + knowledges_array = [] + } + }) + } + this.reset(); + }; onDeleteFilter(event) { const item = this.getFilterIndex(event); diff --git a/frontend/app/zh-search/zh-search.component.ts b/frontend/app/zh-search/zh-search.component.ts index 1755708f..746d995c 100644 --- a/frontend/app/zh-search/zh-search.component.ts +++ b/frontend/app/zh-search/zh-search.component.ts @@ -95,6 +95,8 @@ export class ZhSearchComponent implements OnInit { onReset() { this._searchService.reset(); // Emit empty object to search all ZH + this.hierarchySearchToggled = false; + this.advancedSearchToggled = false; this.onSearch.emit(); } From 1a2899717655f0a925f7df77e3595efbca21653f Mon Sep 17 00:00:00 2001 From: Julien Corny Date: Thu, 26 Sep 2024 11:55:33 +0200 Subject: [PATCH 3/8] linter --- .../zh-hierarchy-search-table.component.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts index c7f0d0f7..e3a3b399 100644 --- a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts +++ b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts @@ -62,7 +62,7 @@ export class ZhHierarchySearchTableComponent implements OnInit { private _zhService: ZhDataService, private _toastr: ToastrService, private _error: ErrorTranslatorService - ) { } + ) {} get data() { return this.form.controls['hierarchy'] as FormArray; @@ -87,7 +87,7 @@ export class ZhHierarchySearchTableComponent implements OnInit { this.fields = []; this.notes = []; }) - .finally(() => { }); + .finally(() => {}); } } @@ -119,7 +119,7 @@ export class ZhHierarchySearchTableComponent implements OnInit { (item.rubrique == event && item.sousrubrique == null) || item.sousrubrique == event ); - + // Creates kind of a Set to have unique objects this.attributes = filteredNotes.filter( (v, i, a) => a.findIndex((v2) => ['attribut'].every((k) => v2[k] === v[k])) === i @@ -130,12 +130,12 @@ export class ZhHierarchySearchTableComponent implements OnInit { if (this.attributes.length > 0) { this.knowledges = this.getKnowledge(this.attributes[0]); } - + if (this.attributes.length > 0) { - this.localForm.controls["attributes"].setValue([this.attributes[0]]); + this.localForm.controls['attributes'].setValue([this.attributes[0]]); } if (this.knowledges.length > 0) { - this.localForm.controls["knowledges"].setValue([this.knowledges]); + this.localForm.controls['knowledges'].setValue([this.knowledges]); } } @@ -170,18 +170,18 @@ export class ZhHierarchySearchTableComponent implements OnInit { const form = this.initialForm(); form.patchValue(this.localForm.value); this.data.push(form); - let knowledges_array = [] - this.data.value.forEach(element => { - if ((element['knowledges'] !== null) && (!(Array.isArray(element['knowledges'])))) { + let knowledges_array = []; + this.data.value.forEach((element) => { + if (element['knowledges'] !== null && !Array.isArray(element['knowledges'])) { // avoid object object in 'connaissance' column of the frontend table knowledges_array.push(element['knowledges']); element['knowledges'] = knowledges_array; - knowledges_array = [] + knowledges_array = []; } - }) - } + }); + } this.reset(); - }; + } onDeleteFilter(event) { const item = this.getFilterIndex(event); From 3aa918ab63727d0d84afccda5d8f26da18971400 Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Fri, 27 Sep 2024 18:04:59 +0200 Subject: [PATCH 4/8] fix: less precise riverbasin existance check --- .../app/zh-hierarchy-search/zh-hierarchy-search.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html b/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html index d5f49519..7f27aed4 100644 --- a/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html +++ b/frontend/app/zh-hierarchy-search/zh-hierarchy-search.component.html @@ -8,7 +8,7 @@

Recherche hiérarchisation

Date: Fri, 27 Sep 2024 18:45:26 +0200 Subject: [PATCH 5/8] fix: remove weird multiple only if multiple value possible --- .../components/zh-hierarchy-search-table.component.html | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html index e0f00478..031e59a9 100644 --- a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html +++ b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html @@ -60,7 +60,6 @@
Attribut
[parentFormControl]="localForm.controls.attributes" keyLabel="attribut" (onChange)="attributesChanged($event)" - [multiple]="attributes.length" />
From 816492809d05b933dc1aa76e96d5e4db3bc02d5b Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Fri, 27 Sep 2024 18:45:38 +0200 Subject: [PATCH 6/8] fix: improve attributes / knowledge bahvior --- .../zh-hierarchy-search-table.component.ts | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts index e3a3b399..5b2128ee 100644 --- a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts +++ b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts @@ -87,7 +87,9 @@ export class ZhHierarchySearchTableComponent implements OnInit { this.fields = []; this.notes = []; }) - .finally(() => {}); + .finally(() => { + this.updateAttributesAndKnowledgeForm(); + }); } } @@ -110,9 +112,6 @@ export class ZhHierarchySearchTableComponent implements OnInit { } fieldChanged(event) { - this.localForm.controls['attributes'].reset(); - this.localForm.controls['knowledges'].reset(); - const filteredNotes = this.notes.filter( (item) => (item.volet == event && item.rubrique == null && item.sousrubrique == null) || @@ -131,11 +130,32 @@ export class ZhHierarchySearchTableComponent implements OnInit { this.knowledges = this.getKnowledge(this.attributes[0]); } - if (this.attributes.length > 0) { - this.localForm.controls['attributes'].setValue([this.attributes[0]]); + // Update the form + this.updateAttributesAndKnowledgeForm(); + } + + updateAttributesAndKnowledgeForm() { + const knowledgeControl = this.localForm.controls['knowledges']; + const attributesControl = this.localForm.controls['attributes']; + + attributesControl.reset(); + knowledgeControl.reset(); + + if (this.attributes.length) { + attributesControl.enable(); + attributesControl.setValue([this.attributes[0]]); + } + else { + attributesControl.disable(); } + + if (this.knowledges.length > 0) { - this.localForm.controls['knowledges'].setValue([this.knowledges]); + knowledgeControl.enable(); + knowledgeControl.setValue(this.knowledges[0]); + } + else { + knowledgeControl.disable(); } } From a8738248dadf65f52b3bb921a85bb0c48f7dd10a Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Mon, 30 Sep 2024 09:47:07 +0200 Subject: [PATCH 7/8] lint: zh hierarchy table --- .../components/zh-hierarchy-search-table.component.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts index 5b2128ee..60e3c53c 100644 --- a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts +++ b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.ts @@ -144,17 +144,14 @@ export class ZhHierarchySearchTableComponent implements OnInit { if (this.attributes.length) { attributesControl.enable(); attributesControl.setValue([this.attributes[0]]); - } - else { + } else { attributesControl.disable(); } - if (this.knowledges.length > 0) { knowledgeControl.enable(); knowledgeControl.setValue(this.knowledges[0]); - } - else { + } else { knowledgeControl.disable(); } } From 562b01b559d1510f2b1efdf4e482da92289ac605 Mon Sep 17 00:00:00 2001 From: Julien Corny Date: Thu, 12 Dec 2024 18:00:06 +0100 Subject: [PATCH 8/8] fix: disable cat not evaluted in filters --- .../components/zh-hierarchy-search-table.component.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html index 031e59a9..07ebd14c 100644 --- a/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html +++ b/frontend/app/zh-hierarchy-search/components/zh-hierarchy-search-table.component.html @@ -28,6 +28,7 @@
Rubrique
@@ -36,6 +37,7 @@
Rubrique