Rearrange summary bar code to consolidate Ajax and IFrame, and /home and /console

Now, Ajax will be used first, and will fall back to IFrame if JS is disabled,
and a separate page if on a text or mobile browser.
Also, /home and /console (and everywhere) now all have the same summary bar
content, which currently defaults to the original full listing.
This commit is contained in:
str4d
2012-06-05 12:44:17 +00:00
parent 531c6c0f4c
commit 52a3860717
9 changed files with 79 additions and 96 deletions

View File

@ -18,12 +18,6 @@ public class NewsHelper extends ContentHelper {
return super.getContent(); return super.getContent();
} }
/** @since 0.9.1 */
public String getNewsHeadings() {
SummaryBarRenderer renderer = new SummaryBarRenderer(_context, this);
return renderer.renderNewsHeadingsHTML();
}
/** @since 0.8.12 */ /** @since 0.8.12 */
public boolean shouldShowNews() { public boolean shouldShowNews() {
return NewsFetcher.getInstance(_context).shouldShowNews(); return NewsFetcher.getInstance(_context).shouldShowNews();

View File

@ -15,6 +15,7 @@ import net.i2p.router.RouterContext;
* *
*/ */
public class SummaryBarRenderer { public class SummaryBarRenderer {
// Commented out because broken. Replaced by if-elseif blob below.
/*static final Map<String, java.lang.reflect.Method> ALL_SECTIONS; /*static final Map<String, java.lang.reflect.Method> ALL_SECTIONS;
static { static {
Map<String, java.lang.reflect.Method> aMap = new HashMap<String, java.lang.reflect.Method>();; Map<String, java.lang.reflect.Method> aMap = new HashMap<String, java.lang.reflect.Method>();;
@ -42,20 +43,10 @@ public class SummaryBarRenderer {
private final RouterContext _context; private final RouterContext _context;
private final SummaryHelper _helper; private final SummaryHelper _helper;
private final NewsHelper _newshelper;
public SummaryBarRenderer(RouterContext context, SummaryHelper helper) { public SummaryBarRenderer(RouterContext context, SummaryHelper helper) {
this(context, helper, null);
}
public SummaryBarRenderer(RouterContext context, NewsHelper newshelper) {
this(context, null, newshelper);
}
public SummaryBarRenderer(RouterContext context, SummaryHelper helper, NewsHelper newshelper) {
_context = context; _context = context;
_helper = helper; _helper = helper;
_newshelper = newshelper;
} }
/** /**
@ -64,25 +55,9 @@ public class SummaryBarRenderer {
*/ */
public void renderSummaryHTML(Writer out) throws IOException { public void renderSummaryHTML(Writer out) throws IOException {
StringBuilder buf = new StringBuilder(8*1024); StringBuilder buf = new StringBuilder(8*1024);
String theme = _context.getProperty(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
// TODO - the bar would render more cleanly if we specified the img height and width here,
// but unfortunately the images in the different themes are different sizes.
// They range in height from 37 to 43 px. But there's a -2 bottom margin...
// So put it in a div.
buf.append("<div style=\"height: 36px;\"><a href=\"/\" target=\"_top\"><img src=\"")
.append(CSSHelper.BASE_THEME_PATH)
.append(theme)
.append("/images/i2plogo.png\" alt=\"")
.append(_("I2P Router Console"))
.append("\" title=\"")
.append(_("I2P Router Console"))
.append("\"></a></div>\n");
out.write(buf.toString());
String[] sections = _helper.getSummaryBarSections(); String[] sections = _helper.getSummaryBarSections();
for (int i = 0; i < sections.length; i++) { for (int i = 0; i < sections.length; i++) {
// Commented out because broken. Replaced by if-elseif blob below.
/*try { /*try {
String section = (String)ALL_SECTIONS.get(sections[i]).invoke(this); String section = (String)ALL_SECTIONS.get(sections[i]).invoke(this);
if (section != null && section != "") { if (section != null && section != "") {
@ -546,7 +521,9 @@ public class SummaryBarRenderer {
/** @since 0.9.1 */ /** @since 0.9.1 */
public String renderNewsHeadingsHTML() { public String renderNewsHeadingsHTML() {
if (_newshelper == null || _newshelper.shouldShowNews()) return ""; if (_helper == null) return "";
NewsHelper newshelper = _helper.getNewsHelper();
if (newshelper == null || newshelper.shouldShowNews()) return "";
StringBuilder buf = new StringBuilder(512); StringBuilder buf = new StringBuilder(512);
String consoleNonce = System.getProperty("router.consoleNonce"); String consoleNonce = System.getProperty("router.consoleNonce");
if (consoleNonce != null) { if (consoleNonce != null) {
@ -555,7 +532,7 @@ public class SummaryBarRenderer {
.append(_("News & Updates")) .append(_("News & Updates"))
.append("</a></h3><hr class=\"b\"><div class=\"newsheadings\">\n"); .append("</a></h3><hr class=\"b\"><div class=\"newsheadings\">\n");
// Get news content. // Get news content.
String newsContent = _newshelper.getContent(); String newsContent = newshelper.getContent();
if (newsContent != "") { if (newsContent != "") {
buf.append("<ul>\n"); buf.append("<ul>\n");
// Parse news content for headings. // Parse news content for headings.

View File

@ -739,6 +739,10 @@ public class SummaryHelper extends HelperBase {
return buf.toString(); return buf.toString();
} }
private NewsHelper _newshelper;
public void storeNewsHelper(NewsHelper n) { _newshelper = n; }
public NewsHelper getNewsHelper() { return _newshelper; }
public String[] getSummaryBarSections() { public String[] getSummaryBarSections() {
String config = _context.getProperty(PROP_SUMMARYBAR, PRESET_FULL); String config = _context.getProperty(PROP_SUMMARYBAR, PRESET_FULL);
return config.split("" + S); return config.split("" + S);

View File

@ -6,7 +6,13 @@
<html><head> <html><head>
<%@include file="css.jsi" %> <%@include file="css.jsi" %>
<%=intl.title("home")%> <%=intl.title("home")%>
</head><body> <script src="/js/ajax.js" type="text/javascript"></script>
<script type="text/javascript">
var failMessage = "<hr><b><%=intl._("Router is down")%><\/b>";
function requestAjax1() { ajax("/xhr1.jsp", "xhr", 15000); }
function initAjax() { setTimeout(requestAjax1, 15000); }
</script>
</head><body onload="initAjax()">
<% <%
String consoleNonce = System.getProperty("router.consoleNonce"); String consoleNonce = System.getProperty("router.consoleNonce");
if (consoleNonce == null) { if (consoleNonce == null) {
@ -15,16 +21,13 @@
} }
%> %>
<%@include file="summary.jsi" %><h1><%=intl._("I2P Router Console")%></h1> <%@include file="summary.jsi" %>
<h1><%=intl._("I2P Router Console")%></h1>
<div class="news" id="news"> <div class="news" id="news">
<jsp:useBean class="net.i2p.router.web.NewsHelper" id="newshelper" scope="request" />
<jsp:setProperty name="newshelper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<% <%
if (newshelper.shouldShowNews()) { if (newshelper.shouldShowNews()) {
java.io.File fpath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml");
%> %>
<jsp:setProperty name="newshelper" property="page" value="<%=fpath.getAbsolutePath()%>" />
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
<jsp:getProperty name="newshelper" property="content" /> <jsp:getProperty name="newshelper" property="content" />
<hr> <hr>
<% <%

View File

@ -6,7 +6,7 @@
<%=intl.title("home")%> <%=intl.title("home")%>
<script src="/js/ajax.js" type="text/javascript"></script> <script src="/js/ajax.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
var failMessage = "<b><%=intl._("Router is down")%><\/b>"; var failMessage = "<hr><b><%=intl._("Router is down")%><\/b>";
function requestAjax1() { ajax("/xhr1.jsp", "xhr", 15000); } function requestAjax1() { ajax("/xhr1.jsp", "xhr", 15000); }
function initAjax() { setTimeout(requestAjax1, 15000); } function initAjax() { setTimeout(requestAjax1, 15000); }
</script> </script>
@ -33,7 +33,6 @@
<div style="height: 36px;"> <div style="height: 36px;">
<a href="/console"><img src="<%=intl.getTheme(request.getHeader("User-Agent"))%>images/i2plogo.png" alt="<%=intl._("I2P Router Console")%>" title="<%=intl._("I2P Router Console")%>"></a> <a href="/console"><img src="<%=intl.getTheme(request.getHeader("User-Agent"))%>images/i2plogo.png" alt="<%=intl._("I2P Router Console")%>" title="<%=intl._("I2P Router Console")%>"></a>
</div> </div>
<hr>
<div id="xhr"> <div id="xhr">
<!-- for non-script --> <!-- for non-script -->
<%@include file="xhr1.jsi" %> <%@include file="xhr1.jsi" %>

View File

@ -1,3 +1,10 @@
<jsp:useBean class="net.i2p.router.web.NewsHelper" id="newshelper" scope="request" />
<jsp:setProperty name="newshelper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<%
java.io.File newspath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml");
%>
<jsp:setProperty name="newshelper" property="page" value="<%=newspath.getAbsolutePath()%>" />
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
<div class="routersummaryouter"> <div class="routersummaryouter">
<% <%
// The refresh delay, 0 to disable // The refresh delay, 0 to disable
@ -15,7 +22,7 @@
newDelay = "?refresh=" + d; newDelay = "?refresh=" + d;
} }
if (!"0".equals(d)) if (!"0".equals(d))
out.print("<iframe src=\"/summaryframe.jsp" + newDelay + "\" height=\"1500\" width=\"200\" scrolling=\"auto\" frameborder=\"0\" title=\"sidepanel\">\n"); out.print("<noscript><iframe src=\"/summaryframe.jsp" + newDelay + "\" height=\"1500\" width=\"200\" scrolling=\"auto\" frameborder=\"0\" title=\"sidepanel\"></noscript>\n");
} }
%> %>
<div class="routersummary"> <div class="routersummary">
@ -34,11 +41,11 @@
// d and allowIFrame defined above // d and allowIFrame defined above
if (!"0".equals(d)) { if (!"0".equals(d)) {
out.print("</div></iframe>\n"); out.print("</div><noscript></iframe></noscript>\n");
} else if (allowIFrame) { } else if (allowIFrame) {
// since we don't have an iframe this will reload the base page, and // since we don't have an iframe this will reload the base page, and
// the new delay will be passed to the iframe above // the new delay will be passed to the iframe above
out.print("<div class=\"refresh\"><form action=\"" + request.getRequestURI() + "\" method=\"POST\">\n" + out.print("<noscript><div class=\"refresh\"><form action=\"" + request.getRequestURI() + "\" method=\"POST\">\n" +
"<b>"); "<b>");
// We have intl defined when this is included, but not when compiled standalone. // We have intl defined when this is included, but not when compiled standalone.
out.print(intl._("Refresh (s)")); out.print(intl._("Refresh (s)"));
@ -47,7 +54,7 @@
// ditto // ditto
out.print(intl._("Enable")); out.print(intl._("Enable"));
out.print("</button>\n" + out.print("</button>\n" +
"</form></div></div>\n"); "</form></div></noscript></div>\n");
} else { } else {
out.print("</div>\n"); out.print("</div>\n");
} }

View File

@ -52,6 +52,13 @@
} }
%> %>
</head><body style="margin: 0;"><div class="routersummary"> </head><body style="margin: 0;"><div class="routersummary">
<jsp:useBean class="net.i2p.router.web.NewsHelper" id="newshelper" scope="request" />
<jsp:setProperty name="newshelper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<%
java.io.File newspath = new java.io.File(net.i2p.I2PAppContext.getGlobalContext().getRouterDir(), "docs/news.xml");
%>
<jsp:setProperty name="newshelper" property="page" value="<%=newspath.getAbsolutePath()%>" />
<jsp:setProperty name="newshelper" property="maxLines" value="300" />
<%@include file="summarynoframe.jsi" %> <%@include file="summarynoframe.jsi" %>
<% <%
// d and shutdownSoon defined above // d and shutdownSoon defined above

View File

@ -1,35 +1,17 @@
<%@page import="net.i2p.router.web.SummaryHelper" %>
<% <%
/* /*
* Note: * TODO - the bar would render more cleanly if we specified the img height and width here,
* This is included almost 30 times, so keep whitespace etc. to a minimum. * but unfortunately the images in the different themes are different sizes.
* They range in height from 37 to 43 px. But there's a -2 bottom margin...
* So put it in a div.
*/ */
%> %>
<jsp:useBean class="net.i2p.router.web.SummaryHelper" id="helper" scope="request" /> <div style="height: 36px;">
<jsp:setProperty name="helper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" /> <a href="/" target="_top">
<jsp:setProperty name="helper" property="action" value="<%=request.getParameter(\"action\")%>" /> <img src="<%=intl.getTheme(request.getHeader("User-Agent"))%>images/i2plogo.png" alt="<%=intl._("I2P Router Console")%>" title="<%=intl._("I2P Router Console")%>">
<jsp:setProperty name="helper" property="updateNonce" value="<%=request.getParameter(\"updateNonce\")%>" /> </a>
<jsp:setProperty name="helper" property="consoleNonce" value="<%=request.getParameter(\"consoleNonce\")%>" /> </div>
<jsp:setProperty name="helper" property="requestURI" value="<%=request.getRequestURI()%>" /> <div id="xhr">
<% helper.storeWriter(out); %> <!-- for non-script -->
<% <%@include file="xhr1.jsi" %>
/* </div>
* The following is required for the reseed button to work, although we probably
* only need the reseedNonce property.
*/
%>
<jsp:useBean class="net.i2p.router.web.ReseedHandler" id="reseed" scope="request" />
<jsp:setProperty name="reseed" property="*" />
<%
/*
* The following is required for the update buttons to work, although we probably
* only need the updateNonce property.
*/
%>
<jsp:useBean class="net.i2p.router.web.UpdateHandler" id="update" scope="request" />
<jsp:setProperty name="update" property="*" />
<jsp:setProperty name="update" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<%
// moved to java for ease of translation and to avoid 30 copies
helper.renderSummaryBar();
%>

View File

@ -1,31 +1,41 @@
<%@page import="net.i2p.router.web.SummaryHelper" %>
<%
/*
* Note:
* This is included on every refresh, so keep whitespace etc. to a minimum.
*/
%>
<jsp:useBean class="net.i2p.router.web.SummaryHelper" id="helper" scope="request" /> <jsp:useBean class="net.i2p.router.web.SummaryHelper" id="helper" scope="request" />
<jsp:setProperty name="helper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" /> <jsp:setProperty name="helper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<jsp:setProperty name="helper" property="action" value="<%=request.getParameter(\"action\")%>" /> <jsp:setProperty name="helper" property="action" value="<%=request.getParameter(\"action\")%>" />
<table><tr><td align="left"><b><%=intl._("Version")%>:</b></td><td align="right">
<jsp:getProperty name="helper" property="version" />
</td></tr><tr><td align="left"><b><%=intl._("Uptime")%>:</b></td><td align="right">
<jsp:getProperty name="helper" property="uptime" />
</td></tr></table><hr>
<jsp:setProperty name="helper" property="updateNonce" value="<%=request.getParameter(\"updateNonce\")%>" /> <jsp:setProperty name="helper" property="updateNonce" value="<%=request.getParameter(\"updateNonce\")%>" />
<jsp:setProperty name="helper" property="consoleNonce" value="<%=request.getParameter(\"consoleNonce\")%>" /> <jsp:setProperty name="helper" property="consoleNonce" value="<%=request.getParameter(\"consoleNonce\")%>" />
<% <%
String reqURI = request.getRequestURI(); String reqURI = request.getRequestURI();
if (reqURI != null) if (reqURI != null)
reqURI = reqURI.replace("/xhr1.jsp", "/home"); reqURI = reqURI.replace("/xhr1.jsp", "/");
helper.setRequestURI(reqURI); helper.setRequestURI(reqURI);
%> %>
<% helper.storeWriter(out); %>
<% helper.storeNewsHelper(newshelper); %>
<% <%
if (!newshelper.shouldShowNews()) { /*
* The following is required for the reseed button to work, although we probably
* only need the reseedNonce property.
*/
%> %>
<jsp:getProperty name="newshelper" property="newsHeadings" /><hr> <jsp:useBean class="net.i2p.router.web.ReseedHandler" id="reseed" scope="request" />
<jsp:setProperty name="reseed" property="*" />
<% <%
} // !shouldShowNews() /*
* The following is required for the update buttons to work, although we probably
* only need the updateNonce property.
*/
%>
<jsp:useBean class="net.i2p.router.web.UpdateHandler" id="update" scope="request" />
<jsp:setProperty name="update" property="*" />
<jsp:setProperty name="update" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
<%
// moved to java for ease of translation
helper.renderSummaryBar();
%> %>
<jsp:getProperty name="helper" property="updateStatus" />
<h4><a href="/confignet#help" title="<%=intl._("Help with configuring your firewall and router for optimal I2P performance")%>"><%=intl._("Network")%>:
<jsp:getProperty name="helper" property="reachability" /></a></h4>
<hr>
<jsp:getProperty name="helper" property="firewallAndReseedStatus" />
<jsp:getProperty name="helper" property="destinations" />
<hr>
<jsp:getProperty name="helper" property="restartStatus" />