fix(mobile): collapsed nodes not expanding

This commit is contained in:
Rucha Mahabal 2021-07-09 01:03:02 +05:30
parent 9270de59f4
commit 9e7302a21e

View File

@ -88,7 +88,7 @@ erpnext.HierarchyChartMobile = class {
me.$sibling_group = $(`<div class="sibling-group mt-4 mb-4"></div>`); me.$sibling_group = $(`<div class="sibling-group mt-4 mb-4"></div>`);
me.page.main.append(me.$sibling_group); me.page.main.append(me.$sibling_group);
me.setup_hierarchy() me.setup_hierarchy();
me.render_root_nodes(); me.render_root_nodes();
} }
} }
@ -194,9 +194,9 @@ erpnext.HierarchyChartMobile = class {
collapse_node() { collapse_node() {
let node = this.selected_node; let node = this.selected_node;
if (node.expandable) { if (node.expandable && node.$children) {
node.$children.hide(); node.$children.hide();
node.expanded = false; node.expanded = 0;
// add a collapsed level to show the collapsed parent // add a collapsed level to show the collapsed parent
// and a button beside it to move to that level // and a button beside it to move to that level
@ -212,10 +212,7 @@ erpnext.HierarchyChartMobile = class {
frappe.run_serially([ frappe.run_serially([
() => this.get_child_nodes(node.parent_id, node.id), () => this.get_child_nodes(node.parent_id, node.id),
(child_nodes) => this.get_node_group(child_nodes, node.parent_id), (child_nodes) => this.get_node_group(child_nodes, node.parent_id),
(node_group) => { (node_group) => node_parent.find('.collapsed-level').append(node_group),
node_parent.find('.collapsed-level')
.append(node_group);
},
() => this.setup_node_group_action() () => this.setup_node_group_action()
]); ]);
} }
@ -268,7 +265,7 @@ erpnext.HierarchyChartMobile = class {
} }
node.$children.show(); node.$children.show();
node.expanded = true; node.expanded = 1;
} }
add_node(node, data) { add_node(node, data) {
@ -380,13 +377,16 @@ erpnext.HierarchyChartMobile = class {
node_element.click(function() { node_element.click(function() {
if (node.is_root) { if (node.is_root) {
var el = $(this).detach();
me.$hierarchy.empty(); me.$hierarchy.empty();
me.add_node_to_hierarchy(node, true); $(`#connectors`).empty();
me.add_node_to_hierarchy(el, node);
} else if (node_element.is(':visible') && node_element.hasClass('active-path')) { } else if (node_element.is(':visible') && node_element.hasClass('active-path')) {
me.remove_levels_after_node(node); me.remove_levels_after_node(node);
me.remove_orphaned_connectors(); me.remove_orphaned_connectors();
} else { } else {
me.add_node_to_hierarchy(node, true); var el = $(this).detach();
me.add_node_to_hierarchy(el, node);
me.collapse_node(); me.collapse_node();
} }
@ -417,15 +417,15 @@ erpnext.HierarchyChartMobile = class {
}); });
} }
add_node_to_hierarchy(node) { add_node_to_hierarchy(node_element, node) {
this.$hierarchy.append(` this.$hierarchy.append(`<li class="level"></li>`);
<li class="level"> node_element.removeClass('active-child active-path');
<div class="node-level d-flex flex-row"> this.$hierarchy.find('.level:last').append(node_element);
</div>
</li>
`);
node.$link.appendTo(this.$hierarchy.find('.level:last')); let node_object = this.nodes[node.id];
node_object.expanded = 0;
node_object.$children = undefined;
this.nodes[node.id] = node_object;
} }
get_node_group(nodes, parent, collapsed=true) { get_node_group(nodes, parent, collapsed=true) {
@ -478,9 +478,11 @@ erpnext.HierarchyChartMobile = class {
expand_sibling_group_node(parent) { expand_sibling_group_node(parent) {
let node_object = this.nodes[parent]; let node_object = this.nodes[parent];
let node = node_object.$link; let node = node_object.$link;
node.removeClass('active-child active-path'); node.removeClass('active-child active-path');
node_object.expanded = 0; node_object.expanded = 0;
node_object.$children = undefined; node_object.$children = undefined;
this.nodes[node.id] = node_object;
// show parent's siblings and expand parent node // show parent's siblings and expand parent node
frappe.run_serially([ frappe.run_serially([
@ -491,16 +493,20 @@ erpnext.HierarchyChartMobile = class {
this.$sibling_group.empty().append(node_group); this.$sibling_group.empty().append(node_group);
}, },
() => this.setup_node_group_action(), () => this.setup_node_group_action(),
() => { () => this.reattach_and_expand_node(node, node_object)
]);
}
reattach_and_expand_node(node, node_object) {
var el = node.detach();
this.$hierarchy.empty().append(` this.$hierarchy.empty().append(`
<li class="level"></li> <li class="level"></li>
`); `);
this.$hierarchy.find('.level').append(node); this.$hierarchy.find('.level').append(el);
$(`#connectors`).empty(); $(`#connectors`).empty();
this.expand_node(node_object); this.expand_node(node_object);
} }
]);
}
remove_levels_after_node(node) { remove_levels_after_node(node) {
let level = $(`#${node.id}`).parent().parent().index(); let level = $(`#${node.id}`).parent().parent().index();