feat: add card from report
This commit is contained in:
parent
ba89bd948a
commit
d8192de74f
2 changed files with 106 additions and 7 deletions
|
|
@ -156,6 +156,14 @@ def get_cards_for_user(doctype, txt, searchfield, start, page_len, filters):
|
|||
conditions=conditions
|
||||
), values)
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_report_number_card(args):
|
||||
card = create_number_card(args)
|
||||
args = frappe.parse_json(args)
|
||||
args.name = card.name
|
||||
if args.dashboard:
|
||||
add_card_to_dashboard(frappe.as_json(args))
|
||||
|
||||
@frappe.whitelist()
|
||||
def add_card_to_dashboard(args):
|
||||
args = frappe.parse_json(args)
|
||||
|
|
|
|||
|
|
@ -128,10 +128,17 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
() => this.setup_progress_bar(),
|
||||
() => this.setup_page_head(),
|
||||
() => this.refresh_report(),
|
||||
() => this.add_chart_buttons_to_toolbar(true)
|
||||
() => this.add_chart_buttons_to_toolbar(true),
|
||||
() => this.add_card_button_to_toolbar(),
|
||||
]);
|
||||
}
|
||||
|
||||
add_card_button_to_toolbar() {
|
||||
this.page.add_inner_button(__("Create Card"), () => {
|
||||
this.add_card_to_dashboard();
|
||||
});
|
||||
}
|
||||
|
||||
add_chart_buttons_to_toolbar(show) {
|
||||
if (show) {
|
||||
this.page.add_inner_button(__("Set Chart"), () => {
|
||||
|
|
@ -148,6 +155,62 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
}
|
||||
}
|
||||
|
||||
add_card_to_dashboard() {
|
||||
let field_options = frappe.report_utils.get_field_options_from_report(this.columns, this.raw_data);
|
||||
const dialog = new frappe.ui.Dialog({
|
||||
title: __('Create Card'),
|
||||
fields: [
|
||||
{
|
||||
fieldname: 'report_field',
|
||||
label: __('Field'),
|
||||
fieldtype: 'Select',
|
||||
options: field_options.numeric_fields,
|
||||
},
|
||||
{
|
||||
fieldname: 'cb_1',
|
||||
fieldtype: 'Column Break'
|
||||
},
|
||||
{
|
||||
fieldname: 'report_function',
|
||||
label: __('Function'),
|
||||
options: ['Sum', 'Average', 'Minimum', 'Maximum'],
|
||||
fieldtype: 'Select'
|
||||
},
|
||||
{
|
||||
fieldname: 'sb_1',
|
||||
label: __('Add to Dashboard'),
|
||||
fieldtype: 'Section Break'
|
||||
},
|
||||
{
|
||||
fieldname: 'dashboard',
|
||||
label: __('Choose Dashboard'),
|
||||
fieldtype: 'Link',
|
||||
options: 'Dashboard',
|
||||
},
|
||||
{
|
||||
fieldname: 'cb_2',
|
||||
fieldtype: 'Column Break'
|
||||
},
|
||||
{
|
||||
fieldname: 'label',
|
||||
label: __('Card Label'),
|
||||
fieldtype: 'Data',
|
||||
}
|
||||
],
|
||||
primary_action_label: __('Add'),
|
||||
primary_action: (values) => {
|
||||
if (!values.label) {
|
||||
values.label = `${values.report_function} of ${toTitle(values.report_field)}`;
|
||||
}
|
||||
this.create_number_card(values, values.dashboard, values.label);
|
||||
dialog.hide();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
add_chart_to_dashboard() {
|
||||
if (this.chart_fields || this.chart_options) {
|
||||
const dialog = new frappe.ui.Dialog({
|
||||
|
|
@ -182,6 +245,24 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
}
|
||||
}
|
||||
|
||||
create_number_card(values, dashboard_name, card_name) {
|
||||
let args = {
|
||||
'dashboard': dashboard_name || null,
|
||||
'type': 'Report',
|
||||
'report_name': this.report_name,
|
||||
'filters_json': JSON.stringify(this.get_filter_values()),
|
||||
};
|
||||
Object.assign(args, values);
|
||||
|
||||
this.add_to_dashboard(
|
||||
'frappe.desk.doctype.number_card.number_card.create_report_number_card',
|
||||
args,
|
||||
dashboard_name,
|
||||
card_name,
|
||||
'Number Card'
|
||||
);
|
||||
}
|
||||
|
||||
create_dashboard_chart(chart_args, dashboard_name, chart_name) {
|
||||
let args = {
|
||||
'dashboard': dashboard_name || null,
|
||||
|
|
@ -224,19 +305,29 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
);
|
||||
}
|
||||
|
||||
frappe.xcall(
|
||||
this.add_to_dashboard(
|
||||
'frappe.desk.doctype.dashboard_chart.dashboard_chart.create_report_chart',
|
||||
args,
|
||||
dashboard_name,
|
||||
chart_name,
|
||||
'Dashboard Chart'
|
||||
);
|
||||
}
|
||||
|
||||
add_to_dashboard(method, args, dashboard_name, name, doctype) {
|
||||
frappe.xcall(
|
||||
method,
|
||||
{args: args}
|
||||
).then( () => {
|
||||
).then(() => {
|
||||
let message;
|
||||
if (dashboard_name) {
|
||||
let dashboard_route_html = `<a href = "#dashboard/${dashboard_name}">${dashboard_name}</a>`;
|
||||
message = __(`New Dashboard Chart ${chart_name} added to Dashboard ` + dashboard_route_html);
|
||||
message = __(`New {0} {1} added to Dashboard ` + dashboard_route_html, [doctype, name]);
|
||||
} else {
|
||||
message = __(`New chart ${chart_name} created`);
|
||||
message = __(`New {0} {1} created`, [doctype, name]);
|
||||
}
|
||||
|
||||
frappe.msgprint(message, __('New Chart Created'));
|
||||
frappe.msgprint(message, __(`New {0} Created`, [doctype]));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -700,7 +791,7 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
|
||||
open_create_chart_dialog() {
|
||||
const me = this;
|
||||
let field_options = frappe.report_utils.get_possible_chart_options(this.columns, this.raw_data);
|
||||
let field_options = frappe.report_utils.get_field_options_from_report(this.columns, this.raw_data);
|
||||
|
||||
function set_chart_values(values) {
|
||||
values.y_fields = [];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue