From 7c1795c497e631f3c12ac85293bdc3a2e21eaa76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Thu, 31 May 2018 17:58:51 +0200 Subject: [PATCH] [Web] Fix initial drawing of Rspamd plot --- data/web/js/debug.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/data/web/js/debug.js b/data/web/js/debug.js index d5724ae6..838fd3c2 100644 --- a/data/web/js/debug.js +++ b/data/web/js/debug.js @@ -346,13 +346,15 @@ jQuery(function($){ } } }); + } + function plot_rspamd() { $.ajax({ url: '/api/v1/get/rspamd/actions', success: function(data){ var total = 0; $(data).map(function(){total += this[1];}) rspamd_labels = $.makeArray($(data).map(function(){return "
" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%
";})); - window.rspamd_donut = $.jqplot('rspamd_donut', [data], + rspamd_donut = $.jqplot('rspamd_donut', [data], { seriesDefaults: { renderer: jQuery.jqplot.DonutRenderer, @@ -378,11 +380,9 @@ jQuery(function($){ } } ); - window.rspamd_donut.replot({}); } }); } - function process_table_data(data, table) { if (table == 'rspamd_history') { $.each(data, function (i, item) { @@ -538,7 +538,15 @@ jQuery(function($){ var timer; clearTimeout(timer); timer = setTimeout(function () { - rspamd_donut.replot({}); + if (typeof rspamd_donut !== 'undefined') { + rspamd_donut.replot({}); + } }, 500); }); + $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + var target = $(e.target).attr("href"); + if ((target == '#tab-rspamd-history')) { + plot_rspamd(); + } + }); });