From 8a99be1db3540e6b06d6437a58b54d2d70f2669c Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Mon, 29 Apr 2013 22:40:49 +0000 Subject: [PATCH] move page nav --- .../org/klomp/snark/web/I2PSnarkServlet.java | 161 +++++++++++------- .../resources/themes/snark/light/snark.css | 4 + .../resources/themes/snark/ubergine/snark.css | 4 + .../resources/themes/snark/vanilla/snark.css | 4 + 4 files changed, 108 insertions(+), 65 deletions(-) diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java index 64457d9459..fd1db4c082 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -378,7 +378,26 @@ public class I2PSnarkServlet extends BasicServlet { out.write("<input type=\"hidden\" name=\"st\" value=\"" + stParam + "\" >\n"); } out.write(TABLE_HEADER); - out.write("<img border=\"0\" src=\"" + _imgPath + "status.png\" title=\""); + + // Opera and text-mode browsers: no   and no input type=image values submitted + // Using a unique name fixes Opera, except for the buttons with js confirms, see below + String ua = req.getHeader("User-Agent"); + boolean isDegraded = ua != null && (ua.startsWith("Lynx") || ua.startsWith("w3m") || + ua.startsWith("ELinks") || ua.startsWith("Links") || + ua.startsWith("Dillo")); + boolean noThinsp = isDegraded || (ua != null && ua.startsWith("Opera")); + + // pages + int start = 0; + int total = snarks.size(); + if (stParam != null) { + try { + start = Math.max(0, Math.min(total - 1, Integer.parseInt(stParam))); + } catch (NumberFormatException nfe) {} + } + int pageSize = Math.max(_manager.getPageSize(), 5); + + out.write("<tr><th><img border=\"0\" src=\"" + _imgPath + "status.png\" title=\""); out.write(_("Status")); out.write("\" alt=\""); out.write(_("Status")); @@ -411,12 +430,15 @@ public class I2PSnarkServlet extends BasicServlet { } out.write("</a><br>\n"); } - out.write("</th>\n<th colspan=\"3\" align=\"left\">"); + out.write("</th>\n<th colspan=\"2\" align=\"left\">"); out.write("<img border=\"0\" src=\"" + _imgPath + "torrent.png\" title=\""); out.write(_("Torrent")); out.write("\" alt=\""); out.write(_("Torrent")); - out.write("\">"); + out.write("\"></th>\n<th align=\"center\">"); + if (total > 0 && (start > 0 || total > pageSize)) { + writePageNav(out, start, pageSize, total, peerParam, noThinsp); + } out.write("</th>\n<th align=\"right\">"); if (_manager.util().connected() && !snarks.isEmpty()) { out.write("<img border=\"0\" src=\"" + _imgPath + "eta.png\" title=\""); @@ -462,14 +484,6 @@ public class I2PSnarkServlet extends BasicServlet { } out.write("</th>\n<th align=\"center\">"); - // Opera and text-mode browsers: no   and no input type=image values submitted - // Using a unique name fixes Opera, except for the buttons with js confirms, see below - String ua = req.getHeader("User-Agent"); - boolean isDegraded = ua != null && (ua.startsWith("Lynx") || ua.startsWith("w3m") || - ua.startsWith("ELinks") || ua.startsWith("Links") || - ua.startsWith("Dillo")); - - boolean noThinsp = isDegraded || (ua != null && ua.startsWith("Opera")); if (_manager.isStopping()) { out.write(" "); } else if (_manager.util().connected()) { @@ -500,18 +514,11 @@ public class I2PSnarkServlet extends BasicServlet { } else { out.write(" "); } - out.write("</th></tr></thead>\n"); + out.write("</th></tr>\n"); + out.write("</thead>\n"); String uri = _contextPath + '/'; boolean showDebug = "2".equals(peerParam); - int start = 0; - int total = snarks.size(); - if (stParam != null) { - try { - start = Math.max(0, Math.min(total - 1, Integer.parseInt(stParam))); - } catch (NumberFormatException nfe) {} - } - int pageSize = Math.max(_manager.getPageSize(), 5); String stParamStr = stParam == null ? "" : "&st=" + stParam; for (int i = 0; i < total; i++) { Snark snark = (Snark)snarks.get(i); @@ -529,10 +536,54 @@ public class I2PSnarkServlet extends BasicServlet { } else /** if (snarks.size() > 1) */ { out.write("<tfoot><tr>\n" + " <th align=\"left\" colspan=\"6\">"); + out.write(" "); + out.write(_("Totals")); + out.write(": "); + out.write(ngettext("1 torrent", "{0} torrents", total)); + out.write(", "); + out.write(DataHelper.formatSize2(stats[5]) + "B"); + if (_manager.util().connected() && total > 0) { + out.write(", "); + out.write(ngettext("1 connected peer", "{0} connected peers", (int) stats[4])); + } + DHT dht = _manager.util().getDHT(); + if (dht != null) { + int dhts = dht.size(); + if (dhts > 0) { + out.write(", "); + out.write(ngettext("1 DHT peer", "{0} DHT peers", dhts)); + } + if (showDebug) + out.write(dht.renderStatusHTML()); + } + out.write("</th>\n"); + if (_manager.util().connected() && total > 0) { + out.write(" <th align=\"right\">" + formatSize(stats[0]) + "</th>\n" + + " <th align=\"right\">" + formatSize(stats[1]) + "</th>\n" + + " <th align=\"right\">" + formatSize(stats[2]) + "ps</th>\n" + + " <th align=\"right\">" + formatSize(stats[3]) + "ps</th>\n" + + " <th></th>"); + } else { + out.write("<th colspan=\"5\"></th>"); + } + out.write("</tr></tfoot>\n"); + } + + out.write("</table>"); + if (isForm) + out.write("</form>\n"); + return start == 0; + } + + /** + * @since 0.9.6 + */ + private void writePageNav(PrintWriter out, int start, int pageSize, int total, + String peerParam, boolean noThinsp) { // Page nav if (start > 0) { // First - out.write(" <a href=\"" + _contextPath); + out.write("<a href=\"" + _contextPath); if (peerParam != null) out.write("?p=" + peerParam); out.write("\">" + @@ -540,16 +591,25 @@ public class I2PSnarkServlet extends BasicServlet { _imgPath + "control_rewind_blue.png\">" + "</a> "); int prev = Math.max(0, start - pageSize); - if (prev > 0) { + //if (prev > 0) { + if (true) { // Back out.write(" <a href=\"" + _contextPath + "?st=" + prev); if (peerParam != null) - out.write("&p=" + peerParam); + out.write("&p=" + peerParam); out.write("\">" + "<img alt=\"" + _("Prev") + "\" title=\"" + _("Previous page") + "\" border=\"0\" src=\"" + _imgPath + "control_back_blue.png\">" + "</a> "); } + } else { + out.write( + "<img alt=\"\" border=\"0\" class=\"disable\" src=\"" + + _imgPath + "control_rewind_blue.png\">" + + " " + + "<img alt=\"\" border=\"0\" class=\"disable\" src=\"" + + _imgPath + "control_back_blue.png\">" + + " "); } // Page count int pages = 1 + ((total - 1) / pageSize); @@ -561,15 +621,17 @@ public class I2PSnarkServlet extends BasicServlet { page = pages; else page = 1 + (start / pageSize); - out.write(" " + _("Page {0}", page) + thinsp(noThinsp) + pages + " "); + //out.write(" " + _("Page {0}", page) + thinsp(noThinsp) + pages + " "); + out.write(" " + page + thinsp(noThinsp) + pages + " "); } if (start + pageSize < total) { int next = start + pageSize; - if (next + pageSize < total) { + //if (next + pageSize < total) { + if (true) { // Next out.write(" <a href=\"" + _contextPath + "?st=" + next); if (peerParam != null) - out.write("&p=" + peerParam); + out.write("&p=" + peerParam); out.write("\">" + "<img alt=\"" + _("Next") + "\" title=\"" + _("Next page") + "\" border=\"0\" src=\"" + _imgPath + "control_play_blue.png\">" + @@ -579,49 +641,19 @@ public class I2PSnarkServlet extends BasicServlet { int last = ((total - 1) / pageSize) * pageSize; out.write(" <a href=\"" + _contextPath + "?st=" + last); if (peerParam != null) - out.write("&p=" + peerParam); + out.write("&p=" + peerParam); out.write("\">" + "<img alt=\"" + _("Last") + "\" title=\"" + _("Last page") + "\" border=\"0\" src=\"" + _imgPath + "control_fastforward_blue.png\">" + "</a> "); - } - out.write(" "); - out.write(_("Totals")); - out.write(": "); - out.write(ngettext("1 torrent", "{0} torrents", total)); - out.write(", "); - out.write(DataHelper.formatSize2(stats[5]) + "B"); - if (_manager.util().connected() && total > 0) { - out.write(", "); - out.write(ngettext("1 connected peer", "{0} connected peers", (int) stats[4])); - } - DHT dht = _manager.util().getDHT(); - if (dht != null) { - int dhts = dht.size(); - if (dhts > 0) { - out.write(", "); - out.write(ngettext("1 DHT peer", "{0} DHT peers", dhts)); - } - if (showDebug) - out.write(dht.renderStatusHTML()); - } - out.write("</th>\n"); - if (_manager.util().connected() && total > 0) { - out.write(" <th align=\"right\">" + formatSize(stats[0]) + "</th>\n" + - " <th align=\"right\">" + formatSize(stats[1]) + "</th>\n" + - " <th align=\"right\">" + formatSize(stats[2]) + "ps</th>\n" + - " <th align=\"right\">" + formatSize(stats[3]) + "ps</th>\n" + - " <th></th>"); } else { - out.write("<th colspan=\"5\"></th>"); + out.write(" " + + "<img alt=\"\" border=\"0\" class=\"disable\" src=\"" + + _imgPath + "control_play_blue.png\">" + + " " + + "<img alt=\"\" border=\"0\" class=\"disable\" src=\"" + + _imgPath + "control_fastforward_blue.png\">"); } - out.write("</tr></tfoot>\n"); - } - - out.write("</table>"); - if (isForm) - out.write("</form>\n"); - return start == 0; } /** @@ -2139,8 +2171,7 @@ public class I2PSnarkServlet extends BasicServlet { private static final String TABLE_HEADER = "<table border=\"0\" class=\"snarkTorrents\" width=\"100%\" >\n" + - "<thead>\n" + - "<tr><th>"; + "<thead>\n"; private static final String FOOTER = "</div></center></body></html>"; diff --git a/installer/resources/themes/snark/light/snark.css b/installer/resources/themes/snark/light/snark.css index aa423ae6b8..428ee1d5a4 100644 --- a/installer/resources/themes/snark/light/snark.css +++ b/installer/resources/themes/snark/light/snark.css @@ -566,6 +566,10 @@ input[type=image], thead img { opacity: 1; } +thead img.disable, img.disable:hover { + opacity: 0.4; +} + input[type=image]:hover, thead img:hover { opacity: 1; } diff --git a/installer/resources/themes/snark/ubergine/snark.css b/installer/resources/themes/snark/ubergine/snark.css index 63b7b05f50..f67257262d 100644 --- a/installer/resources/themes/snark/ubergine/snark.css +++ b/installer/resources/themes/snark/ubergine/snark.css @@ -572,6 +572,10 @@ input[type=image], thead img { opacity: 0.8; } +thead img.disable, img.disable:hover { + opacity: 0.2; +} + input[type=image]:hover, thead img:hover { opacity: 1; } diff --git a/installer/resources/themes/snark/vanilla/snark.css b/installer/resources/themes/snark/vanilla/snark.css index c111ea3089..2ea324aa9b 100644 --- a/installer/resources/themes/snark/vanilla/snark.css +++ b/installer/resources/themes/snark/vanilla/snark.css @@ -424,6 +424,10 @@ table.SnarkDirInfo { padding: 0 3px !important; } +thead img.disable, img.disable:hover { + opacity: 0.4; +} + .SnarkDirInfo td { min-width: 0px !important; } -- GitLab