commit 99074e5: [WebUI] Fix Status tab display for scanned = 0

moisseev moiseev at mezonplus.ru
Sat Oct 3 20:21:06 UTC 2020


Author: moisseev
Date: 2020-10-02 21:27:22 +0300
URL: https://github.com/rspamd/rspamd/commit/99074e58773cad52d6b1a09e7e64ffa4f9e3f3a4 (refs/pull/3505/head)

[WebUI] Fix Status tab display for scanned = 0
Fixes:  #3498

---
 interface/js/app/stats.js | 50 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 43 insertions(+), 7 deletions(-)

diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js
index d9fda8f6a..582c5017f 100644
--- a/interface/js/app/stats.js
+++ b/interface/js/app/stats.js
@@ -199,9 +199,42 @@ define(["jquery", "d3pie"],
             }
         }
 
-        function getChart(rspamd, pie, checked_server) {
+        function getChart(rspamd, graphs, checked_server) {
+            if (graphs.chart) {
+                graphs.chart.destroy();
+                delete graphs.chart;
+            }
+
             var creds = JSON.parse(sessionStorage.getItem("Credentials"));
-            if (!creds || !creds[checked_server]) return null;
+            // Controller doesn't return the 'actions' object until at least one message is scanned
+            if (!creds || !creds[checked_server] || !creds[checked_server].data.scanned) {
+                // Show grayed out pie as percentage is undefined
+                return rspamd.drawPie(graphs.chart,
+                    "chart",
+                    [{
+                        value: 1,
+                        color: "#ffffff",
+                        label: "undefined"
+                    }],
+                    {
+                        labels: {
+                            mainLabel: {
+                                fontSize: 14,
+                            },
+                            inner: {
+                                format: "none",
+                            },
+                            lines: {
+                                color: "#cccccc"
+                            }
+                        },
+                        tooltips: {
+                            enabled: true,
+                            string: "{label}"
+                        },
+                    }
+                );
+            }
 
             var data = creds[checked_server].data.actions;
             var new_data = [{
@@ -236,7 +269,7 @@ define(["jquery", "d3pie"],
                 value: data.reject
             }];
 
-            return rspamd.drawPie(pie, "chart", new_data);
+            return rspamd.drawPie(graphs.chart, "chart", new_data);
         }
         // Public API
         var ui = {
@@ -271,9 +304,12 @@ define(["jquery", "d3pie"],
 
                         function process_node_stat(e) {
                             var data = neighbours_status[e].data;
-                            for (var action in neighbours_sum.actions) {
-                                if ({}.hasOwnProperty.call(neighbours_sum.actions, action)) {
-                                    neighbours_sum.actions[action] += data.actions[action];
+                            // Controller doesn't return the 'actions' object until at least one message is scanned
+                            if (data.scanned) {
+                                for (var action in neighbours_sum.actions) {
+                                    if ({}.hasOwnProperty.call(neighbours_sum.actions, action)) {
+                                        neighbours_sum.actions[action] += data.actions[action];
+                                    }
                                 }
                             }
                             ["learned", "scanned", "uptime"].forEach(function (p) {
@@ -327,7 +363,7 @@ define(["jquery", "d3pie"],
                                 to_Credentials["All SERVERS"].data = neighbours_sum;
                                 sessionStorage.setItem("Credentials", JSON.stringify(to_Credentials));
                                 displayStatWidgets(checked_server);
-                                graphs.chart = getChart(rspamd, graphs.chart, checked_server);
+                                graphs.chart = getChart(rspamd, graphs, checked_server);
                             });
                         }, promises.length ? 100 : 0);
                     },


More information about the Commits mailing list