diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-01 21:16:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-01 21:16:23 +0100 |
commit | 45f1f3661a6ad55400f537f6f78ca26468266dc5 (patch) | |
tree | 54bf7074b5284aedf1f51faf835f867590a25e4c | |
parent | 62646da93b1d5145878f79db88b21ce8367ef99d (diff) | |
parent | c0195310bbf2d836f047dcb5691577da79ad88b9 (diff) | |
download | rspamd-45f1f3661a6ad55400f537f6f78ca26468266dc5.tar.gz rspamd-45f1f3661a6ad55400f537f6f78ca26468266dc5.zip |
Merge pull request #2454 from moisseev/eslint
[WebUI] Fix tables destroying
-rw-r--r-- | interface/js/app/graph.js | 55 | ||||
-rw-r--r-- | interface/js/app/history.js | 38 | ||||
-rw-r--r-- | interface/js/app/rspamd.js | 4 |
3 files changed, 40 insertions, 57 deletions
diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index 12e6b4676..9776fef0f 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -28,7 +28,6 @@ define(["jquery", "d3evolution", "footable"], function ($, D3Evolution) { "use strict"; - var ft; var rrd_pie_config = { header: {}, @@ -139,7 +138,24 @@ define(["jquery", "d3evolution", "footable"], }, []); } - function updateSummaryTable(data) { + function initSummaryTable(tables, rows, unit) { + tables.rrd_summary = FooTable.init("#rrd-table", { + sorting: { + enabled: true + }, + columns: [ + {name: "label", title: "Action"}, + {name: "value", title: "Messages", defaultContent: ""}, + {name: "min", title: "Minimum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, + {name: "avg", title: "Average, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, + {name: "max", title: "Maximum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, + {name: "last", title: "Last, " + unit}, + ], + rows: rows + }); + } + + function drawRrdTable(tables, data, unit) { var total_messages = 0; var rows = data.map(function (curr, i) { total_messages += curr.value; @@ -155,42 +171,17 @@ define(["jquery", "d3evolution", "footable"], document.getElementById("rrd-total-value").innerHTML = total_messages; - ft.rows.load(rows); - } - - function initSummaryTable(data, unit) { - return FooTable.init("#rrd-table", { - sorting: { - enabled: true - }, - columns: [ - {name: "label", title: "Action"}, - {name: "value", title: "Messages", defaultContent: ""}, - {name: "min", title: "Minimum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, - {name: "avg", title: "Average, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, - {name: "max", title: "Maximum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""}, - {name: "last", title: "Last, " + unit}, - ], - on: { - "ready.ft.table": function () { - updateSummaryTable(data); - } - } - }); - } - - function drawRrdTable(data, unit) { - if (ft) { - updateSummaryTable(data); + if (Object.prototype.hasOwnProperty.call(tables, "rrd_summary")) { + tables.rrd_summary.rows.load(rows); } else { - ft = initSummaryTable(data, unit); + initSummaryTable(tables, rows, unit); } } var ui = {}; var prevUnit = "msg/s"; - ui.draw = function (rspamd, graphs, neighbours, checked_server, type) { + ui.draw = function (rspamd, graphs, tables, neighbours, checked_server, type) { function updateWidgets(data) { var rrd_summary = []; var unit = "msg/s"; @@ -224,7 +215,7 @@ define(["jquery", "d3evolution", "footable"], $(".unit").text(unit); prevUnit = unit; } - drawRrdTable(rrd_summary, unit); + drawRrdTable(tables, rrd_summary, unit); } if (!graphs.graph) { 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); } } }); diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 4cfc99954..4e0e57841 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -84,14 +84,14 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, }); break; case "#throughput_nav": - tab_graph.draw(ui, graphs, neighbours, checked_server, selData); + tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData); var autoRefresh = { hourly: 60000, daily: 300000 }; timer_id.throughput = Visibility.every(autoRefresh[selData] || 3600000, function () { - tab_graph.draw(ui, graphs, neighbours, checked_server, selData); + tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData); }); break; case "#configuration_nav": |