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