refactor: add options to chart
- method to return the node data - wrapper for showing the hierarchy
This commit is contained in:
parent
bcc998e8c2
commit
f15e8b7f5a
@ -8,10 +8,12 @@ frappe.pages['organizational-chart'].on_page_load = function(wrapper) {
|
|||||||
$(wrapper).bind('show', () => {
|
$(wrapper).bind('show', () => {
|
||||||
frappe.require('/assets/js/hierarchy-chart.min.js', () => {
|
frappe.require('/assets/js/hierarchy-chart.min.js', () => {
|
||||||
let organizational_chart = undefined;
|
let organizational_chart = undefined;
|
||||||
|
let method = 'erpnext.hr.page.organizational_chart.organizational_chart.get_children';
|
||||||
|
|
||||||
if (frappe.is_mobile()) {
|
if (frappe.is_mobile()) {
|
||||||
organizational_chart = new erpnext.HierarchyChartMobile(wrapper);
|
organizational_chart = new erpnext.HierarchyChartMobile(wrapper, method);
|
||||||
} else {
|
} else {
|
||||||
organizational_chart = new erpnext.HierarchyChart(wrapper);
|
organizational_chart = new erpnext.HierarchyChart(wrapper, method);
|
||||||
}
|
}
|
||||||
organizational_chart.show();
|
organizational_chart.show();
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@ def get_children(parent=None, company=None, exclude_node=None, is_root=False, is
|
|||||||
filters.append(['company', '=', company])
|
filters.append(['company', '=', company])
|
||||||
|
|
||||||
if not fields:
|
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:
|
if is_root:
|
||||||
parent = ''
|
parent = ''
|
||||||
@ -27,9 +27,9 @@ def get_children(parent=None, company=None, exclude_node=None, is_root=False, is
|
|||||||
|
|
||||||
for employee in employees:
|
for employee in employees:
|
||||||
is_expandable = frappe.get_all('Employee', filters=[
|
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
|
employee.expandable = 1 if is_expandable else 0
|
||||||
|
|
||||||
return employees
|
return employees
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
erpnext.HierarchyChart = class {
|
erpnext.HierarchyChart = class {
|
||||||
|
/* Options:
|
||||||
constructor(wrapper) {
|
- wrapper: wrapper for the hierarchy view
|
||||||
|
- method:
|
||||||
|
- to get the data for each node
|
||||||
|
- this method should return id, name, title, image, and connections for each node
|
||||||
|
*/
|
||||||
|
constructor(wrapper, method) {
|
||||||
this.wrapper = $(wrapper);
|
this.wrapper = $(wrapper);
|
||||||
this.page = wrapper.page;
|
this.page = wrapper.page;
|
||||||
|
this.method = method;
|
||||||
|
|
||||||
this.page.main.css({
|
this.page.main.css({
|
||||||
'min-height': '300px',
|
'min-height': '300px',
|
||||||
@ -114,8 +120,6 @@ erpnext.HierarchyChart = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render_root_node() {
|
render_root_node() {
|
||||||
this.method = 'erpnext.hr.page.organizational_chart.organizational_chart.get_children';
|
|
||||||
|
|
||||||
let me = this;
|
let me = this;
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
@ -128,12 +132,12 @@ erpnext.HierarchyChart = class {
|
|||||||
let data = r.message[0];
|
let data = r.message[0];
|
||||||
|
|
||||||
let root_node = new me.Node({
|
let root_node = new me.Node({
|
||||||
id: data.name,
|
id: data.id,
|
||||||
parent: me.$hierarchy.find('.root-level'),
|
parent: me.$hierarchy.find('.root-level'),
|
||||||
parent_id: undefined,
|
parent_id: undefined,
|
||||||
image: data.image,
|
image: data.image,
|
||||||
name: data.employee_name,
|
name: data.name,
|
||||||
title: data.designation,
|
title: data.title,
|
||||||
expandable: true,
|
expandable: true,
|
||||||
connections: data.connections,
|
connections: data.connections,
|
||||||
is_root: true,
|
is_root: true,
|
||||||
@ -225,7 +229,7 @@ erpnext.HierarchyChart = class {
|
|||||||
this.add_node(node, data);
|
this.add_node(node, data);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.add_connector(node.id, data.name);
|
this.add_connector(node.id, data.id);
|
||||||
}, 250);
|
}, 250);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -240,12 +244,12 @@ erpnext.HierarchyChart = class {
|
|||||||
var $li = $('<li class="child-node"></li>');
|
var $li = $('<li class="child-node"></li>');
|
||||||
|
|
||||||
return new this.Node({
|
return new this.Node({
|
||||||
id: data.name,
|
id: data.id,
|
||||||
parent: $li.appendTo(node.$children),
|
parent: $li.appendTo(node.$children),
|
||||||
parent_id: node.id,
|
parent_id: node.id,
|
||||||
image: data.image,
|
image: data.image,
|
||||||
name: data.employee_name,
|
name: data.name,
|
||||||
title: data.designation,
|
title: data.title,
|
||||||
expandable: data.expandable,
|
expandable: data.expandable,
|
||||||
connections: data.connections,
|
connections: data.connections,
|
||||||
children: undefined
|
children: undefined
|
||||||
@ -333,7 +337,7 @@ erpnext.HierarchyChart = class {
|
|||||||
(child_nodes) => {
|
(child_nodes) => {
|
||||||
if (child_nodes) {
|
if (child_nodes) {
|
||||||
$.each(child_nodes, (_i, data) => {
|
$.each(child_nodes, (_i, data) => {
|
||||||
this.add_connector(node_parent, data.name);
|
this.add_connector(node_parent, data.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
erpnext.HierarchyChartMobile = class {
|
erpnext.HierarchyChartMobile = class {
|
||||||
|
/* Options:
|
||||||
constructor(wrapper) {
|
- wrapper: wrapper for the hierarchy view
|
||||||
|
- method:
|
||||||
|
- to get the data for each node
|
||||||
|
- this method should return id, name, title, image, and connections for each node
|
||||||
|
*/
|
||||||
|
constructor(wrapper, method) {
|
||||||
this.wrapper = $(wrapper);
|
this.wrapper = $(wrapper);
|
||||||
this.page = wrapper.page;
|
this.page = wrapper.page;
|
||||||
|
this.method = method;
|
||||||
|
|
||||||
this.page.main.css({
|
this.page.main.css({
|
||||||
'min-height': '300px',
|
'min-height': '300px',
|
||||||
@ -123,8 +129,6 @@ erpnext.HierarchyChartMobile = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render_root_node() {
|
render_root_node() {
|
||||||
this.method = 'erpnext.hr.page.organizational_chart.organizational_chart.get_children';
|
|
||||||
|
|
||||||
let me = this;
|
let me = this;
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
@ -137,12 +141,12 @@ erpnext.HierarchyChartMobile = class {
|
|||||||
let data = r.message[0];
|
let data = r.message[0];
|
||||||
|
|
||||||
let root_node = new me.Node({
|
let root_node = new me.Node({
|
||||||
id: data.name,
|
id: data.id,
|
||||||
parent: me.$hierarchy.find('.root-level'),
|
parent: me.$hierarchy.find('.root-level'),
|
||||||
parent_id: undefined,
|
parent_id: undefined,
|
||||||
image: data.image,
|
image: data.image,
|
||||||
name: data.employee_name,
|
name: data.name,
|
||||||
title: data.designation,
|
title: data.title,
|
||||||
expandable: true,
|
expandable: true,
|
||||||
connections: data.connections,
|
connections: data.connections,
|
||||||
is_root: true,
|
is_root: true,
|
||||||
@ -249,10 +253,10 @@ erpnext.HierarchyChartMobile = class {
|
|||||||
if (child_nodes) {
|
if (child_nodes) {
|
||||||
$.each(child_nodes, (_i, data) => {
|
$.each(child_nodes, (_i, data) => {
|
||||||
this.add_node(node, data);
|
this.add_node(node, data);
|
||||||
$(`#${data.name}`).addClass('active-child');
|
$(`#${data.id}`).addClass('active-child');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.add_connector(node.id, data.name);
|
this.add_connector(node.id, data.id);
|
||||||
}, 250);
|
}, 250);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -266,12 +270,12 @@ erpnext.HierarchyChartMobile = class {
|
|||||||
var $li = $('<li class="child-node"></li>');
|
var $li = $('<li class="child-node"></li>');
|
||||||
|
|
||||||
return new this.Node({
|
return new this.Node({
|
||||||
id: data.name,
|
id: data.id,
|
||||||
parent: $li.appendTo(node.$children),
|
parent: $li.appendTo(node.$children),
|
||||||
parent_id: node.id,
|
parent_id: node.id,
|
||||||
image: data.image,
|
image: data.image,
|
||||||
name: data.employee_name,
|
name: data.name,
|
||||||
title: data.designation,
|
title: data.title,
|
||||||
expandable: data.expandable,
|
expandable: data.expandable,
|
||||||
connections: data.connections,
|
connections: data.connections,
|
||||||
children: undefined
|
children: undefined
|
||||||
@ -418,7 +422,7 @@ erpnext.HierarchyChartMobile = class {
|
|||||||
${html}
|
${html}
|
||||||
<span class="avatar avatar-small">
|
<span class="avatar avatar-small">
|
||||||
<div class="avatar-frame standard-image avatar-extra-count"
|
<div class="avatar-frame standard-image avatar-extra-count"
|
||||||
title="${extra_nodes.map(node => node.employee_name).join(', ')}">
|
title="${extra_nodes.map(node => node.name).join(', ')}">
|
||||||
+${extra_nodes.length}
|
+${extra_nodes.length}
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
@ -443,7 +447,7 @@ erpnext.HierarchyChartMobile = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_avatar(node) {
|
get_avatar(node) {
|
||||||
return `<span class="avatar avatar-small" title="${node.employee_name}">
|
return `<span class="avatar avatar-small" title="${node.name}">
|
||||||
<span class="avatar-frame" src=${node.image} style="background-image: url(${node.image})"></span>
|
<span class="avatar-frame" src=${node.image} style="background-image: url(${node.image})"></span>
|
||||||
</span>`
|
</span>`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user