]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Refactor displayStatWidgets function
authormoisseev <moiseev@mezonplus.ru>
Sat, 8 Aug 2020 15:24:30 +0000 (18:24 +0300)
committermoisseev <moiseev@mezonplus.ru>
Sat, 8 Aug 2020 15:24:30 +0000 (18:24 +0300)
interface/js/app/stats.js

index 299b02aad8157f33ec435964a64c1d864b9c768f..57e16261e125523d26a30a8e87b28e8cd58f8b92 100644 (file)
@@ -56,17 +56,14 @@ define(["jquery", "d3pie"],
         }
 
         function displayStatWidgets(checked_server) {
-            var widgets = $("#statWidgets");
-            $(widgets).empty().hide();
-
             var servers = JSON.parse(sessionStorage.getItem("Credentials"));
             var data = {};
-
             if (servers && servers[checked_server]) {
                 data = servers[checked_server].data;
             }
-            var stat_w = [];
 
+            var stat_w = [];
+            $("#statWidgets").empty().hide();
             $.each(data, function (i, item) {
                 var widgetsOrder = ["scanned", "no action", "greylist", "add header", "rewrite subject", "reject", "learned"];
 
@@ -89,7 +86,7 @@ define(["jquery", "d3pie"],
                     }
                     $('<div class="' + cls + 'float-left px-3"><strong class="d-block mt-2 mb-1 font-weight-bold">' +
                       val + "</strong>" + i + "</div>")
-                        .appendTo(widgets);
+                        .appendTo("#statWidgets");
                 } else if (i === "actions") {
                     $.each(item, function (action, count) {
                         stat_w[widgetsOrder.indexOf(action)] = widget(action, count);
@@ -99,12 +96,13 @@ define(["jquery", "d3pie"],
                 }
             });
             $.each(stat_w, function (i, item) {
-                $(item).appendTo(widgets);
+                $(item).appendTo("#statWidgets");
             });
             $("#statWidgets > div:not(.stat-box)")
                 .wrapAll('<div class="card stat-box text-center bg-light shadow-sm float-right">' +
                   '<div class="widget overflow-hidden p-2 text-capitalize"></div></div>');
             $("#statWidgets").find("div.float-right").appendTo("#statWidgets");
+            $("#statWidgets").show();
 
             $("#clusterTable tbody").empty();
             $("#selSrv").empty();
@@ -144,7 +142,6 @@ define(["jquery", "d3pie"],
                     $('#selSrv [value="' + key + '"]').prop("disabled", true);
                 }
             });
-            $(widgets).show();
         }
 
         function getChart(rspamd, pie, checked_server) {