Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Org Chart fixes #27305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions erpnext/hr/page/organizational_chart/organizational_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
26 changes: 15 additions & 11 deletions erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ erpnext.HierarchyChart = class {
}

show() {
frappe.breadcrumbs.add('HR');

this.setup_actions();
if ($(`[data-fieldname="company"]`).length) return;
let me = this;
Expand All @@ -83,15 +81,18 @@ 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
me.make_svg_markers();
me.setup_hierarchy();
me.render_root_nodes();
me.all_nodes_expanded = false;
} else {
frappe.throw(__('Please select a company first.'));
}
}
});
Expand Down Expand Up @@ -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() {
Expand All @@ -203,6 +204,8 @@ erpnext.HierarchyChart = class {
<g id="connectors" fill="none">
</g>
</svg>
<div id="hierarchy-chart">
</div>
</div>`);
}

Expand All @@ -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')),
Expand Down Expand Up @@ -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()
]);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions erpnext/public/js/hierarchy_chart/hierarchy_chart_mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ erpnext.HierarchyChartMobile = class {
}

show() {
frappe.breadcrumbs.add('HR');

let me = this;
if ($(`[data-fieldname="company"]`).length) return;

Expand Down
12 changes: 8 additions & 4 deletions erpnext/utilities/hierarchy_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
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)
Expand Down