fix: Org Chart fixes (#27290)
* fix(org chart): multiple root nodes not expanding on clicking Expand All * fix: unstable filter inserts duplicate nodes
This commit is contained in:
parent
dea5c34d8d
commit
f828d853e3
@ -15,6 +15,8 @@ frappe.pages['organizational-chart'].on_page_load = function(wrapper) {
|
||||
} else {
|
||||
organizational_chart = new erpnext.HierarchyChart('Employee', wrapper, method);
|
||||
}
|
||||
|
||||
frappe.breadcrumbs.add('HR');
|
||||
organizational_chart.show();
|
||||
});
|
||||
});
|
||||
|
@ -67,8 +67,6 @@ erpnext.HierarchyChart = class {
|
||||
}
|
||||
|
||||
show() {
|
||||
frappe.breadcrumbs.add('HR');
|
||||
|
||||
this.setup_actions();
|
||||
if ($(`[data-fieldname="company"]`).length) return;
|
||||
let me = this;
|
||||
@ -83,8 +81,9 @@ erpnext.HierarchyChart = class {
|
||||
reqd: 1,
|
||||
change: () => {
|
||||
me.company = undefined;
|
||||
$('#hierarchy-chart-wrapper').remove();
|
||||
|
||||
if (company.get_value() && me.company != company.get_value()) {
|
||||
if (company.get_value()) {
|
||||
me.company = company.get_value();
|
||||
|
||||
// svg for connectors
|
||||
@ -92,6 +91,8 @@ erpnext.HierarchyChart = class {
|
||||
me.setup_hierarchy();
|
||||
me.render_root_nodes();
|
||||
me.all_nodes_expanded = false;
|
||||
} else {
|
||||
frappe.throw(__('Please select a company first.'));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -172,11 +173,11 @@ erpnext.HierarchyChart = class {
|
||||
</ul>`);
|
||||
|
||||
this.page.main
|
||||
.find('#hierarchy-chart-wrapper')
|
||||
.find('#hierarchy-chart')
|
||||
.empty()
|
||||
.append(this.$hierarchy);
|
||||
|
||||
this.nodes = {};
|
||||
this.all_nodes_expanded = false;
|
||||
}
|
||||
|
||||
make_svg_markers() {
|
||||
@ -203,6 +204,8 @@ erpnext.HierarchyChart = class {
|
||||
<g id="connectors" fill="none">
|
||||
</g>
|
||||
</svg>
|
||||
<div id="hierarchy-chart">
|
||||
</div>
|
||||
</div>`);
|
||||
}
|
||||
|
||||
@ -219,7 +222,10 @@ erpnext.HierarchyChart = class {
|
||||
let expand_node = undefined;
|
||||
let node = undefined;
|
||||
|
||||
$.each(r.message, (i, data) => {
|
||||
$.each(r.message, (_i, data) => {
|
||||
if ($(`#${data.id}`).length)
|
||||
return;
|
||||
|
||||
node = new me.Node({
|
||||
id: data.id,
|
||||
parent: $('<li class="child-node"></li>').appendTo(me.$hierarchy.find('.node-children')),
|
||||
@ -290,7 +296,7 @@ erpnext.HierarchyChart = class {
|
||||
() => frappe.dom.freeze(),
|
||||
() => this.setup_hierarchy(),
|
||||
() => this.render_root_nodes(true),
|
||||
() => this.get_all_nodes(node.id, node.name),
|
||||
() => this.get_all_nodes(),
|
||||
(data_list) => this.render_children_of_all_nodes(data_list),
|
||||
() => frappe.dom.unfreeze()
|
||||
]);
|
||||
@ -341,15 +347,13 @@ erpnext.HierarchyChart = class {
|
||||
node.expanded = true;
|
||||
}
|
||||
|
||||
get_all_nodes(node_id, node_name) {
|
||||
get_all_nodes() {
|
||||
return new Promise(resolve => {
|
||||
frappe.call({
|
||||
method: 'erpnext.utilities.hierarchy_chart.get_all_nodes',
|
||||
args: {
|
||||
method: this.method,
|
||||
company: this.company,
|
||||
parent: node_id,
|
||||
parent_name: node_name
|
||||
company: this.company
|
||||
},
|
||||
callback: (r) => {
|
||||
resolve(r.message);
|
||||
|
@ -59,8 +59,6 @@ erpnext.HierarchyChartMobile = class {
|
||||
}
|
||||
|
||||
show() {
|
||||
frappe.breadcrumbs.add('HR');
|
||||
|
||||
let me = this;
|
||||
if ($(`[data-fieldname="company"]`).length) return;
|
||||
|
||||
|
@ -6,17 +6,21 @@ import frappe
|
||||
from frappe import _
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_all_nodes(parent, parent_name, method, company):
|
||||
def get_all_nodes(method, company):
|
||||
'''Recursively gets all data from nodes'''
|
||||
method = frappe.get_attr(method)
|
||||
|
||||
if method not in frappe.whitelisted:
|
||||
frappe.throw(_('Not Permitted'), frappe.PermissionError)
|
||||
|
||||
data = method(parent, company)
|
||||
result = [dict(parent=parent, parent_name=parent_name, data=data)]
|
||||
root_nodes = method(company=company)
|
||||
result = []
|
||||
nodes_to_expand = []
|
||||
|
||||
nodes_to_expand = [{'id': d.get('id'), 'name': d.get('name')} for d in data if d.get('expandable')]
|
||||
for root in root_nodes:
|
||||
data = method(root.id, company)
|
||||
result.append(dict(parent=root.id, parent_name=root.name, data=data))
|
||||
nodes_to_expand.extend([{'id': d.get('id'), 'name': d.get('name')} for d in data if d.get('expandable')])
|
||||
|
||||
while nodes_to_expand:
|
||||
parent = nodes_to_expand.pop(0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user