sorting of trust subscriptions table
This commit is contained in:
@ -74,22 +74,22 @@ public class TrustServlet extends HttpServlet {
|
||||
list.forEach(l -> l.toXML(sb));
|
||||
sb.append("</Users>");
|
||||
} else if (section.equals("subscriptions")) {
|
||||
sb.append("<Subscriptions>");
|
||||
|
||||
List<Subscription> subs = new ArrayList<>();
|
||||
|
||||
for (RemoteTrustList list : core.getTrustSubscriber().getRemoteTrustLists().values()) {
|
||||
sb.append("<Subscription>");
|
||||
sb.append("<User>").append(Util.escapeHTMLinXML(list.getPersona().getHumanReadableName())).append("</User>");
|
||||
sb.append("<UserB64>").append(list.getPersona().toBase64()).append("</UserB64>");
|
||||
sb.append("<Status>").append(list.getStatus()).append("</Status>");
|
||||
String timestamp = Util._t("Never");
|
||||
if (list.getTimestamp() > 0)
|
||||
timestamp = DataHelper.formatTime(list.getTimestamp());
|
||||
sb.append("<Timestamp>").append(timestamp).append("</Timestamp>");
|
||||
sb.append("<Trusted>").append(list.getGood().size()).append("</Trusted>");
|
||||
sb.append("<Distrusted>").append(list.getBad().size()).append("</Distrusted>");
|
||||
sb.append("</Subscription>");
|
||||
Subscription sub = new Subscription(list.getPersona(),
|
||||
list.getStatus(),
|
||||
list.getTimestamp(),
|
||||
list.getGood().size(),
|
||||
list.getBad().size());
|
||||
subs.add(sub);
|
||||
}
|
||||
|
||||
SUBSCRIPTION_COMPARATORS.sort(subs, req);
|
||||
|
||||
sb.append("<Subscriptions>");
|
||||
subs.forEach(sub -> sub.toXML(sb));
|
||||
sb.append("</Subscriptions>");
|
||||
|
||||
} else if (section.equals("list")) {
|
||||
@ -241,4 +241,62 @@ public class TrustServlet extends HttpServlet {
|
||||
USER_COMPARATORS.add("Subscribe", USER_BY_SUBSCRIBED);
|
||||
}
|
||||
|
||||
private static class Subscription {
|
||||
private final Persona persona;
|
||||
private final RemoteTrustList.Status status;
|
||||
private final long timestamp;
|
||||
private final int trusted, distrusted;
|
||||
|
||||
Subscription(Persona persona, RemoteTrustList.Status status, long timestamp,
|
||||
int trusted, int distrusted) {
|
||||
this.persona = persona;
|
||||
this.status = status;
|
||||
this.timestamp = timestamp;
|
||||
this.trusted = trusted;
|
||||
this.distrusted = distrusted;
|
||||
}
|
||||
|
||||
void toXML(StringBuilder sb) {
|
||||
sb.append("<Subscription>");
|
||||
sb.append("<User>").append(Util.escapeHTMLinXML(persona.getHumanReadableName())).append("</User>");
|
||||
sb.append("<UserB64>").append(persona.toBase64()).append("</UserB64>");
|
||||
sb.append("<Status>").append(status).append("</Status>");
|
||||
String timestampString = Util._t("Never");
|
||||
if (timestamp > 0)
|
||||
timestampString = DataHelper.formatTime(timestamp);
|
||||
sb.append("<Timestamp>").append(timestampString).append("</Timestamp>");
|
||||
sb.append("<Trusted>").append(trusted).append("</Trusted>");
|
||||
sb.append("<Distrusted>").append(distrusted).append("</Distrusted>");
|
||||
sb.append("</Subscription>");
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<Subscription> SUBSCRIPTION_BY_USER = (l, r) -> {
|
||||
return l.persona.getHumanReadableName().compareTo(r.persona.getHumanReadableName());
|
||||
};
|
||||
|
||||
private static final Comparator<Subscription> SUBSCRIPTION_BY_STATUS = (l, r) -> {
|
||||
return l.status.toString().compareTo(r.status.toString());
|
||||
};
|
||||
|
||||
private static final Comparator<Subscription> SUBSCRIPTION_BY_TIMESTAMP = (l, r) -> {
|
||||
return Long.compare(l.timestamp, r.timestamp);
|
||||
};
|
||||
|
||||
private static final Comparator<Subscription> SUBSCRIPTION_BY_TRUSTED = (l, r) -> {
|
||||
return Integer.compare(l.trusted, r.trusted);
|
||||
};
|
||||
|
||||
private static final Comparator<Subscription> SUBSCRIPTION_BY_DISTRUSTED = (l, r) -> {
|
||||
return Integer.compare(l.distrusted, r.distrusted);
|
||||
};
|
||||
|
||||
private static final ColumnComparators<Subscription> SUBSCRIPTION_COMPARATORS = new ColumnComparators<>();
|
||||
static {
|
||||
SUBSCRIPTION_COMPARATORS.add("Name", SUBSCRIPTION_BY_USER);
|
||||
SUBSCRIPTION_COMPARATORS.add("Status", SUBSCRIPTION_BY_STATUS);
|
||||
SUBSCRIPTION_COMPARATORS.add("Last Updated", SUBSCRIPTION_BY_TIMESTAMP);
|
||||
SUBSCRIPTION_COMPARATORS.add("Trusted", SUBSCRIPTION_BY_TRUSTED);
|
||||
SUBSCRIPTION_COMPARATORS.add("Distrusted", SUBSCRIPTION_BY_DISTRUSTED);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,22 @@ class TrustList {
|
||||
this.trusted = xmlNode.getElementsByTagName("Trusted")[0].childNodes[0].nodeValue
|
||||
this.distrusted = xmlNode.getElementsByTagName("Distrusted")[0].childNodes[0].nodeValue
|
||||
}
|
||||
|
||||
getMapping() {
|
||||
var mapping = new Map()
|
||||
|
||||
var userLink = new Link(this.user, "displayList", [this.user])
|
||||
var unsubscribeLink = new Link(_t("Unsubscribe"), "unsubscribe", [this.userB64])
|
||||
var refreshLink = new Link(_t("Refresh"), "forceUpdate", [this.userB64])
|
||||
|
||||
mapping.set("Name", userLink.render() + unsubscribeLink.render() + refreshLink.render())
|
||||
mapping.set("Status", this.status)
|
||||
mapping.set("Last Updated", this.timestamp)
|
||||
mapping.set("Trusted", this.trusted)
|
||||
mapping.set("Distrusted", this.distrusted)
|
||||
|
||||
return mapping
|
||||
}
|
||||
}
|
||||
|
||||
class Persona {
|
||||
@ -58,6 +74,9 @@ var lists = new Map()
|
||||
var revision = -1
|
||||
var currentUser = null
|
||||
|
||||
var listsSortKey
|
||||
var listsSortOrder
|
||||
|
||||
function markTrusted(user) {
|
||||
var linkSpan = document.getElementById("trusted-link-" + user)
|
||||
linkSpan.innerHTML = ""
|
||||
@ -207,41 +226,45 @@ function displayList(user) {
|
||||
xmlhttp.send()
|
||||
}
|
||||
|
||||
function sortSubscriptions(key, order) {
|
||||
listsSortKey = key
|
||||
listsSortOrder = order
|
||||
refreshLists()
|
||||
}
|
||||
|
||||
function refreshLists() {
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
lists.clear()
|
||||
var listOfLists = []
|
||||
var subs = this.responseXML.getElementsByTagName("Subscription")
|
||||
var i
|
||||
for (i = 0; i < subs.length; i++) {
|
||||
var trustList = new TrustList(subs[i])
|
||||
lists.set(trustList.user, trustList)
|
||||
lists.set(trustList.user, trustList)
|
||||
listOfLists.push(trustList)
|
||||
}
|
||||
|
||||
var newOrder
|
||||
if (listsSortOrder == "descending")
|
||||
newOrder = "ascending"
|
||||
else if (listsSortOrder == "ascending")
|
||||
newOrder = "descending"
|
||||
var table = new Table(["Name","Trusted","Distrusted","Status","Last Updated"], "sortSubscriptions", listsSortKey, newOrder)
|
||||
|
||||
var html = "<table><thead><tr><th>" + _t("Name") + "</th><th>" + _t("Trusted") + "</th><th>" + _t("Distrusted") + "</th><th>" + _t("Status") + "</th><th>" + _t("Last Updated") + "</th><th>" + _t("Actions") + "</th></tr></thead><tbody>"
|
||||
for (var [user, list] of lists) {
|
||||
html += "<tr>"
|
||||
html += "<td>" + "<a href='#' onclick='window.displayList(\"" + list.user + "\");return false;'>" + list.user + "</a></td>"
|
||||
html += "<td>" + list.trusted + "</td>"
|
||||
html += "<td>" + list.distrusted +"</td>"
|
||||
html += "<td>" + list.status + "</td>"
|
||||
html += "<td>" + list.timestamp + "</td>"
|
||||
html += "<td>" + "<a href='#' onclick='window.unsubscribe(\"" + list.userB64 + "\");return false;'>" + _t("Unsubscribe") + "</a>" +
|
||||
" <a href='#' onclick='window.forceUpdate(\"" + list.userB64 + "\");return false;'>" + _t("Refresh") + "</a>" +
|
||||
"</td>"
|
||||
html += "</tr>"
|
||||
for (i = 0; i < listOfLists.length; i++) {
|
||||
table.addRow(listOfLists[i].getMapping())
|
||||
}
|
||||
html += "</tbody></table>"
|
||||
|
||||
document.getElementById("trustLists").innerHTML = html
|
||||
document.getElementById("trustLists").innerHTML = table.render()
|
||||
|
||||
if (currentUser != null)
|
||||
displayList(currentUser)
|
||||
}
|
||||
}
|
||||
xmlhttp.open("GET", "/MuWire/Trust?section=subscriptions", true)
|
||||
var sortParam = "&key=" + listsSortKey + "&order=" + listsSortOrder
|
||||
xmlhttp.open("GET", encodeURI("/MuWire/Trust?section=subscriptions" + sortParam), true)
|
||||
xmlhttp.send()
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ String pagetitle=Util._t("Trust Lists");
|
||||
<head>
|
||||
<%@ include file="css.jsi"%>
|
||||
<script src="js/util.js?<%=version%>" type="text/javascript"></script>
|
||||
<script src="js/tables.js?<%=version%>" type="text/javascript"></script>
|
||||
<script src="js/trustLists.js?<%=version%>" type="text/javascript"></script>
|
||||
|
||||
</head>
|
||||
|
Reference in New Issue
Block a user