[report-background] alerts on start and end

This commit is contained in:
Prateeksha Singh 2018-07-03 22:47:31 +05:30
parent f3b2dcd9b9
commit ffd3b8ec44
2 changed files with 22 additions and 4 deletions

View file

@ -38,8 +38,13 @@ def run_background(instance):
instance.report_end_time = frappe.utils.now()
instance.save()
frappe.publish_realtime(
'report_generated',
{"report_name": instance.report_name},
user=frappe.session.user
)
# TODO:
# Show Alert
# Send Email to user
def remove_header_meta(columns):

View file

@ -36,7 +36,8 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
let tasks = [
this.setup_defaults,
this.setup_page,
this.setup_report_wrapper
this.setup_report_wrapper,
this.setup_events
].map(fn => fn.bind(this));
this.init_promise = frappe.run_serially(tasks);
return this.init_promise;
@ -59,6 +60,16 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
this.menu_items = [];
}
setup_events() {
frappe.realtime.on("report_generated", (data) => {
if(data.report_name) {
let alert_message = `Report ${this.report_name} generated.
<a target='_blank' href="#query-report/${this.report_name}">View</a>`;
frappe.show_alert({message: alert_message, indicator: 'orange'});
}
})
}
load() {
if (frappe.get_route().length < 2) {
this.toggle_nothing_to_show(true);
@ -291,8 +302,10 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
},
callback: resolve
})).then(r => {
const data = r.message;
frappe.msgprint("Prepared report initiated successfully. Track and access results <a class='text-info' target='_blank' href="+data.redirect_url+">here</a>", "Notification");
const data = r.message;
let alert_message = `Report initiated. You can track its status
<a class='text-info' target='_blank' href=${data.redirect_url}>here</a>`;
frappe.show_alert({message: alert_message, indicator: 'orange'});
this.toggle_nothing_to_show(true);
});
}