From cc61f4eb619d3220cdd50758f543b4bf195650a1 Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 9 Jun 2012 13:48:26 +0000 Subject: [PATCH] Some changes to enable per-page sidebar configuration from the config file --- .../net/i2p/router/web/ConfigSummaryHandler.java | 6 +++--- .../src/net/i2p/router/web/SummaryBarRenderer.java | 4 +++- .../java/src/net/i2p/router/web/SummaryHelper.java | 14 ++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigSummaryHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigSummaryHandler.java index 1f90bc495..f66880016 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigSummaryHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigSummaryHandler.java @@ -40,11 +40,11 @@ public class ConfigSummaryHandler extends FormHandler { } } else if ("1".equals(group)) { if (_action.equals(_("Use full preset"))) { - _context.router().saveConfig(SummaryHelper.PROP_SUMMARYBAR, SummaryHelper.PRESET_FULL); + _context.router().saveConfig(SummaryHelper.PROP_SUMMARYBAR + "default", SummaryHelper.PRESET_FULL); addFormNotice(_("Full summary bar preset selected.") + " " + _("Summary bar will refresh shortly.")); } else if (_action.equals(_("Use reduced preset"))) { - _context.router().saveConfig(SummaryHelper.PROP_SUMMARYBAR, SummaryHelper.PRESET_SHORT); + _context.router().saveConfig(SummaryHelper.PROP_SUMMARYBAR + "default", SummaryHelper.PRESET_SHORT); addFormNotice(_("Reduced summary bar preset selected.") + " " + _("Summary bar will refresh shortly.")); } else { @@ -115,7 +115,7 @@ public class ConfigSummaryHandler extends FormHandler { } } } - SummaryHelper.saveSummaryBarSections(_context, sections); + SummaryHelper.saveSummaryBarSections(_context, "default", sections); addFormError(_("Saved order of sections.") + " " + _("Summary bar will refresh shortly.")); } else { diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java index c8d4aacc5..b7767c6ad 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java @@ -59,8 +59,10 @@ public class SummaryBarRenderer { * on lower-level directory errors. */ public void renderSummaryHTML(Writer out) throws IOException { + String requestURI = _helper.getRequestURI(); + String page = requestURI.replace("/", "").replace(".jsp", ""); + List sections = _helper.getSummaryBarSections(page); StringBuilder buf = new StringBuilder(8*1024); - List sections = _helper.getSummaryBarSections(); for (String section : sections) { // Commented out because broken. Replaced by if-elseif blob below. /*try { diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java index 882e3c563..23aac0791 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java @@ -40,7 +40,7 @@ public class SummaryHelper extends HelperBase { //static final String THINSP = " / "; static final String THINSP = " / "; private static final char S = ','; - static final String PROP_SUMMARYBAR = "routerconsole.summaryBar"; + static final String PROP_SUMMARYBAR = "routerconsole.summaryBar."; static final String PRESET_FULL = "HelpAndFAQ" + S + @@ -747,16 +747,18 @@ public class SummaryHelper extends HelperBase { public void storeNewsHelper(NewsHelper n) { _newshelper = n; } public NewsHelper getNewsHelper() { return _newshelper; } - public List getSummaryBarSections() { - String config = _context.getProperty(PROP_SUMMARYBAR, PRESET_FULL); + public List getSummaryBarSections(String page) { + String config = _context.getProperty(PROP_SUMMARYBAR + page, null); + if (config == null) + config = _context.getProperty(PROP_SUMMARYBAR + "default", PRESET_FULL); return Arrays.asList(config.split("" + S)); } - static void saveSummaryBarSections(RouterContext ctx, Map sections) { + static void saveSummaryBarSections(RouterContext ctx, String page, Map sections) { StringBuilder buf = new StringBuilder(512); for(String section : sections.values()) buf.append(section).append(S); - ctx.router().saveConfig(PROP_SUMMARYBAR, buf.toString()); + ctx.router().saveConfig(PROP_SUMMARYBAR + page, buf.toString()); } /** output the summary bar to _out */ @@ -785,7 +787,7 @@ public class SummaryHelper extends HelperBase { public String getConfigTable() { String[] allSections = SummaryBarRenderer.ALL_SECTIONS; - List sections = getSummaryBarSections(); + List sections = getSummaryBarSections("default"); TreeSet sortedSections = new TreeSet(); for (int i = 0; i < allSections.length; i++) {