From: Alexander Moisseev Date: Sun, 26 Aug 2018 19:50:24 +0000 (+0300) Subject: [WebUI] Avoid errors table reinitialization X-Git-Tag: 1.8.0~201^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=08b280f0e30d7bf6a3878265a0efe4337f5359b4;p=rspamd.git [WebUI] Avoid errors table reinitialization --- diff --git a/.eslintrc.json b/.eslintrc.json index d83055202..c0f1eeb4b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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"], diff --git a/interface/js/app/history.js b/interface/js/app/history.js index af64c5c63..3863fece4 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -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); + } } });