Merge pull request #10021 from rohitwaghchaure/custom_dashbaiord_options

fix: custom options not adding in the dashboard chart
This commit is contained in:
mergify[bot] 2020-04-25 13:04:52 +00:00 committed by GitHub
commit 4d8717171a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 4 deletions

View file

@ -59,6 +59,10 @@ frappe.ui.form.on('Dashboard Chart', {
if (frm.doc.report_name) {
frm.trigger('set_chart_report_filters');
}
if (!frappe.boot.developer_mode) {
frm.set_df_property("custom_options", "hidden", 1);
}
},
source: function(frm) {

View file

@ -33,6 +33,7 @@
"type",
"column_break_2",
"color",
"custom_options",
"section_break_10",
"last_synced_on"
],
@ -124,7 +125,7 @@
"fieldname": "type",
"fieldtype": "Select",
"label": "Type",
"options": "Line\nBar\nPercentage\nPie",
"options": "Line\nBar\nPercentage\nPie\nDonut",
"reqd": 1
},
{
@ -213,10 +214,16 @@
"label": "Y Axis",
"mandatory_depends_on": "eval:doc.report_name && !doc.is_custom",
"options": "Dashboard Chart Field"
},
{
"description": "Ex: \"colors\": [\"#d1d8dd\", \"#ff5858\"]",
"fieldname": "custom_options",
"fieldtype": "Code",
"label": "Custom Options"
}
],
"links": [],
"modified": "2020-04-08 18:54:36.739183",
"modified": "2020-04-20 23:49:11.389909",
"modified_by": "Administrator",
"module": "Desk",
"name": "Dashboard Chart",

View file

@ -97,6 +97,10 @@ def create_report_chart(args):
_doc = frappe.new_doc('Dashboard Chart')
_doc.update(args)
if (args.get("custom_options")):
_doc.custom_options = json.dumps(args.get("custom_options"))
if frappe.db.exists('Dashboard Chart', args.chart_name):
args.chart_name = append_number_if_name_exists('Dashboard Chart', args.chart_name)
_doc.chart_name = args.chart_name
@ -108,6 +112,7 @@ def create_report_chart(args):
@frappe.whitelist()
def add_chart_to_dashboard(args):
args = frappe.parse_json(args)
dashboard = frappe.get_doc('Dashboard', args.dashboard)
dashboard_link = frappe.new_doc('Dashboard Chart Link')
dashboard_link.chart = args.chart_name
@ -362,6 +367,8 @@ class DashboardChart(Document):
self.check_required_field()
self.check_document_type()
self.validate_custom_options()
def check_required_field(self):
if not self.document_type:
frappe.throw(_("Document type is required to create a dashboard chart"))
@ -378,3 +385,10 @@ class DashboardChart(Document):
def check_document_type(self):
if frappe.get_meta(self.document_type).issingle:
frappe.throw("You cannot create a dashboard chart from single DocTypes")
def validate_custom_options(self):
if self.custom_options:
try:
json.loads(self.custom_options)
except ValueError as error:
frappe.throw("Invalid json added in the custom options: %s" % error)

View file

@ -183,7 +183,6 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
}
create_dashboard_chart(chart_args, dashboard_name, chart_name) {
let args = {
'dashboard': dashboard_name || null,
'chart_type': 'Report',
@ -191,8 +190,15 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
'type': chart_args.chart_type || frappe.model.unscrub(chart_args.type),
'color': chart_args.color,
'filters_json': JSON.stringify(this.get_filter_values()),
'custom_options': {}
};
for (let key in chart_args) {
if (key != "data") {
args['custom_options'][key] = chart_args[key];
}
}
if (this.chart_fields) {
let x_field_title = toTitle(chart_args.x_field);
let y_field_title = toTitle(chart_args.y_fields[0]);

View file

@ -457,7 +457,8 @@ export default class ChartWidget extends Widget {
Line: "line",
Bar: "bar",
Percentage: "percentage",
Pie: "pie"
Pie: "pie",
Donut: "donut"
};
let colors = [];
@ -490,6 +491,14 @@ export default class ChartWidget extends Widget {
shortenYAxisNumbers: 1
}
};
if (this.chart_doc.custom_options) {
let custom_options = JSON.parse(this.chart_doc.custom_options);
for (let key in custom_options) {
chart_args[key] = custom_options[key];
}
}
if (!this.dashboard_chart) {
this.dashboard_chart = new frappe.Chart(
this.chart_wrapper[0],