aboutsummaryrefslogtreecommitdiffstats
path: root/interface/js/app
diff options
context:
space:
mode:
authorAlexander Moisseev <moiseev@mezonplus.ru>2018-10-01 12:15:23 +0300
committerAlexander Moisseev <moiseev@mezonplus.ru>2018-10-01 12:15:23 +0300
commit51c5a3c6f1b7c4cccfdaaf17300f9b0a11aed7c1 (patch)
tree36c37d387cf68c532225cf62caa4ff14fc18321a /interface/js/app
parent09c208bda19a1c46fdb7f2750f70cc2c30e2d15f (diff)
downloadrspamd-51c5a3c6f1b7c4cccfdaaf17300f9b0a11aed7c1.tar.gz
rspamd-51c5a3c6f1b7c4cccfdaaf17300f9b0a11aed7c1.zip
[WebUI] Change symbols order without updating history
Diffstat (limited to 'interface/js/app')
-rw-r--r--interface/js/app/history.js80
1 files changed, 47 insertions, 33 deletions
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"],
"=": "&#x3D;"
};
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("<br>\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("<br>\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