]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Avoid errors table reinitialization
authorAlexander Moisseev <moiseev@mezonplus.ru>
Sun, 26 Aug 2018 19:50:24 +0000 (22:50 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Sun, 26 Aug 2018 19:50:24 +0000 (22:50 +0300)
.eslintrc.json
interface/js/app/history.js

index d830552025b76ee7096577c7fba26653756aeae3..c0f1eeb4b7c3f8c1dda8d548b81a4727ed0c5f1f 100644 (file)
@@ -19,7 +19,7 @@
         "id-length": ["error", { "min": 1 }],
         // "max-len": ["error", { "code": 120 }],
         "max-params": ["warn", 9],
-        "max-statements": ["warn", 27],
+        "max-statements": ["warn", 28],
         "max-statements-per-line": ["error", { "max": 2 }],
         "multiline-comment-style": "off",
         "multiline-ternary": ["error", "always-multiline"],
index af64c5c63279702a5b7cc15d45109aee315321e6..3863fece48508501136df3deba34a7c3617bb8e4 100644 (file)
@@ -705,13 +705,22 @@ define(["jquery", "footable", "humanize"],
             });
         };
 
-        function drawErrorsTable(tables, data) {
-            var items = [];
-            $.each(data, function (i, item) {
-                items.push(
-                    item.ts = unix_time_format(item.ts)
-                );
+        function updateErrorsTable(tables, data) {
+            var neighbours_data = data
+                .filter(function (d) {
+                    return d.status;
+                }) // filter out unavailable neighbours
+                .map(function (d) {
+                    return d.data;
+                });
+            var flattened_data = [].concat.apply([], neighbours_data);
+            $.each(flattened_data, function (i, item) {
+                item.ts = unix_time_format(item.ts);
             });
+            tables.errors.rows.load(flattened_data);
+        }
+
+        function initErrorsTable(tables, data) {
             tables.errors = FooTable.init("#errorsLog", {
                 columns: [
                     {sorted: true, direction: "DESC", name:"ts", title:"Time", style:{"font-size":"11px", "width":300, "maxWidth":300}},
@@ -721,7 +730,6 @@ define(["jquery", "footable", "humanize"],
                     {name:"id", title:"Internal ID", style:{"font-size":"11px"}},
                     {name:"message", title:"Message", breakpoints:"xs sm", style:{"font-size":"11px"}},
                 ],
-                rows: data,
                 paging: {
                     enabled: true,
                     limit: 5,
@@ -734,6 +742,11 @@ define(["jquery", "footable", "humanize"],
                 },
                 sorting: {
                     enabled: true
+                },
+                on: {
+                    "ready.ft.table": function () {
+                        updateErrorsTable(tables, data);
+                    }
                 }
             });
         }
@@ -742,15 +755,12 @@ define(["jquery", "footable", "humanize"],
             if (rspamd.read_only) return;
 
             rspamd.query("errors", {
-                success: function (req_data) {
-                    var neighbours_data = req_data
-                        .filter(function (d) {
-                            return d.status;
-                        }) // filter out unavailable neighbours
-                        .map(function (d) {
-                            return d.data;
-                        });
-                    drawErrorsTable(tables, [].concat.apply([], neighbours_data));
+                success: function (data) {
+                    if (Object.prototype.hasOwnProperty.call(tables, "errors")) {
+                        updateErrorsTable(tables, data);
+                    } else {
+                        initErrorsTable(tables, data);
+                    }
                 }
             });