feat: add button to reset default chart config

This commit is contained in:
prssanna 2020-04-02 11:35:55 +05:30
parent f79a43d5f3
commit a50492eae4
2 changed files with 26 additions and 6 deletions

View file

@ -27,13 +27,17 @@ def get_permission_query_conditions(user):
return '''(`tabDashboard Settings`.name = '{user}')'''.format(user=user)
@frappe.whitelist()
def save_chart_config(config, chart_name):
config = frappe.parse_json(config)
def save_chart_config(reset, config, chart_name):
reset = frappe.parse_json(reset)
doc = frappe.get_doc('Dashboard Settings', frappe.session.user)
chart_config = frappe.parse_json(doc.chart_config) or {}
if not chart_name in chart_config:
if reset:
chart_config[chart_name] = {}
else:
config = frappe.parse_json(config)
if not chart_name in chart_config:
chart_config[chart_name] = {}
chart_config[chart_name].update(config)
chart_config[chart_name].update(config)
frappe.db.set_value('Dashboard Settings', frappe.session.user, 'chart_config', json.dumps(chart_config))

View file

@ -243,7 +243,7 @@ export default class ChartWidget extends Widget {
}
},
{
label: __("Edit..."),
label: __("Edit"),
action: "action-edit",
handler: () => {
frappe.set_route(
@ -252,6 +252,15 @@ export default class ChartWidget extends Widget {
this.chart_doc.name
);
}
},
{
label: __("Reset Chart"),
action: "action-list",
handler: () => {
this.reset_chart();
delete this.dashboard_chart;
this.make_chart();
}
}
];
@ -359,10 +368,17 @@ export default class ChartWidget extends Widget {
dialog.set_values(this.filters);
}
save_chart_config_for_user(config) {
reset_chart() {
this.save_chart_config_for_user(null, 1);
this.chart_settings = {};
this.filters = null;
}
save_chart_config_for_user(config, reset=0) {
Object.assign(this.chart_settings, config);
frappe.xcall('frappe.desk.doctype.dashboard_settings.dashboard_settings.save_chart_config',
{
'reset': reset,
'config': this.chart_settings,
'chart_name': this.chart_doc.chart_name
});