Work on banlist

This commit is contained in:
calzoneman 2014-01-09 17:43:07 -06:00
parent 8554c38c7d
commit 501a22556a
3 changed files with 80 additions and 21 deletions

View File

@ -48,7 +48,10 @@ function sendJade(res, view, locals) {
}); });
cache[view] = fn; cache[view] = fn;
} }
var start = Date.now();
var html = cache[view](merge(locals)); var html = cache[view](merge(locals));
var end = Date.now();
console.log(view + " " + (end - start) + "ms");
res.send(html); res.send(html);
} }

View File

@ -444,27 +444,8 @@ Callbacks = {
banlist: function(entries) { banlist: function(entries) {
var tbl = $("#cs-banlist table"); var tbl = $("#cs-banlist table");
tbl.find("tbody").remove(); tbl.data("entries", entries);
for(var i = 0; i < entries.length; i++) { formatCSBanlist();
var tr = $("<tr/>");
var remove = $("<button/>").addClass("btn btn-xs btn-danger")
.appendTo($("<td/>").appendTo(tr));
$("<span/>").addClass("glyphicon glyphicon-remove-circle").appendTo(remove);
var ip = $("<td/>").text(entries[i].ip).appendTo(tr);
var name = $("<td/>").text(entries[i].name).appendTo(tr);
var bannedby = $("<td/>").text(entries[i].bannedby).appendTo(tr);
(function (reason) {
reason = "Kept spamming links";
tr.popover({
title: "Ban Reason",
content: reason,
placement: "left",
trigger: "hover"
});
})(entries[i].reason);
tr.appendTo(tbl);
}
}, },
recentLogins: function(entries) { recentLogins: function(entries) {

View File

@ -1763,3 +1763,78 @@ function formatCSModList() {
tr.appendTo(tbl); tr.appendTo(tbl);
}); });
} }
function formatCSBanlist() {
var tbl = $("#cs-banlist table");
tbl.find("tbody").remove();
var entries = tbl.data("entries") || [];
var sparse = {};
for (var i = 0; i < entries.length; i++) {
if (!(entries[i].name in sparse)) {
sparse[entries[i].name] = [];
}
sparse[entries[i].name].push(entries[i]);
}
var flat = [];
for (var name in sparse) {
flat.push({
name: name,
bans: sparse[name]
});
}
flat.sort(function (a, b) {
var x = a.name.toLowerCase(),
y = b.name.toLowerCase();
return x === y ? 0 : (x > y ? 1 : -1);
});
var addBanRow = function (entry, after) {
var tr = $("<tr/>");
if (after) {
tr.insertAfter(after);
} else {
tr.appendTo(tbl);
}
var unban = $("<button/>").addClass("btn btn-xs btn-danger")
.appendTo($("<td/>").appendTo(tr));
$("<span/>").addClass("glyphicon glyphicon-remove-circle").appendTo(unban);
$("<td/>").text(entry.ip).appendTo(tr);
$("<td/>").text(entry.name).appendTo(tr);
$("<td/>").text(entry.bannedby).appendTo(tr);
tr.popover({
title: "Ban Reason",
content: entry.reason,
placement: "left",
trigger: "hover"
});
return tr;
};
flat.forEach(function (person) {
var bans = person.bans;
var name = person.name;
var first = addBanRow(bans.shift());
if (bans.length > 0) {
var showmore = $("<button/>").addClass("btn btn-xs btn-default pull-right");
$("<span/>").addClass("glyphicon glyphicon-list").appendTo(showmore);
showmore.appendTo(first.find("td")[1]);
showmore.click(function () {
if (showmore.data("elems")) {
showmore.data("elems").forEach(function (e) {
e.remove();
});
showmore.data("elems", null);
} else {
var elems = [];
bans.forEach(function (b) {
elems.push(addBanRow(b, first));
});
showmore.data("elems", elems);
}
});
}
});
}