diff options
author | moisseev <moiseev@mezonplus.ru> | 2020-03-06 11:07:27 +0300 |
---|---|---|
committer | moisseev <moiseev@mezonplus.ru> | 2020-03-06 11:07:27 +0300 |
commit | fdd568d7c7cb2c68710a913f2ce2020f6337a066 (patch) | |
tree | e29cd0a50f68f174973e5876906930407ca96bbd /interface/js/app/rspamd.js | |
parent | 2e46c5ace410cc8784319d398c861b3e12b7b021 (diff) | |
download | rspamd-fdd568d7c7cb2c68710a913f2ce2020f6337a066.tar.gz rspamd-fdd568d7c7cb2c68710a913f2ce2020f6337a066.zip |
[WebUI] Add auto-refresh interval settings
Diffstat (limited to 'interface/js/app/rspamd.js')
-rw-r--r-- | interface/js/app/rspamd.js | 79 |
1 files changed, 66 insertions, 13 deletions
diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index c58b3803c..972d3c247 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -94,23 +94,68 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_ tab_id = "#" + $(".navbar-nav .active > a").attr("id"); } + $("#autoRefresh").hide(); + $(".btn-group .btn:visible").last().addClass("radius-right"); + + function setAutoRefresh(refreshInterval, timer, callback) { + function countdown(interval) { + Visibility.stop(timer_id.countdown); + if (!interval) { + $("#countdown").text("--:--"); + return; + } + + var timeLeft = interval; + $("#countdown").text("00:00"); + timer_id.countdown = Visibility.every(1000, 1000, function () { + timeLeft -= 1000; + $("#countdown").text(new Date(timeLeft).toISOString().substr(14, 5)); + if (timeLeft <= 0) Visibility.stop(timer_id.countdown); + }); + } + + $(".btn-group .btn:visible").last().removeClass("radius-right"); + $("#autoRefresh").show(); + + countdown(refreshInterval); + if (!refreshInterval) return; + timer_id[timer] = Visibility.every(refreshInterval, function () { + countdown(refreshInterval); + callback(); + }); + } + switch (tab_id) { case "#status_nav": - tab_stat.statWidgets(ui, graphs, checked_server); - timer_id.status = Visibility.every(10000, function () { - tab_stat.statWidgets(ui, graphs, checked_server); - }); + (function () { + var refreshInterval = $(".dropdown-menu li.active.preset a").data("value"); + setAutoRefresh(refreshInterval, "status", + function () { return tab_stat.statWidgets(ui, graphs, checked_server); }); + if (refreshInterval) tab_stat.statWidgets(ui, graphs, checked_server); + + $(".preset").show(); + $(".dynamic").hide(); + }()); break; case "#throughput_nav": - tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData); + (function () { + var step = { + day: 60000, + week: 300000 + }; + var refreshInterval = step[selData] || 3600000; + $("#dynamic-item").text((refreshInterval / 60000) + " min"); + + if (!$(".dropdown-menu li.active.dynamic a").data("value")) { + refreshInterval = null; + } + setAutoRefresh(refreshInterval, "throughput", + function () { return tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData); }); + if (refreshInterval) tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData); - var autoRefresh = { - day: 60000, - week: 300000 - }; - timer_id.throughput = Visibility.every(autoRefresh[selData] || 3600000, function () { - tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData); - }); + $(".preset").hide(); + $(".dynamic").show(); + }()); break; case "#configuration_nav": tab_config.getActions(ui, checked_server); @@ -233,7 +278,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_ $("#errors-history").show(); } - var buttons = $("#navBar .pull-right"); + var buttons = $("#navBar form.navbar-right"); $("#mainUI").show(); $(buttons).show(); $(".nav-tabs-sticky").stickyTabs({initialTab:"#status_nav"}); @@ -358,6 +403,14 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_ var tab_id = "#" + $(e.target).attr("id"); tabClick(tab_id); }); + $(".dropdown-menu li a").click(function (e) { + e.preventDefault(); + var classList = $(this).parent().attr("class"); + var menuClass = (/\b(?:dynamic|preset)\b/).exec(classList)[0]; + $(".dropdown-menu li.active." + menuClass).removeClass("active"); + $(this).parent("li").addClass("active"); + tabClick("#refresh"); + }); $("#selSrv").change(function () { checked_server = this.value; |