diff --git a/frappe/core/page/dashboard/dashboard.js b/frappe/core/page/dashboard/dashboard.js index d4b1c2b444..8e2c9d6d93 100644 --- a/frappe/core/page/dashboard/dashboard.js +++ b/frappe/core/page/dashboard/dashboard.js @@ -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 = ``; - 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, diff --git a/frappe/core/page/dashboard/dashboard.py b/frappe/core/page/dashboard/dashboard.py index 0c6de7792c..dba97e11f6 100644 --- a/frappe/core/page/dashboard/dashboard.py +++ b/frappe/core/page/dashboard/dashboard.py @@ -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): diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.json b/frappe/desk/doctype/dashboard_chart/dashboard_chart.json index 1190c58830..ed0602fea2 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.json +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.json @@ -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", diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py index bcadf354e1..4431696018 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py @@ -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( diff --git a/frappe/desk/page/user_profile/user_profile.js b/frappe/desk/page/user_profile/user_profile.js index 80b5ecc797..567722a65d 100644 --- a/frappe/desk/page/user_profile/user_profile.js +++ b/frappe/desk/page/user_profile/user_profile.js @@ -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 = `
- `; - let options_html; - - if (filter.fieldnames) { - options_html = filter.options.map((option, i) => - `
  • ${option}
  • `).join(''); - } else { - options_html = filter.options.map( option => `
  • ${option}
  • `).join(''); - } - - let dropdown_html = chart_filter_html + `
    `; - 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({ diff --git a/frappe/public/build.json b/frappe/public/build.json index 3ef64e7e15..8f56d56dae 100755 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -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" ], diff --git a/frappe/public/js/frappe/utils/dashboard_utils.js b/frappe/public/js/frappe/utils/dashboard_utils.js new file mode 100644 index 0000000000..c374fe9baf --- /dev/null +++ b/frappe/public/js/frappe/utils/dashboard_utils.js @@ -0,0 +1,41 @@ +frappe.dashboard_utils = { + + render_chart_filters: function(filters, button_class, container, append) { + filters.forEach(filter => { + let chart_filter_html = ``; + 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); + }); + }); + + } +}; \ No newline at end of file