From: Alexander Moisseev Date: Sat, 1 Sep 2018 12:25:11 +0000 (+0300) Subject: [WebUI] Fix tables destroying X-Git-Tag: 1.8.0~194^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F2454%2Fhead;p=rspamd.git [WebUI] Fix tables destroying It seems there is a bug in Footable. FooTable doesn't remove the table body if the table was initialized without contents. --- diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index a70f09f4c..9776fef0f 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -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, " + unit + "", 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); } } diff --git a/interface/js/app/history.js b/interface/js/app/history.js index 3863fece4..a6c080253 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -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); } } });