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/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..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
@@ -60,7 +62,6 @@
Attribut
[parentFormControl]="localForm.controls.attributes" keyLabel="attribut" (onChange)="attributesChanged($event)" - [multiple]="knowledges.length" />
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..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 @@ -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; }; @@ -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,29 @@ 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[0]]); + knowledgeControl.enable(); + knowledgeControl.setValue(this.knowledges[0]); + } else { + knowledgeControl.disable(); } } @@ -170,9 +187,17 @@ 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) { 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..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,12 +8,12 @@

Recherche hiérarchisation

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(); }