diff options
-rw-r--r-- | .eslintrc.json | 6 | ||||
-rw-r--r-- | interface/js/app/graph.js | 36 | ||||
-rw-r--r-- | interface/js/app/history.js | 7 | ||||
-rw-r--r-- | interface/js/app/rspamd.js | 1 | ||||
-rw-r--r-- | interface/js/app/stats.js | 64 |
5 files changed, 60 insertions, 54 deletions
diff --git a/.eslintrc.json b/.eslintrc.json index fd33c6de2..ccd26cc74 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -28,6 +28,7 @@ "multiline-comment-style": "off", "multiline-ternary": ["error", "always-multiline"], "newline-per-chained-call": ["error", { "ignoreChainWithDepth": 5 }], + "no-continue": "off", "no-extra-parens": ["error", "functions"], "no-implicit-globals": "off", "no-magic-numbers": "off", @@ -42,6 +43,7 @@ "padded-blocks": "off", "prefer-arrow-callback": "off", "prefer-destructuring": "off", + "prefer-spread": "off", "prefer-template": "off", "quote-props" : ["error", "consistent-as-needed"], "require-jsdoc": "off", @@ -54,13 +56,10 @@ // Temporarily disabled rules - "array-callback-return": "off", "array-element-newline": "off", - "consistent-return": "off", "consistent-this": "off", "func-style": "off", "function-paren-newline": "off", - "guard-for-in": "off", "line-comment-position": "off", "max-len": "off", "max-lines": "off", @@ -69,7 +68,6 @@ "no-invalid-this": "off", "no-underscore-dangle": "off", "one-var-declaration-per-line": "off", - "prefer-spread": "off", "sort-keys": "off", "sort-vars": "off" } 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 = { |