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

Fix/hierarchy filter no rb #91

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 3 deletions backend/gn_module_zh/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion backend/gn_module_zh/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ <h5>Attribut</h5>
[parentFormControl]="localForm.controls.attributes"
keyLabel="attribut"
(onChange)="attributesChanged($event)"
[multiple]="knowledges.length"
/>
</div>
<div class="pr-0 col-lg-3 col-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -87,7 +87,9 @@ export class ZhHierarchySearchTableComponent implements OnInit {
this.fields = [];
this.notes = [];
})
.finally(() => {});
.finally(() => {
this.updateAttributesAndKnowledgeForm();
});
}
}

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

Expand Down Expand Up @@ -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 = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

c'est assez bizarre ça.

}
});
}
this.reset();
}

onDeleteFilter(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ <h4>Recherche hiérarchisation</h4>
<div class="card-body">
<div
class="row"
*ngIf="riverBasin?.value?.length > 0; else noZone"
*ngIf="riverBasin?.value?.code; else noZone"
>
<div class="col-12">
<zh-hierarchy-search-table
[form]="form"
[riverBasin]="riverBasin?.value[0]"
[riverBasin]="riverBasin?.value"
></zh-hierarchy-search-table>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/zh-search/zh-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Loading