From 51c5a3c6f1b7c4cccfdaaf17300f9b0a11aed7c1 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Mon, 1 Oct 2018 12:15:23 +0300 Subject: [WebUI] Change symbols order without updating history --- interface/js/app/history.js | 80 ++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 33 deletions(-) (limited to 'interface/js/app') diff --git a/interface/js/app/history.js b/interface/js/app/history.js index 3d1983b23..ca6b21c47 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -42,6 +42,7 @@ define(["jquery", "footable", "humanize"], "=": "=" }; var htmlEscaper = /[&<>"'/`=]/g; + var symbols = []; var symbolDescriptions = {}; var escapeHTML = function (string) { @@ -112,32 +113,43 @@ define(["jquery", "footable", "humanize"], }; } - function process_history_v2(data) { - // Display no more than rcpt_lim recipients - var rcpt_lim = 3; - var items = []; + function get_compare_function() { + var compare_functions = { + magnitude: function (e1, e2) { + return Math.abs(e2.score) - Math.abs(e1.score); + }, + name: function (e1, e2) { + return e1.name.localeCompare(e2.name); + }, + score: function (e1, e2) { + return e2.score - e1.score; + } + }; function getSelector(id) { var e = document.getElementById(id); return e.options[e.selectedIndex].value; } - var compare = null; - switch (getSelector("selSymOrder")) { - case "score": - compare = function (e1, e2) { - return e2.score - e1.score; - }; - break; - case "name": - compare = function (e1, e2) { - return e1.name.localeCompare(e2.name); - }; - break; - default: - compare = function (e1, e2) { - return Math.abs(e2.score) - Math.abs(e1.score); - }; - } + + return compare_functions[getSelector("selSymOrder")]; + } + + function sort_symbols(o, compare_function) { + return Object.keys(o) + .map(function (key) { + return o[key]; + }) + .sort(compare_function) + .map(function (e) { return e.str; }) + .join("
\n"); + } + + function process_history_v2(data) { + // Display no more than rcpt_lim recipients + var rcpt_lim = 3; + var items = []; + var unsorted_symbols = []; + var compare_function = get_compare_function(); $("#selSymOrder, label[for='selSymOrder']").show(); @@ -182,15 +194,10 @@ define(["jquery", "footable", "humanize"], if (sym.options) { str += "[" + sym.options.join(",") + "]"; } - item.symbols[key].str = str; + sym.str = str; }); - item.symbols = Object.keys(item.symbols) - .map(function (key) { - return item.symbols[key]; - }) - .sort(compare) - .map(function (e) { return e.str; }) - .join("
\n"); + unsorted_symbols.push(item.symbols); + item.symbols = sort_symbols(item.symbols, compare_function); item.time = { value: unix_time_format(item.unix_time), options: { @@ -224,7 +231,7 @@ define(["jquery", "footable", "humanize"], items.push(item); }); - return items; + return {items:items, symbols:unsorted_symbols}; } function process_history_legacy(data) { @@ -262,7 +269,7 @@ define(["jquery", "footable", "humanize"], items.push(item); }); - return items; + return {items:items}; } function columns_v2() { @@ -660,7 +667,9 @@ define(["jquery", "footable", "humanize"], // Legacy version data = [].concat.apply([], neighbours_data); } - var items = process_history_data(data); + var o = process_history_data(data); + var items = o.items; + symbols = o.symbols; if (Object.prototype.hasOwnProperty.call(tables, "history") && version === prevVersion) { @@ -694,7 +703,12 @@ define(["jquery", "footable", "humanize"], ui.getHistory(rspamd, tables); }); $("#selSymOrder").unbind().change(function () { - ui.getHistory(rspamd, tables); + var compare_function = get_compare_function(); + $.each(tables.history.rows.all, function (i, row) { + var cell_val = sort_symbols(symbols[i], compare_function); + row.cells[8].val(cell_val, false, true); + }); + drawTooltips(); }); // @reset history log -- cgit v1.2.3