fix: expand all nodes not working when there are only 2 levels
- added dom freeze while expanding all nodes and exporting
This commit is contained in:
parent
4c612b7cb2
commit
0b4959966c
@ -32,16 +32,17 @@ def get_children(parent=None, company=None, exclude_node=None):
|
|||||||
def get_connections(employee):
|
def get_connections(employee):
|
||||||
num_connections = 0
|
num_connections = 0
|
||||||
|
|
||||||
connections = frappe.get_list('Employee', filters=[
|
nodes_to_expand = frappe.get_list('Employee', filters=[
|
||||||
['reports_to', '=', employee]
|
['reports_to', '=', employee]
|
||||||
])
|
])
|
||||||
num_connections += len(connections)
|
num_connections += len(nodes_to_expand)
|
||||||
|
|
||||||
while connections:
|
while nodes_to_expand:
|
||||||
for entry in connections:
|
parent = nodes_to_expand.pop(0)
|
||||||
connections = frappe.get_list('Employee', filters=[
|
descendants = frappe.get_list('Employee', filters=[
|
||||||
['reports_to', '=', entry.name]
|
['reports_to', '=', parent.name]
|
||||||
])
|
])
|
||||||
num_connections += len(connections)
|
num_connections += len(descendants)
|
||||||
|
nodes_to_expand.extend(descendants)
|
||||||
|
|
||||||
return num_connections
|
return num_connections
|
||||||
@ -103,6 +103,7 @@ erpnext.HierarchyChart = class {
|
|||||||
|
|
||||||
setup_actions() {
|
setup_actions() {
|
||||||
let me = this;
|
let me = this;
|
||||||
|
this.page.clear_inner_toolbar();
|
||||||
this.page.add_inner_button(__('Export'), function() {
|
this.page.add_inner_button(__('Export'), function() {
|
||||||
me.export_chart();
|
me.export_chart();
|
||||||
});
|
});
|
||||||
@ -124,6 +125,7 @@ erpnext.HierarchyChart = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export_chart() {
|
export_chart() {
|
||||||
|
frappe.dom.freeze(__('Exporting...'));
|
||||||
this.page.main.css({
|
this.page.main.css({
|
||||||
'min-height': '',
|
'min-height': '',
|
||||||
'max-height': '',
|
'max-height': '',
|
||||||
@ -147,6 +149,8 @@ erpnext.HierarchyChart = class {
|
|||||||
a.href = dataURL;
|
a.href = dataURL;
|
||||||
a.download = 'hierarchy_chart';
|
a.download = 'hierarchy_chart';
|
||||||
a.click();
|
a.click();
|
||||||
|
}).finally(() => {
|
||||||
|
frappe.dom.unfreeze();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setup_page_style();
|
this.setup_page_style();
|
||||||
@ -170,7 +174,9 @@ erpnext.HierarchyChart = class {
|
|||||||
this.page.main
|
this.page.main
|
||||||
.find('#hierarchy-chart-wrapper')
|
.find('#hierarchy-chart-wrapper')
|
||||||
.append(this.$hierarchy);
|
.append(this.$hierarchy);
|
||||||
|
|
||||||
this.nodes = {};
|
this.nodes = {};
|
||||||
|
this.all_nodes_expanded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
make_svg_markers() {
|
make_svg_markers() {
|
||||||
@ -203,7 +209,7 @@ erpnext.HierarchyChart = class {
|
|||||||
render_root_nodes(expanded_view=false) {
|
render_root_nodes(expanded_view=false) {
|
||||||
let me = this;
|
let me = this;
|
||||||
|
|
||||||
frappe.call({
|
return frappe.call({
|
||||||
method: me.method,
|
method: me.method,
|
||||||
args: {
|
args: {
|
||||||
company: me.company
|
company: me.company
|
||||||
@ -230,8 +236,8 @@ erpnext.HierarchyChart = class {
|
|||||||
expand_node = node;
|
expand_node = node;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
me.root_node = expand_node;
|
||||||
if (!expanded_view) {
|
if (!expanded_view) {
|
||||||
me.root_node = expand_node;
|
|
||||||
me.expand_node(expand_node);
|
me.expand_node(expand_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,10 +287,12 @@ erpnext.HierarchyChart = class {
|
|||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
frappe.run_serially([
|
frappe.run_serially([
|
||||||
|
() => frappe.dom.freeze(),
|
||||||
() => this.setup_hierarchy(),
|
() => this.setup_hierarchy(),
|
||||||
() => this.render_root_nodes(true),
|
() => this.render_root_nodes(true),
|
||||||
() => this.get_all_nodes(node.id, node.name),
|
() => this.get_all_nodes(node.id, node.name),
|
||||||
(data_list) => this.render_children_of_all_nodes(data_list)
|
(data_list) => this.render_children_of_all_nodes(data_list),
|
||||||
|
() => frappe.dom.unfreeze()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,7 +368,7 @@ erpnext.HierarchyChart = class {
|
|||||||
node = this.nodes[entry.parent];
|
node = this.nodes[entry.parent];
|
||||||
if (node) {
|
if (node) {
|
||||||
this.render_child_nodes_for_expanded_view(node, entry.data);
|
this.render_child_nodes_for_expanded_view(node, entry.data);
|
||||||
} else {
|
} else if (data_list.length) {
|
||||||
data_list.push(entry);
|
data_list.push(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user