From 6482437795f7fe8fc35aaab6fcc00d6a1fdd4630 Mon Sep 17 00:00:00 2001
From: hankhill19580 <hankhill19580@gmail.com>
Date: Wed, 15 Jul 2020 16:06:06 +0000
Subject: [PATCH] Move plugins to their own section on /home, and make it so
 that if all the elements of a section are shown, that section becomes
 hidden(so that plugins are not enabled by default)

---
 .../i2p/router/web/helpers/HomeHelper.java    | 106 +++++++++++++++++-
 apps/routerconsole/jsp/home.jsp               |  39 ++-----
 2 files changed, 111 insertions(+), 34 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/HomeHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/HomeHelper.java
index 21ac4dcdb3..c55d5233a7 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/HomeHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/HomeHelper.java
@@ -111,28 +111,113 @@ public class HomeHelper extends HelperBase {
     }
 
     public String getServices() {
+    	String table = homeTable(PROP_SERVICES, DEFAULT_SERVICES, null);
+    	if (table.length() == 0) {
+    		return "";
+    	}
+    	StringBuilder buf = new StringBuilder(1380);
+		buf.append("<div class=\"ag2\">");
+		buf.append("<h4 class=\"app\">");
+		buf.append(_t("Applications"));
+		buf.append("</h4>");
+		buf.append("<div class=\"homeapps\">");
+		buf.append(table);
+		buf.append("<br>");
+		buf.append("<div class=\"clearer\">&nbsp;</div>");
+		buf.append("</div>");
+		buf.append("</div>");
+        return buf.toString();
+    }
+    
+    /** @since 0.9.47 */
+    public String getPlugins(){
         List<App> plugins = NavHelper.getClientApps(_context);
-        return homeTable(PROP_SERVICES, DEFAULT_SERVICES, plugins);
+    	String table = pluginTable(plugins);
+    	if (table.length() == 0) {
+    		return "";
+    	}
+    	StringBuilder buf = new StringBuilder(1380);
+		buf.append("<div class=\"ag2\">");
+		buf.append("<h4 class=\"app\">");
+		buf.append(_t("Plugins"));
+		buf.append("</h4>");
+		buf.append("<div class=\"homeapps\">");
+		buf.append(table);
+		buf.append("<br>");
+		buf.append("<div class=\"clearer\">&nbsp;</div>");
+		buf.append("</div>");
+		buf.append("</div>");
+        return buf.toString();
     }
-
+    
     /** @since 0.9.44 */
     public String getConfig(){
-        return homeTable(PROP_CONFIG, DEFAULT_CONFIG, null);
+    	String table = homeTable(PROP_CONFIG, DEFAULT_CONFIG, null);
+    	if (table.length() == 0) {
+    		return "";
+    	}
+    	StringBuilder buf = new StringBuilder(1380);
+		buf.append("<div class=\"ag2\">");
+		buf.append("<h4 class=\"app\">");
+		buf.append(_t("Configuration"));
+		buf.append("</h4>");
+		buf.append("<div class=\"homeapps\">");
+		buf.append(table);
+		buf.append("<br>");
+		buf.append("<div class=\"clearer\">&nbsp;</div>");
+		buf.append("</div>");
+		buf.append("</div>");
+        return buf.toString();
     }
 
     /** @since 0.9.44 */
     public String getMonitoring(){
-        return homeTable(PROP_MONITORING, DEFAULT_MONITORING, null);
+    	String table = homeTable(PROP_MONITORING, DEFAULT_MONITORING, null);
+    	if (table.length() == 0) {
+    		return "";
+    	}
+    	StringBuilder buf = new StringBuilder(1380);
+		buf.append("<div class=\"ag2\">");
+		buf.append("<h4 class=\"app\">");
+		buf.append(_t("Developer Information"));
+		buf.append("</h4>");
+		buf.append("<div class=\"homeapps\">");
+		buf.append(table);
+		buf.append("<br>");
+		buf.append("<div class=\"clearer\">&nbsp;</div>");
+		buf.append("</div>");
+		buf.append("</div>");
+        return buf.toString();
     }
 
     public String getFavorites() {
-        return homeTable(PROP_FAVORITES, DEFAULT_FAVORITES, null);
+    	String table = homeTable(PROP_FAVORITES, DEFAULT_FAVORITES, null);
+    	if (table.length() == 0) {
+    		return "";
+    	}
+    	StringBuilder buf = new StringBuilder(1380);
+		buf.append("<div class=\"ag2\">");
+		buf.append("<h4 class=\"app\">");
+		buf.append(_t("I2P Sites"));
+		buf.append("</h4>");
+		buf.append("<div class=\"homeapps\">");
+		buf.append(table);
+		buf.append("<br>");
+		buf.append("<div class=\"clearer\">&nbsp;</div>");
+		buf.append("</div>");
+		buf.append("</div>");
+        return buf.toString();
     }
 
     public String getConfigServices() {
         return configTable(PROP_SERVICES, DEFAULT_SERVICES);
     }
 
+	/** @since 0.9.47 */
+	public String getConfigPlugins() {
+		return getPlugins();
+	}
+
     /** @since 0.9.44 */
     public String getConfigConfig() {
         return configTable(PROP_CONFIG, DEFAULT_CONFIG);
@@ -165,6 +250,14 @@ public class HomeHelper extends HelperBase {
                "\">";
     }
 
+
+	private String pluginTable(Collection<App> toAdd) {
+        Collection<App> apps = buildApps(_context, "");
+        if (toAdd != null)
+            apps.addAll(toAdd);
+        return renderApps(apps);
+	}
+
     private String homeTable(String prop, String dflt, Collection<App> toAdd) {
         String config = _context.getProperty(prop, dflt);
         Collection<App> apps = buildApps(_context, config);
@@ -223,6 +316,9 @@ public class HomeHelper extends HelperBase {
     }
 
     private String renderApps(Collection<App> apps) {
+    	if (apps.size() == 0) {
+    		return "";
+    	}
         String website = _t("Web Server");
         StringBuilder buf = new StringBuilder(1024);
         buf.append("<div class=\"appgroup\">");
diff --git a/apps/routerconsole/jsp/home.jsp b/apps/routerconsole/jsp/home.jsp
index 9ceae72da4..9cd7a8b024 100644
--- a/apps/routerconsole/jsp/home.jsp
+++ b/apps/routerconsole/jsp/home.jsp
@@ -84,34 +84,15 @@
 <%
    }  // shouldShowSearch()
 %>
-  <div class="ag2">
-    <h4 class="app"><%=intl._t("Applications")%></h4>
-    <div class="homeapps">
-      <jsp:getProperty name="homehelper" property="services" /><br>
-    <div class="clearer">&nbsp;</div>
-    </div>
-  </div>
-  <div class="ag2">
-    <h4 class="app2"><%=intl._t("Websites Inside I2P")%></h4>
-    <div class="homesites">
-      <jsp:getProperty name="homehelper" property="favorites" /><br>
-    <div class="clearer">&nbsp;</div>
-    </div>
-  </div>
-  <div class="ag2">
-    <h4 class="app"><%=intl._t("Configuration")%></h4>
-    <div class="homeconfig">
-      <jsp:getProperty name="homehelper" property="config" /><br>
-    <div class="clearer">&nbsp;</div>
-    </div>
-  </div>
-  <div class="ag2">
-    <h4 class="app"><%=intl._t("Developer Information")%></h4>
-    <div class="homedevs">
-      <jsp:getProperty name="homehelper" property="monitoring" /><br>
-    <div class="clearer">&nbsp;</div>
-    </div>
-  </div>
-</div>
+  <jsp:getProperty name="homehelper" property="services" />
+
+  <jsp:getProperty name="homehelper" property="plugins" />
+
+  <jsp:getProperty name="homehelper" property="favorites" /><br>
+
+  <jsp:getProperty name="homehelper" property="config" /><br>
+
+  <jsp:getProperty name="homehelper" property="monitoring" /><br>
+
 </div>
 </body></html>
-- 
GitLab