Some initial code to hook into the WithSearch component and check if we are using a HierarchicalListViewController.

This commit is contained in:
Marc Durepos 2023-12-12 16:36:48 -05:00
parent 8cf4d716b3
commit 43d2ed0172
6 changed files with 53 additions and 9 deletions

View file

@ -28,7 +28,7 @@
'data': [], 'data': [],
'assets': { 'assets': {
'web.assets_backend': [ 'web.assets_backend': [
'bemade_hierarchical_tree_view/src/*/**', 'bemade_hierarchical_tree_view/static/src/*/**',
] ]
}, },
'installable': True, 'installable': True,

View file

@ -1,8 +0,0 @@
/** @odoo-module **/
import { ListController } from "@web/views/list/list_controller";
import { ListRenderer } from "@web/views/list/list_renderer";
export class HierarchicalTreeViewController extends ListController {
}

View file

@ -0,0 +1,18 @@
/** @odoo-module **/
import { ListController } from "@web/views/list/list_controller";
export class HierarchicalTreeViewController extends ListController {
}
HierarchicalTreeViewController.props = {
...ListController.props,
parentField: String,
childField: String,
}
HierarchicalTreeViewController.defaultProps = {
...ListController.defaultProps,
parentField: 'parent_id',
childField: 'child_id',
}

View file

@ -0,0 +1,34 @@
/** @odoo-module **/
import {patch} from "@web/core/utils/patch";
import {WithSearch} from "@web/search/with_search/with_search";
import {onWillRender} from "@odoo/owl";
import {HierarchicalTreeViewController} from "./hierarchical_tree_view_controller";
patch(WithSearch.prototype, "bemade_hierarchical_tree_view/with_search", {
setup() {
onWillRender(() => {
let children = Object.hasOwn(this.__owl__, 'children') ? this.__owl__.children : null;
if (children && Object.keys(children).length !== 0) {
for (let childProp in children) {
let child = children[childProp];
if (Object.hasOwn(child, 'component')) {
let childComponent = child.component;
if (childComponent.prototype == HierarchicalTreeViewController.prototype) {
let parentField, childField = (childComponent.parentField, childComponent.childField)
let parentIndex = this.groupBy.indexOf(parentField);
let childIndex = this.groupBy.indexOf(childField);
if (parentIndex) {
this.groupBy.splice(parentField, 1);
}
if (childField) {
this.groupBy.splice(childField, 1);
}
}
}
}
}
});
this._super();
}
});