forked from I2P_Developers/i2p.i2p
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:
@ -18,12 +18,6 @@ public class NewsHelper extends ContentHelper {
|
||||
return super.getContent();
|
||||
}
|
||||
|
||||
/** @since 0.9.1 */
|
||||
public String getNewsHeadings() {
|
||||
SummaryBarRenderer renderer = new SummaryBarRenderer(_context, this);
|
||||
return renderer.renderNewsHeadingsHTML();
|
||||
}
|
||||
|
||||
/** @since 0.8.12 */
|
||||
public boolean shouldShowNews() {
|
||||
return NewsFetcher.getInstance(_context).shouldShowNews();
|
||||
|
@ -15,6 +15,7 @@ import net.i2p.router.RouterContext;
|
||||
*
|
||||
*/
|
||||
public class SummaryBarRenderer {
|
||||
// Commented out because broken. Replaced by if-elseif blob below.
|
||||
/*static final Map<String, java.lang.reflect.Method> ALL_SECTIONS;
|
||||
static {
|
||||
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 SummaryHelper _helper;
|
||||
private final NewsHelper _newshelper;
|
||||
|
||||
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;
|
||||
_helper = helper;
|
||||
_newshelper = newshelper;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,25 +55,9 @@ public class SummaryBarRenderer {
|
||||
*/
|
||||
public void renderSummaryHTML(Writer out) throws IOException {
|
||||
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();
|
||||
for (int i = 0; i < sections.length; i++) {
|
||||
// Commented out because broken. Replaced by if-elseif blob below.
|
||||
/*try {
|
||||
String section = (String)ALL_SECTIONS.get(sections[i]).invoke(this);
|
||||
if (section != null && section != "") {
|
||||
@ -546,7 +521,9 @@ public class SummaryBarRenderer {
|
||||
|
||||
/** @since 0.9.1 */
|
||||
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);
|
||||
String consoleNonce = System.getProperty("router.consoleNonce");
|
||||
if (consoleNonce != null) {
|
||||
@ -555,7 +532,7 @@ public class SummaryBarRenderer {
|
||||
.append(_("News & Updates"))
|
||||
.append("</a></h3><hr class=\"b\"><div class=\"newsheadings\">\n");
|
||||
// Get news content.
|
||||
String newsContent = _newshelper.getContent();
|
||||
String newsContent = newshelper.getContent();
|
||||
if (newsContent != "") {
|
||||
buf.append("<ul>\n");
|
||||
// Parse news content for headings.
|
||||
|
@ -739,6 +739,10 @@ public class SummaryHelper extends HelperBase {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private NewsHelper _newshelper;
|
||||
public void storeNewsHelper(NewsHelper n) { _newshelper = n; }
|
||||
public NewsHelper getNewsHelper() { return _newshelper; }
|
||||
|
||||
public String[] getSummaryBarSections() {
|
||||
String config = _context.getProperty(PROP_SUMMARYBAR, PRESET_FULL);
|
||||
return config.split("" + S);
|
||||
|
@ -6,7 +6,13 @@
|
||||
<html><head>
|
||||
<%@include file="css.jsi" %>
|
||||
<%=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");
|
||||
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">
|
||||
<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()) {
|
||||
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" />
|
||||
<hr>
|
||||
<%
|
||||
|
@ -6,7 +6,7 @@
|
||||
<%=intl.title("home")%>
|
||||
<script src="/js/ajax.js" type="text/javascript"></script>
|
||||
<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 initAjax() { setTimeout(requestAjax1, 15000); }
|
||||
</script>
|
||||
@ -33,7 +33,6 @@
|
||||
<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>
|
||||
</div>
|
||||
<hr>
|
||||
<div id="xhr">
|
||||
<!-- for non-script -->
|
||||
<%@include file="xhr1.jsi" %>
|
||||
|
@ -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">
|
||||
<%
|
||||
// The refresh delay, 0 to disable
|
||||
@ -15,7 +22,7 @@
|
||||
newDelay = "?refresh=" + 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">
|
||||
@ -34,11 +41,11 @@
|
||||
|
||||
// d and allowIFrame defined above
|
||||
if (!"0".equals(d)) {
|
||||
out.print("</div></iframe>\n");
|
||||
out.print("</div><noscript></iframe></noscript>\n");
|
||||
} else if (allowIFrame) {
|
||||
// since we don't have an iframe this will reload the base page, and
|
||||
// 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>");
|
||||
// We have intl defined when this is included, but not when compiled standalone.
|
||||
out.print(intl._("Refresh (s)"));
|
||||
@ -47,7 +54,7 @@
|
||||
// ditto
|
||||
out.print(intl._("Enable"));
|
||||
out.print("</button>\n" +
|
||||
"</form></div></div>\n");
|
||||
"</form></div></noscript></div>\n");
|
||||
} else {
|
||||
out.print("</div>\n");
|
||||
}
|
||||
|
@ -52,6 +52,13 @@
|
||||
}
|
||||
%>
|
||||
</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" %>
|
||||
<%
|
||||
// d and shutdownSoon defined above
|
||||
|
@ -1,35 +1,17 @@
|
||||
<%@page import="net.i2p.router.web.SummaryHelper" %>
|
||||
<%
|
||||
/*
|
||||
* Note:
|
||||
* This is included almost 30 times, so keep whitespace etc. to a minimum.
|
||||
* 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.
|
||||
*/
|
||||
%>
|
||||
<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="action" value="<%=request.getParameter(\"action\")%>" />
|
||||
<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="requestURI" value="<%=request.getRequestURI()%>" />
|
||||
<% helper.storeWriter(out); %>
|
||||
<%
|
||||
/*
|
||||
* 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();
|
||||
%>
|
||||
<div style="height: 36px;">
|
||||
<a href="/" target="_top">
|
||||
<img src="<%=intl.getTheme(request.getHeader("User-Agent"))%>images/i2plogo.png" alt="<%=intl._("I2P Router Console")%>" title="<%=intl._("I2P Router Console")%>">
|
||||
</a>
|
||||
</div>
|
||||
<div id="xhr">
|
||||
<!-- for non-script -->
|
||||
<%@include file="xhr1.jsi" %>
|
||||
</div>
|
||||
|
@ -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:setProperty name="helper" property="contextId" value="<%=(String)session.getAttribute(\"i2p.contextId\")%>" />
|
||||
<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="consoleNonce" value="<%=request.getParameter(\"consoleNonce\")%>" />
|
||||
<%
|
||||
String reqURI = request.getRequestURI();
|
||||
if (reqURI != null)
|
||||
reqURI = reqURI.replace("/xhr1.jsp", "/home");
|
||||
reqURI = reqURI.replace("/xhr1.jsp", "/");
|
||||
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" />
|
||||
|
Reference in New Issue
Block a user