fix: fix user profile page chart api
This commit is contained in:
parent
e65fb5b62e
commit
80fa4ccff0
7 changed files with 74 additions and 103 deletions
|
|
@ -190,7 +190,7 @@ class DashboardChart {
|
|||
},
|
||||
];
|
||||
|
||||
this.render_chart_filters(filters, this.chart_container, 1);
|
||||
frappe.dashboard_utils.render_chart_filters(filters, 'chart-actions', this.chart_container, 1);
|
||||
}
|
||||
|
||||
fetch_and_update_chart() {
|
||||
|
|
@ -237,45 +237,6 @@ class DashboardChart {
|
|||
}
|
||||
}
|
||||
|
||||
render_chart_filters(filters, container, append) {
|
||||
filters.forEach(filter => {
|
||||
let chart_filter_html = `<div class="chart-actions btn-group dropdown pull-right">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<button class="btn btn-default btn-xs">
|
||||
<span class="filter-label">${filter.label}</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
</a>`;
|
||||
let options_html;
|
||||
|
||||
if (filter.fieldnames) {
|
||||
options_html = filter.options.map((option, i) =>
|
||||
`<li><a data-fieldname = "${filter.fieldnames[i]}">${option}</a></li>`).join('');
|
||||
} else {
|
||||
options_html = filter.options.map( option => `<li><a>${option}</a></li>`).join('');
|
||||
}
|
||||
|
||||
let dropdown_html = chart_filter_html + `<ul class="dropdown-menu">${options_html}</ul></div>`;
|
||||
let $chart_filter = $(dropdown_html);
|
||||
|
||||
if (append) {
|
||||
$chart_filter.prependTo(container);
|
||||
} else $chart_filter.appendTo(container);
|
||||
|
||||
$chart_filter.find('.dropdown-menu').on('click', 'li a', (e) => {
|
||||
let $el = $(e.currentTarget);
|
||||
let fieldname;
|
||||
if ($el.attr('data-fieldname')) {
|
||||
fieldname = $el.attr('data-fieldname');
|
||||
}
|
||||
let selected_item = $el.text();
|
||||
$el.parents('.chart-actions').find('.filter-label').text(selected_item);
|
||||
filter.action(selected_item, fieldname);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
get_report_chart_data(result) {
|
||||
let chart_fields = {
|
||||
y_field: this.chart_doc.y_field,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ def cache_source(function):
|
|||
chart = kwargs.get("chart")
|
||||
no_cache = kwargs.get("no_cache")
|
||||
if no_cache:
|
||||
return function(args)
|
||||
return function(chart = chart, no_cache = no_cache)
|
||||
chart_name = frappe.parse_json(chart).name
|
||||
cache_key = "chart-data:{}".format(chart_name)
|
||||
if int(kwargs.get("refresh") or 0):
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@
|
|||
"fieldname": "time_interval",
|
||||
"fieldtype": "Select",
|
||||
"label": "Time Interval",
|
||||
"options": "Quarterly\nMonthly\nWeekly\nDaily"
|
||||
"options": "Yearly\nQuarterly\nMonthly\nWeekly\nDaily"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
|
|
@ -213,8 +213,8 @@
|
|||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2020-01-29 17:17:06.239511",
|
||||
"modified_by": "umair@erpnext.com",
|
||||
"modified": "2020-02-06 12:26:08.949451",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Desk",
|
||||
"name": "Dashboard Chart",
|
||||
"owner": "Administrator",
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ def get_chart_config(chart, filters, timespan, timegrain, from_date, to_date):
|
|||
doctype = chart.document_type
|
||||
from_date = from_date.strftime('%Y-%m-%d')
|
||||
to_date = to_date
|
||||
|
||||
|
||||
filters.append([chart.document_type, datefield, '>=', from_date, False])
|
||||
filters.append([chart.document_type, datefield, '<=', to_date, False])
|
||||
|
||||
|
|
@ -101,7 +101,8 @@ def get_chart_config(chart, filters, timespan, timegrain, from_date, to_date):
|
|||
],
|
||||
filters = filters,
|
||||
group_by = '_year, _unit',
|
||||
order_by = '_year asc, _unit asc'
|
||||
order_by = '_year asc, _unit asc',
|
||||
as_list = True
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -172,17 +173,18 @@ def convert_to_dates(data, timegrain):
|
|||
""" Converts individual dates within data to the end of period """
|
||||
result = []
|
||||
for d in data:
|
||||
if timegrain == 'Daily':
|
||||
result.append([add_to_date('{:d}-01-01'.format(int(d[0])), days = d[1] - 1), d[2]])
|
||||
elif timegrain == 'Weekly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), weeks = d[1] + 1), days = -1), d[2]])
|
||||
elif timegrain == 'Monthly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), months=d[1]), days = -1), d[2]])
|
||||
elif timegrain == 'Quarterly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), months=d[1] * 3), days = -1), d[2]])
|
||||
elif timegrain == 'Yearly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), months=12), days = -1), d[2]])
|
||||
result[-1][0] = getdate(result[-1][0])
|
||||
if d[2] != 0:
|
||||
if timegrain == 'Daily':
|
||||
result.append([add_to_date('{:d}-01-01'.format(int(d[0])), days = d[1] - 1), d[2]])
|
||||
elif timegrain == 'Weekly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), weeks = d[1] + 1), days = -1), d[2]])
|
||||
elif timegrain == 'Monthly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), months=d[1]), days = -1), d[2]])
|
||||
elif timegrain == 'Quarterly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), months=d[1] * 3), days = -1), d[2]])
|
||||
elif timegrain == 'Yearly':
|
||||
result.append([add_to_date(add_to_date('{:d}-01-01'.format(int(d[0])), months=12), days = -1), d[2]])
|
||||
result[-1][0] = getdate(result[-1][0])
|
||||
|
||||
return result
|
||||
|
||||
|
|
@ -190,7 +192,7 @@ def get_unit_function(doctype, datefield, timegrain):
|
|||
unit_function = ''
|
||||
if timegrain=='Daily':
|
||||
if frappe.db.db_type == 'mariadb':
|
||||
unit_function = 'extract(day_minute from `tab{doctype}`.{datefield})'.format(
|
||||
unit_function = 'dayofyear({datefield})'.format(
|
||||
doctype=doctype, datefield=datefield)
|
||||
else:
|
||||
unit_function = 'extract(doy from `tab{doctype}`.{datefield})'.format(
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ class UserProfile {
|
|||
}
|
||||
|
||||
render_line_chart() {
|
||||
this.line_chart_filters = {'user': this.user_id};
|
||||
this.line_chart_filters = [['Energy Point Log', 'user', '=', this.user_id, false]];
|
||||
this.line_chart_config = {
|
||||
timespan: 'Last Month',
|
||||
time_interval: 'Daily',
|
||||
|
|
@ -200,14 +200,18 @@ class UserProfile {
|
|||
label: 'All',
|
||||
options: ['All', 'Auto', 'Criticism', 'Appreciation', 'Revert'],
|
||||
action: (selected_item) => {
|
||||
if (selected_item === 'All') delete this.line_chart_filters.type;
|
||||
else this.line_chart_filters.type = selected_item;
|
||||
if (selected_item === 'All') {
|
||||
if (this.line_chart_filters.length > 1) this.line_chart_filters.pop();
|
||||
}
|
||||
else {
|
||||
this.line_chart_filters[1] = ['Energy Point Log', 'type', '=', selected_item, false];
|
||||
};
|
||||
this.update_line_chart_data();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Last Month',
|
||||
options: ['Last Week', 'Last Month', 'Last Quarter'],
|
||||
options: ['Last Week', 'Last Month', 'Last Quarter', 'Last Year'],
|
||||
action: (selected_item) => {
|
||||
this.line_chart_config.timespan = selected_item;
|
||||
this.update_line_chart_data();
|
||||
|
|
@ -222,7 +226,7 @@ class UserProfile {
|
|||
}
|
||||
},
|
||||
];
|
||||
this.render_chart_filters(filters, '.line-chart-container', 1);
|
||||
frappe.dashboard_utils.render_chart_filters(filters, 'chart-filter', '.line-chart-container', 1);
|
||||
}
|
||||
|
||||
create_percentage_chart_filters() {
|
||||
|
|
@ -237,7 +241,7 @@ class UserProfile {
|
|||
}
|
||||
},
|
||||
];
|
||||
this.render_chart_filters(filters, '.percentage-chart-container');
|
||||
frappe.dashboard_utils.render_chart_filters(filters, 'chart-filter', '.percentage-chart-container');
|
||||
}
|
||||
|
||||
create_heatmap_chart_filters() {
|
||||
|
|
@ -250,47 +254,9 @@ class UserProfile {
|
|||
}
|
||||
},
|
||||
];
|
||||
this.render_chart_filters(filters, '.heatmap-container');
|
||||
frappe.dashboard_utils.render_chart_filters(filters, 'chart-filter', '.heatmap-container');
|
||||
}
|
||||
|
||||
render_chart_filters(filters, container, append) {
|
||||
filters.forEach(filter => {
|
||||
let chart_filter_html = `<div class="chart-filter pull-right">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<button class="btn btn-default btn-xs">
|
||||
<span class="filter-label">${filter.label}</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
</a>`;
|
||||
let options_html;
|
||||
|
||||
if (filter.fieldnames) {
|
||||
options_html = filter.options.map((option, i) =>
|
||||
`<li><a data-fieldname = "${filter.fieldnames[i]}">${option}</a></li>`).join('');
|
||||
} else {
|
||||
options_html = filter.options.map( option => `<li><a>${option}</a></li>`).join('');
|
||||
}
|
||||
|
||||
let dropdown_html = chart_filter_html + `<ul class="dropdown-menu">${options_html}</ul></div>`;
|
||||
let $chart_filter = $(dropdown_html);
|
||||
|
||||
if (append) {
|
||||
$chart_filter.prependTo(this.wrapper.find(container));
|
||||
} else $chart_filter.appendTo(this.wrapper.find(container));
|
||||
|
||||
$chart_filter.find('.dropdown-menu').on('click', 'li a', (e) => {
|
||||
let $el = $(e.currentTarget);
|
||||
let fieldname;
|
||||
if ($el.attr('data-fieldname')) {
|
||||
fieldname = $el.attr('data-fieldname');
|
||||
}
|
||||
let selected_item = $el.text();
|
||||
$el.parents('.chart-filter').find('.filter-label').text(selected_item);
|
||||
filter.action(selected_item, fieldname);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
edit_profile() {
|
||||
let edit_profile_dialog = new frappe.ui.Dialog({
|
||||
|
|
|
|||
|
|
@ -235,6 +235,7 @@
|
|||
"public/js/frappe/chat.js",
|
||||
"public/js/frappe/social/social_factory.js",
|
||||
"public/js/frappe/utils/energy_point_utils.js",
|
||||
"public/js/frappe/utils/dashboard_utils.js",
|
||||
"public/js/frappe/ui/chart.js",
|
||||
"public/js/frappe/barcode_scanner/index.js"
|
||||
],
|
||||
|
|
|
|||
41
frappe/public/js/frappe/utils/dashboard_utils.js
Normal file
41
frappe/public/js/frappe/utils/dashboard_utils.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
frappe.dashboard_utils = {
|
||||
|
||||
render_chart_filters: function(filters, button_class, container, append) {
|
||||
filters.forEach(filter => {
|
||||
let chart_filter_html = `<div class="${button_class} btn-group dropdown pull-right">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<button class="btn btn-default btn-xs">
|
||||
<span class="filter-label">${filter.label}</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
</a>`;
|
||||
let options_html;
|
||||
|
||||
if (filter.fieldnames) {
|
||||
options_html = filter.options.map((option, i) =>
|
||||
`<li><a data-fieldname = "${filter.fieldnames[i]}">${option}</a></li>`).join('');
|
||||
} else {
|
||||
options_html = filter.options.map( option => `<li><a>${option}</a></li>`).join('');
|
||||
}
|
||||
|
||||
let dropdown_html = chart_filter_html + `<ul class="dropdown-menu">${options_html}</ul></div>`;
|
||||
let $chart_filter = $(dropdown_html);
|
||||
|
||||
if (append) {
|
||||
$chart_filter.prependTo(container);
|
||||
} else $chart_filter.appendTo(container);
|
||||
|
||||
$chart_filter.find('.dropdown-menu').on('click', 'li a', (e) => {
|
||||
let $el = $(e.currentTarget);
|
||||
let fieldname;
|
||||
if ($el.attr('data-fieldname')) {
|
||||
fieldname = $el.attr('data-fieldname');
|
||||
}
|
||||
let selected_item = $el.text();
|
||||
$el.parents(`.${button_class}`).find('.filter-label').text(selected_item);
|
||||
filter.action(selected_item, fieldname);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue