I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Unverified Commit 76d8d911 authored by zzz's avatar zzz
Browse files

Console: Add link to sort netdb country chart by count

parent 67c09c69
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ public class NetDbHelper extends FormHandler {
private String _routerPrefix;
private String _version;
private String _country;
private String _family, _caps, _ip, _sybil, _mtu, _ssucaps, _ipv6, _transport, _hostname;
private String _family, _caps, _ip, _sybil, _mtu, _ssucaps, _ipv6, _transport, _hostname, _sort;
private int _full, _port, _cost, _page, _mode;
private long _date;
private int _limit = DEFAULT_LIMIT;
......@@ -217,6 +217,12 @@ public class NetDbHelper extends FormHandler {
_page = 0;
} catch (NumberFormatException nfe) {}
}
/** @since 0.9.57 */
public void setSort(String f) {
_sort = f;
}
/**
* call for non-text-mode browsers
......@@ -309,6 +315,8 @@ public class NetDbHelper extends FormHandler {
} else if (_full == 4) {
renderLookupForm();
} else {
if (_full == 0 && _sort != null)
_full = 3;
renderer.renderStatusHTML(_out, _limit, _page, _full);
}
} catch (IOException ioe) {
......
......@@ -847,6 +847,7 @@ class NetDbRenderer {
/**
* @param mode 0: charts only; 1: full routerinfos; 2: abbreviated routerinfos
* mode 3: Same as 0 but sort countries by count
*/
public void renderStatusHTML(Writer out, int pageSize, int page, int mode) throws IOException {
if (!_context.netDb().isInitialized()) {
......@@ -1005,9 +1006,24 @@ class NetDbRenderer {
// country table
List<String> countryList = new ArrayList<String>(countries.objects());
if (!countryList.isEmpty()) {
Collections.sort(countryList, new CountryComparator());
if (mode == 3)
Collections.sort(countryList, new CountryCountComparator(countries));
else
Collections.sort(countryList, new CountryComparator());
buf.append("<table id=\"netdbcountrylist\">\n");
buf.append("<tr><th align=\"left\">" + _t("Country") + "</th><th>" + _t("Count") + "</th></tr>\n");
buf.append("<tr><th align=\"left\">");
if (mode == 3)
buf.append("<a href=\"/netdb\" title=\"").append(_t("Sort by country")).append("\">");
buf.append(_t("Country"));
if (mode == 3)
buf.append("</a>");
buf.append("</th><th>");
if (mode == 0)
buf.append("<a href=\"/netdb?s=1\" title=\"").append(_t("Sort by count")).append("\">");
buf.append(_t("Count"));
if (mode == 0)
buf.append("</a>");
buf.append("</th></tr>\n");
for (String country : countryList) {
int num = countries.count(country);
buf.append("<tr><td><a href=\"/netdb?c=").append(country).append("\">");
......@@ -1073,6 +1089,31 @@ class NetDbRenderer {
}
}
/**
* Reverse sort by count, then forward by translated name.
*
* @since 0.9.57
*/
private class CountryCountComparator implements Comparator<String> {
private static final long serialVersionUID = 1L;
private final ObjectCounter<String> counts;
private final Collator coll;
public CountryCountComparator(ObjectCounter<String> counts) {
super();
this.counts = counts;
coll = Collator.getInstance(new Locale(Messages.getLanguage(_context)));
}
public int compare(String l, String r) {
int rv = counts.count(r) - counts.count(l);
if (rv != 0)
return rv;
return coll.compare(getTranslatedCountry(l),
getTranslatedCountry(r));
}
}
/**
* Sort by style, then host
* @since 0.9.38
......
......@@ -38,6 +38,7 @@
<jsp:setProperty name="formhandler" property="mode" value="<%=request.getParameter(\"m\")%>" />
<jsp:setProperty name="formhandler" property="date" value="<%=request.getParameter(\"date\")%>" />
<jsp:setProperty name="formhandler" property="leaseset" value="<%=request.getParameter(\"ls\")%>" />
<jsp:setProperty name="formhandler" property="sort" value="<%=request.getParameter(\"s\")%>" />
<%@include file="formhandler.jsi" %>
<jsp:getProperty name="formhandler" property="netDbSummary" />
</div></body></html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment