refactor: add options to chart

- method to return the node data

- wrapper for showing the hierarchy
This commit is contained in:
Rucha Mahabal
2021-06-29 21:26:47 +05:30
parent 281241dc24
commit 249621af1b
4 changed files with 41 additions and 31 deletions

View File

@@ -8,10 +8,12 @@ frappe.pages['organizational-chart'].on_page_load = function(wrapper) {
$(wrapper).bind('show', () => {
frappe.require('/assets/js/hierarchy-chart.min.js', () => {
let organizational_chart = undefined;
let method = 'erpnext.hr.page.organizational_chart.organizational_chart.get_children';
if (frappe.is_mobile()) {
organizational_chart = new erpnext.HierarchyChartMobile(wrapper);
organizational_chart = new erpnext.HierarchyChartMobile(wrapper, method);
} else {
organizational_chart = new erpnext.HierarchyChart(wrapper);
organizational_chart = new erpnext.HierarchyChart(wrapper, method);
}
organizational_chart.show();
});

View File

@@ -9,7 +9,7 @@ def get_children(parent=None, company=None, exclude_node=None, is_root=False, is
filters.append(['company', '=', company])
if not fields:
fields = ['employee_name', 'name', 'reports_to', 'image', 'designation']
fields = ['employee_name as name', 'name as id', 'reports_to', 'image', 'designation as title']
if is_root:
parent = ''
@@ -27,9 +27,9 @@ def get_children(parent=None, company=None, exclude_node=None, is_root=False, is
for employee in employees:
is_expandable = frappe.get_all('Employee', filters=[
['reports_to', '=', employee.get('name')]
['reports_to', '=', employee.get('id')]
])
employee.connections = get_connections(employee.name)
employee.connections = get_connections(employee.id)
employee.expandable = 1 if is_expandable else 0
return employees