Browse Source

[WebUI] Change symbols order without updating history

tags/1.8.1
Alexander Moisseev 5 years ago
parent
commit
51c5a3c6f1
2 changed files with 48 additions and 34 deletions
  1. 1
    1
      .eslintrc.json
  2. 47
    33
      interface/js/app/history.js

+ 1
- 1
.eslintrc.json View File

@@ -23,7 +23,7 @@
"singleLine": { "afterColon": false }
}],
"max-params": ["warn", 6],
"max-statements": ["warn", 28],
"max-statements": ["warn", 30],
"max-statements-per-line": ["error", { "max": 2 }],
"multiline-comment-style": "off",
"multiline-ternary": ["error", "always-multiline"],

+ 47
- 33
interface/js/app/history.js View File

@@ -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("<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

Loading…
Cancel
Save