]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Fix tables destroying 2454/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Sat, 1 Sep 2018 12:25:11 +0000 (15:25 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Sat, 1 Sep 2018 12:25:11 +0000 (15:25 +0300)
It seems there is a bug in Footable.
FooTable doesn't remove the table body if the table was initialized without contents.

interface/js/app/graph.js
interface/js/app/history.js

index a70f09f4c7a960c05c79347d58be3a6837cf3a43..9776fef0fff9cb083a6f74d4d8831420d8d394f1 100644 (file)
@@ -138,26 +138,7 @@ define(["jquery", "d3evolution", "footable"],
             }, []);
         }
 
-        function updateSummaryTable(tables, data) {
-            var total_messages = 0;
-            var rows = data.map(function (curr, i) {
-                total_messages += curr.value;
-                return {
-                    options: {
-                        style: {
-                            color: graph_options.legend.entries[i].color
-                        }
-                    },
-                    value: curr
-                };
-            }, []);
-
-            document.getElementById("rrd-total-value").innerHTML = total_messages;
-
-            tables.rrd_summary.rows.load(rows);
-        }
-
-        function initSummaryTable(tables, data, unit) {
+        function initSummaryTable(tables, rows, unit) {
             tables.rrd_summary = FooTable.init("#rrd-table", {
                 sorting: {
                     enabled: true
@@ -170,19 +151,30 @@ define(["jquery", "d3evolution", "footable"],
                     {name: "max", title: "Maximum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""},
                     {name: "last", title: "Last, " + unit},
                 ],
-                on: {
-                    "ready.ft.table": function () {
-                        updateSummaryTable(tables, data);
-                    }
-                }
+                rows: rows
             });
         }
 
         function drawRrdTable(tables, data, unit) {
+            var total_messages = 0;
+            var rows = data.map(function (curr, i) {
+                total_messages += curr.value;
+                return {
+                    options: {
+                        style: {
+                            color: graph_options.legend.entries[i].color
+                        }
+                    },
+                    value: curr
+                };
+            }, []);
+
+            document.getElementById("rrd-total-value").innerHTML = total_messages;
+
             if (Object.prototype.hasOwnProperty.call(tables, "rrd_summary")) {
-                updateSummaryTable(tables, data);
+                tables.rrd_summary.rows.load(rows);
             } else {
-                initSummaryTable(tables, data, unit);
+                initSummaryTable(tables, rows, unit);
             }
         }
 
index 3863fece48508501136df3deba34a7c3617bb8e4..a6c0802538b6e42075db4de9b699a404cdee5785 100644 (file)
@@ -705,22 +705,7 @@ define(["jquery", "footable", "humanize"],
             });
         };
 
-        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) {
+        function initErrorsTable(tables, rows) {
             tables.errors = FooTable.init("#errorsLog", {
                 columns: [
                     {sorted: true, direction: "DESC", name:"ts", title:"Time", style:{"font-size":"11px", "width":300, "maxWidth":300}},
@@ -730,6 +715,7 @@ 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: rows,
                 paging: {
                     enabled: true,
                     limit: 5,
@@ -742,11 +728,6 @@ define(["jquery", "footable", "humanize"],
                 },
                 sorting: {
                     enabled: true
-                },
-                on: {
-                    "ready.ft.table": function () {
-                        updateErrorsTable(tables, data);
-                    }
                 }
             });
         }
@@ -756,10 +737,21 @@ define(["jquery", "footable", "humanize"],
 
             rspamd.query("errors", {
                 success: function (data) {
+                    var neighbours_data = data
+                        .filter(function (d) {
+                            return d.status;
+                        }) // filter out unavailable neighbours
+                        .map(function (d) {
+                            return d.data;
+                        });
+                    var rows = [].concat.apply([], neighbours_data);
+                    $.each(rows, function (i, item) {
+                        item.ts = unix_time_format(item.ts);
+                    });
                     if (Object.prototype.hasOwnProperty.call(tables, "errors")) {
-                        updateErrorsTable(tables, data);
+                        tables.errors.rows.load(rows);
                     } else {
-                        initErrorsTable(tables, data);
+                        initErrorsTable(tables, rows);
                     }
                 }
             });