aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-11-20 11:06:17 +0000
committerGitHub <noreply@github.com>2020-11-20 11:06:17 +0000
commitb163ba4b7256c089382148092e0bab8792ead3a4 (patch)
treee27c4b97877d4f585541728a8f31d039bbdea22a
parente2f131f592910225996dc7156749bf93b4d12135 (diff)
parent94744ca826eec8bb8d755af28bca63a350104f60 (diff)
downloadrspamd-b163ba4b7256c089382148092e0bab8792ead3a4.tar.gz
rspamd-b163ba4b7256c089382148092e0bab8792ead3a4.zip
Merge pull request #3555 from moisseev/webui
[WebUI] Add History tab autorefreshing
-rw-r--r--interface/index.html11
-rw-r--r--interface/js/app/graph.js1
-rw-r--r--interface/js/app/history.js1
-rw-r--r--interface/js/app/rspamd.js31
-rw-r--r--interface/js/app/stats.js1
5 files changed, 40 insertions, 5 deletions
diff --git a/interface/index.html b/interface/index.html
index a3810804b..ea118dcfc 100644
--- a/interface/index.html
+++ b/interface/index.html
@@ -63,6 +63,17 @@
<div class="dropdown-divider preset" role="separator"></div>
<a class="dropdown-item preset" href="#" data-value="3600000">1 hour</a>
+ <a class="dropdown-item history active" href="#" data-value=null>Disable</a>
+ <div class="dropdown-divider history" role="separator"></div>
+ <a class="dropdown-item history" href="#" data-value="10000">10 seconds</a>
+ <a class="dropdown-item history" href="#" data-value="30000">30 seconds</a>
+ <div class="dropdown-divider history" role="separator"></div>
+ <a class="dropdown-item history" href="#" data-value="60000">1 minute</a>
+ <a class="dropdown-item history" href="#" data-value="600000">10 minutes</a>
+ <a class="dropdown-item history" href="#" data-value="1800000">30 minutes</a>
+ <div class="dropdown-divider history" role="separator"></div>
+ <a class="dropdown-item history" href="#" data-value="3600000">1 hour</a>
+
<a class="dropdown-item dynamic" href="#" data-value=null>Disable</a>
<div class="dropdown-divider dynamic" role="separator"></div>
<a class="dropdown-item dynamic active" href="#" id="dynamic-item" data-value="3600000">1 hour</a>
diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js
index d2e3c5ac6..54daf79c1 100644
--- a/interface/js/app/graph.js
+++ b/interface/js/app/graph.js
@@ -285,6 +285,7 @@ define(["jquery", "d3evolution", "footable"],
}
updateWidgets(data);
},
+ complete: function () { $("#refresh").removeAttr("disabled").removeClass("disabled"); },
errorMessage: "Cannot receive throughput data",
errorOnceId: "alerted_graph_",
data: {type:type}
diff --git a/interface/js/app/history.js b/interface/js/app/history.js
index e9642d26a..edf9e19cf 100644
--- a/interface/js/app/history.js
+++ b/interface/js/app/history.js
@@ -370,6 +370,7 @@ define(["jquery", "footable"],
rspamd.destroyTable("history");
}
},
+ complete: function () { $("#refresh").removeAttr("disabled").removeClass("disabled"); },
errorMessage: "Cannot receive history",
});
};
diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js
index 360ba603e..7fb985347 100644
--- a/interface/js/app/rspamd.js
+++ b/interface/js/app/rspamd.js
@@ -91,7 +91,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
var tab_id = id;
if ($(id).attr("disabled")) return;
var navBarControls = $("#selSrv, #navBar li, #navBar a, #navBar button");
- navBarControls.attr("disabled", true).addClass("disabled", true);
+ if (id !== "#autoRefresh") navBarControls.attr("disabled", true).addClass("disabled", true);
stopTimers();
@@ -126,6 +126,8 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
if (!refreshInterval) return;
timer_id[timer] = Visibility.every(refreshInterval, function () {
countdown(refreshInterval);
+ if ($("#refresh").attr("disabled")) return;
+ $("#refresh").attr("disabled", true).addClass("disabled", true);
callback();
});
}
@@ -145,6 +147,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
if (id !== "#autoRefresh") tab_stat.statWidgets(ui, graphs, checked_server);
$(".preset").show();
+ $(".history").hide();
$(".dynamic").hide();
}());
break;
@@ -165,6 +168,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
if (id !== "#autoRefresh") tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData);
$(".preset").hide();
+ $(".history").hide();
$(".dynamic").show();
}());
break;
@@ -176,8 +180,20 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
tab_symbols.getSymbols(ui, tables, checked_server);
break;
case "#history_nav":
- tab_history.getHistory(ui, tables);
- tab_history.getErrors(ui, tables);
+ (function () {
+ function getHistoryAndErrors() {
+ tab_history.getHistory(ui, tables);
+ tab_history.getErrors(ui, tables);
+ }
+ var refreshInterval = $(".dropdown-menu a.active.history").data("value");
+ setAutoRefresh(refreshInterval, "history",
+ function () { return getHistoryAndErrors(); });
+ if (id !== "#autoRefresh") getHistoryAndErrors();
+
+ $(".preset").hide();
+ $(".history").show();
+ $(".dynamic").hide();
+ }());
break;
case "#disconnect":
disconnect();
@@ -186,6 +202,9 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
}
setTimeout(function () {
+ // Do not enable Refresh button until AJAX requests to all neighbours are finished
+ if (tab_id === "#history_nav") navBarControls = $(navBarControls).not("#refresh");
+
navBarControls.removeAttr("disabled").removeClass("disabled");
}, (id === "#autoRefresh") ? 0 : 1000);
}
@@ -367,6 +386,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
} else {
alertMessage("alert-error", "Request failed");
}
+ if (o.complete) o.complete();
NProgress.done();
}
},
@@ -414,7 +434,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
$(".dropdown-menu a").click(function (e) {
e.preventDefault();
var classList = $(this).attr("class");
- var menuClass = (/\b(?:dynamic|preset)\b/).exec(classList)[0];
+ var menuClass = (/\b(?:dynamic|history|preset)\b/).exec(classList)[0];
$(".dropdown-menu a.active." + menuClass).removeClass("active");
$(this).addClass("active");
tabClick("#autoRefresh");
@@ -597,6 +617,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
* @param {string} url - A string containing the URL to which the request is sent
* @param {Object} [options] - A set of key/value pairs that configure the Ajax request. All settings are optional.
*
+ * @param {Function} [options.complete] - A function to be called when the requests to all neighbours complete.
* @param {Object|string|Array} [options.data] - Data to be sent to the server.
* @param {Function} [options.error] - A function to be called if the request fails.
* @param {string} [options.errorMessage] - Text to display in the alert message if the request fails.
@@ -615,7 +636,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
// Force options to be an object
var o = options || {};
Object.keys(o).forEach(function (option) {
- if (["data", "error", "errorMessage", "errorOnceId", "headers", "method", "params", "server", "statusCode",
+ if (["complete", "data", "error", "errorMessage", "errorOnceId", "headers", "method", "params", "server", "statusCode",
"success"]
.indexOf(option) < 0) {
throw new Error("Unknown option: " + option);
diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js
index 582c5017f..b674d25c3 100644
--- a/interface/js/app/stats.js
+++ b/interface/js/app/stats.js
@@ -367,6 +367,7 @@ define(["jquery", "d3pie"],
});
}, promises.length ? 100 : 0);
},
+ complete: function () { $("#refresh").removeAttr("disabled").removeClass("disabled"); },
errorMessage: "Cannot receive stats data",
errorOnceId: "alerted_stats_",
server: "All SERVERS"