feat: provision to set_route for Custom Number Card (#21806)
This commit is contained in:
parent
4888e85df1
commit
3b8aca1a43
2 changed files with 32 additions and 15 deletions
|
|
@ -96,12 +96,14 @@ frappe.ui.form.on("Number Card", {
|
|||
set_method_description: function (frm) {
|
||||
if (frm.doc.type == "Custom") {
|
||||
frm.fields_dict.method.set_description(`
|
||||
Set the path to a whitelisted function that will return the number on the card in the format:
|
||||
Set the path to a whitelisted function that will return the data for the number card in the format:
|
||||
<pre class="small text-muted">
|
||||
<code>
|
||||
{
|
||||
"value": value,
|
||||
"fieldtype": "Currency"
|
||||
"fieldtype": "Currency",
|
||||
"route_options": {"from_date": "2023-05-23"},
|
||||
"route": ["query-report", "Permitted Documents For User"]
|
||||
}
|
||||
</code></pre>`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,12 +64,17 @@ export default class NumberCardWidget extends Widget {
|
|||
|
||||
set_events() {
|
||||
$(this.body).click(() => {
|
||||
if (this.in_customize_mode || this.card_doc.type == "Custom") return;
|
||||
if (this.in_customize_mode) return;
|
||||
this.set_route();
|
||||
});
|
||||
}
|
||||
|
||||
set_route() {
|
||||
if (this.card_doc.type === "Custom") {
|
||||
this.set_route_for_custom_card();
|
||||
return;
|
||||
}
|
||||
|
||||
const is_document_type = this.card_doc.type !== "Report";
|
||||
const name = is_document_type ? this.card_doc.document_type : this.card_doc.report_name;
|
||||
const route = frappe.utils.generate_route({
|
||||
|
|
@ -90,6 +95,16 @@ export default class NumberCardWidget extends Widget {
|
|||
frappe.set_route(route);
|
||||
}
|
||||
|
||||
set_route_for_custom_card() {
|
||||
if (!this.data?.route) return;
|
||||
|
||||
if (this.data.route_options) {
|
||||
frappe.route_options = this.data.route_options;
|
||||
}
|
||||
|
||||
frappe.set_route(this.data.route);
|
||||
}
|
||||
|
||||
set_doc_args() {
|
||||
this.card_doc = Object.assign(
|
||||
{},
|
||||
|
|
@ -139,7 +154,7 @@ export default class NumberCardWidget extends Widget {
|
|||
return frappe.dashboard_utils.get_all_filters(this.card_doc);
|
||||
}
|
||||
|
||||
render_card() {
|
||||
async render_card() {
|
||||
this.prepare_actions();
|
||||
this.set_title();
|
||||
this.set_loading_state();
|
||||
|
|
@ -149,8 +164,10 @@ export default class NumberCardWidget extends Widget {
|
|||
}
|
||||
|
||||
this.settings = this.get_settings(this.card_doc.type);
|
||||
this.data = await this.get_data();
|
||||
|
||||
frappe.run_serially([() => this.render_number(), () => this.render_stats()]);
|
||||
this.render_number();
|
||||
this.render_stats();
|
||||
}
|
||||
|
||||
set_loading_state() {
|
||||
|
|
@ -159,10 +176,8 @@ export default class NumberCardWidget extends Widget {
|
|||
</div>`);
|
||||
}
|
||||
|
||||
get_number() {
|
||||
return frappe.xcall(this.settings.method, this.settings.args).then((res) => {
|
||||
return this.settings.get_number(res);
|
||||
});
|
||||
get_data() {
|
||||
return frappe.xcall(this.settings.method, this.settings.args);
|
||||
}
|
||||
|
||||
get_number_for_custom_card(res) {
|
||||
|
|
@ -212,15 +227,15 @@ export default class NumberCardWidget extends Widget {
|
|||
}
|
||||
|
||||
render_number() {
|
||||
return this.get_number().then(() => {
|
||||
$(this.body).html(`<div class="widget-content">
|
||||
<div class="number" style="color:${this.card_doc.color}">${this.formatted_number}</div>
|
||||
</div>`);
|
||||
});
|
||||
this.settings.get_number(this.data);
|
||||
|
||||
$(this.body).html(`<div class="widget-content">
|
||||
<div class="number" style="color:${this.card_doc.color}">${this.formatted_number}</div>
|
||||
</div>`);
|
||||
}
|
||||
|
||||
render_stats() {
|
||||
if (this.card_doc.type !== "Document Type") {
|
||||
if (this.card_doc.type !== "Document Type" || !this.card_doc.show_percentage_stats) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue