aboutsummaryrefslogtreecommitdiffstats
path: root/interface
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-09-21 10:48:33 +0100
committerGitHub <noreply@github.com>2018-09-21 10:48:33 +0100
commit99123a5910bf905c4d1e6c5f8a2865a75c709f58 (patch)
tree35d793dcc4a3e84a626861d93dd48cb1a51d45f2 /interface
parentceb02b73ac502c16862c475528262997e035bb45 (diff)
parent47cad9a73265359c182191f9146c5fa22b6846f9 (diff)
downloadrspamd-99123a5910bf905c4d1e6c5f8a2865a75c709f58.tar.gz
rspamd-99123a5910bf905c4d1e6c5f8a2865a75c709f58.zip
Merge pull request #2512 from moisseev/eslint
[WebUI] Fix throughput data consolidation
Diffstat (limited to 'interface')
-rw-r--r--interface/js/app/graph.js36
-rw-r--r--interface/js/app/history.js7
-rw-r--r--interface/js/app/rspamd.js1
-rw-r--r--interface/js/app/stats.js64
4 files changed, 58 insertions, 50 deletions
diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js
index bdd4da3fb..c148434ca 100644
--- a/interface/js/app/graph.js
+++ b/interface/js/app/graph.js
@@ -120,7 +120,7 @@ define(["jquery", "d3evolution", "footable"],
var timeInterval = xExtents[1] - xExtents[0];
return json.map(function (curr, i) {
- // Time intervals that don't have data are excluded from average calculation as d3.mean()ignores nulls
+ // Time intervals that don't have data are excluded from average calculation as d3.mean()ignores nulls
var avg = d3.mean(curr, function (d) { return d.y; });
// To find an integral on the whole time interval we need to convert nulls to zeroes
var value = d3.mean(curr, function (d) { return Number(d.y); }) * timeInterval / scaleFactor;
@@ -224,36 +224,40 @@ define(["jquery", "d3evolution", "footable"],
rspamd.query("graph", {
success: function (req_data) {
+ var data = null;
var neighbours_data = req_data
.filter(function (d) { return d.status; }) // filter out unavailable neighbours
.map(function (d) { return d.data; });
- if (neighbours_data.length > 1) {
- neighbours_data.reduce(function (res, curr) {
+ if (neighbours_data.length === 1) {
+ data = neighbours_data[0];
+ } else {
+ var time_match = true;
+ neighbours_data.reduce(function (res, curr, _, arr) {
if ((curr[0][0].x !== res[0][0].x) ||
(curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
+ time_match = false;
rspamd.alertMessage("alert-error",
"Neighbours time extents do not match. Check if time is synchronized on all servers.");
- updateWidgets();
- return;
+ arr.splice(1); // Break out of .reduce() by mutating the source array
}
+ return curr;
+ });
- var data = [];
- curr.forEach(function (action, j) {
- data.push(
- action.map(function (d, i) {
+ if (time_match) {
+ data = neighbours_data.reduce(function (res, curr) {
+ return curr.map(function (action, j) {
+ return action.map(function (d, i) {
return {
x: d.x,
y: (res[j][i].y === null) ? d.y : res[j][i].y + d.y
};
- })
- );
+ });
+ });
});
- updateWidgets(data);
- });
- } else {
- updateWidgets(neighbours_data[0]);
+ }
}
+ updateWidgets(data);
},
errorMessage: "Cannot receive throughput data",
errorOnceId: "alerted_graph_",
@@ -262,7 +266,7 @@ define(["jquery", "d3evolution", "footable"],
};
ui.setup = function () {
- // Handling mouse events on overlapping elements
+ // Handling mouse events on overlapping elements
$("#rrd-pie").mouseover(function () {
$("#rrd-pie").css("z-index", "200");
$("#rrd-table_toggle").css("z-index", "300");
diff --git a/interface/js/app/history.js b/interface/js/app/history.js
index 1aab72456..68e66924e 100644
--- a/interface/js/app/history.js
+++ b/interface/js/app/history.js
@@ -61,13 +61,14 @@ define(["jquery", "footable", "humanize"],
function preprocess_item(item) {
for (var prop in item) {
+ if (!{}.hasOwnProperty.call(item, prop)) continue;
switch (prop) {
case "rcpt_mime":
case "rcpt_smtp":
escape_HTML_array(item[prop]);
break;
case "symbols":
- Object.keys(item.symbols).map(function (key) {
+ Object.keys(item.symbols).forEach(function (key) {
var sym = item.symbols[key];
if (!sym.name) {
sym.name = key;
@@ -155,7 +156,7 @@ define(["jquery", "footable", "humanize"],
}
preprocess_item(item);
- Object.keys(item.symbols).map(function (key) {
+ Object.keys(item.symbols).forEach(function (key) {
var str = null;
var sym = item.symbols[key];
@@ -614,6 +615,7 @@ define(["jquery", "footable", "humanize"],
waitForRowsDisplayed(callback, i);
}, 500);
}
+ return null;
}
rspamd.query("history", {
@@ -627,6 +629,7 @@ define(["jquery", "footable", "humanize"],
"Neighbours history backend versions do not match. Cannot display history.");
return true;
}
+ return false;
}
var neighbours_data = req_data
diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js
index 1d41bd85b..fde541285 100644
--- a/interface/js/app/rspamd.js
+++ b/interface/js/app/rspamd.js
@@ -54,6 +54,7 @@ function ($, D3pie, visibility, NProgress, tab_stat, tab_graph, tab_config,
function stopTimers() {
for (var key in timer_id) {
+ if (!{}.hasOwnProperty.call(timer_id, key)) continue;
Visibility.stop(timer_id[key]);
}
}
diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js
index e9f0b8f2d..c7b0228c0 100644
--- a/interface/js/app/stats.js
+++ b/interface/js/app/stats.js
@@ -67,7 +67,7 @@ define(["jquery", "d3pie", "humanize"],
$.each(data, function (i, item) {
var widget = "";
- if (i === "auth" || i === "error") { return true; } // Skip to the next iteration
+ if (i === "auth" || i === "error") return; // Skip to the next iteration
if (i === "version") {
widget = "<div class=\"left\"><strong>" + item + "</strong>" +
i + "</div>";
@@ -136,37 +136,37 @@ define(["jquery", "d3pie", "humanize"],
function getChart(rspamd, pie, checked_server) {
var creds = JSON.parse(sessionStorage.getItem("Credentials"));
- if (creds && creds[checked_server]) {
- var data = creds[checked_server].data;
- var new_data = [{
- color: "#66CC00",
- label: "Clean",
- data: data.clean,
- value: data.clean
- }, {
- color: "#BF8040",
- label: "Temporarily rejected",
- data: data.soft_reject,
- value: data.soft_reject
- }, {
- color: "#FFAD00",
- label: "Probable spam",
- data: data.probable,
- value: data.probable
- }, {
- color: "#436EEE",
- label: "Greylisted",
- data: data.greylist,
- value: data.greylist
- }, {
- color: "#FF0000",
- label: "Rejected",
- data: data.reject,
- value: data.reject
- }];
-
- return rspamd.drawPie(pie, "chart", new_data);
- }
+ if (!creds || !creds[checked_server]) return null;
+
+ var data = creds[checked_server].data;
+ var new_data = [{
+ color: "#66CC00",
+ label: "Clean",
+ data: data.clean,
+ value: data.clean
+ }, {
+ color: "#BF8040",
+ label: "Temporarily rejected",
+ data: data.soft_reject,
+ value: data.soft_reject
+ }, {
+ color: "#FFAD00",
+ label: "Probable spam",
+ data: data.probable,
+ value: data.probable
+ }, {
+ color: "#436EEE",
+ label: "Greylisted",
+ data: data.greylist,
+ value: data.greylist
+ }, {
+ color: "#FF0000",
+ label: "Rejected",
+ data: data.reject,
+ value: data.reject
+ }];
+
+ return rspamd.drawPie(pie, "chart", new_data);
}
// Public API
var ui = {