From 7aa3d6807f1e86b170f87295e45bbe65e85e0fe9 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 28 Jul 2017 17:15:07 +0300 Subject: [PATCH] Added HighCharts, Replaced Pie Graphs with Highcharts version --- Plan/pom.xml | 1 + .../plan/ui/html/DataRequestHandler.java | 4 +- .../response/JavaScriptResponse.java | 25 ++ .../djrapitops/plan/utilities/HtmlUtils.java | 2 +- .../utilities/analysis/ExportUtility.java | 4 +- Plan/src/main/resources/analysis.html | 274 +++++++----------- .../plan/utilities/HtmlUtilsTest.java | 2 +- 7 files changed, 134 insertions(+), 178 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/JavaScriptResponse.java diff --git a/Plan/pom.xml b/Plan/pom.xml index ee70cb4c3..50d990bcc 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -105,6 +105,7 @@ . ${basedir}/src/main/resources + *.js *.yml *.html diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/DataRequestHandler.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/DataRequestHandler.java index 4d7889e70..b1cadbb9d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/DataRequestHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/DataRequestHandler.java @@ -52,7 +52,7 @@ public class DataRequestHandler { return "

404 Data was not found in cache

"; } return HtmlUtils.replacePlaceholders( - HtmlUtils.getHtmlStringFromResource("player.html"), + HtmlUtils.getStringFromResource("player.html"), PlaceholderUtils.getInspectReplaceRules(data) ); } catch (FileNotFoundException ex) { @@ -71,7 +71,7 @@ public class DataRequestHandler { return "

404 Data was not found in cache

"; } return HtmlUtils.replacePlaceholders( - HtmlUtils.getHtmlStringFromResource("analysis.html"), + HtmlUtils.getStringFromResource("analysis.html"), PlaceholderUtils.getAnalysisReplaceRules(analysisCache.getData()) ); } catch (FileNotFoundException ex) { diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/JavaScriptResponse.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/JavaScriptResponse.java new file mode 100644 index 000000000..d5145e901 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/JavaScriptResponse.java @@ -0,0 +1,25 @@ +package main.java.com.djrapitops.plan.ui.webserver.response; + +import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.utilities.HtmlUtils; + +import java.io.FileNotFoundException; +import java.io.OutputStream; + +/** + * @author Rsl1122 + * @since 3.5.2 + */ +public class JavaScriptResponse extends Response { + + public JavaScriptResponse(OutputStream output, String resource) { + super(output); + super.setHeader("HTTP/1.1 200 OK"); + try { + super.setContent(HtmlUtils.getStringFromResource(resource)); + } catch (FileNotFoundException e) { + Log.toLog(this.getClass().getName(), e); + super.setContent(""); + } + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java index ca29dd44d..196bc866b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java @@ -21,7 +21,7 @@ public class HtmlUtils { * @return * @throws FileNotFoundException */ - public static String getHtmlStringFromResource(String fileName) throws FileNotFoundException { + public static String getStringFromResource(String fileName) throws FileNotFoundException { InputStream resourceStream = null; Scanner scanner = null; try { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java index 2a71b03e8..ff057faa6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java @@ -90,7 +90,7 @@ public class ExportUtility { if (!Settings.ANALYSIS_EXPORT.isTrue()) { return; } - String inspectHtml = HtmlUtils.replacePlaceholders(HtmlUtils.getHtmlStringFromResource("player.html"), + String inspectHtml = HtmlUtils.replacePlaceholders(HtmlUtils.getStringFromResource("player.html"), PlaceholderUtils.getInspectReplaceRules(userData)); File playerFolder = new File(playersFolder, userData.getName()); playerFolder.mkdir(); @@ -109,7 +109,7 @@ public class ExportUtility { if (!Settings.ANALYSIS_EXPORT.isTrue()) { return; } - String analysisHtml = HtmlUtils.replacePlaceholders(HtmlUtils.getHtmlStringFromResource("analysis.html"), + String analysisHtml = HtmlUtils.replacePlaceholders(HtmlUtils.getStringFromResource("analysis.html"), PlaceholderUtils.getAnalysisReplaceRules(analysisData)) .replace(HtmlUtils.getInspectUrl(""), "../player/"); File analysisHtmlFile = new File(serverFolder, "index.html"); diff --git a/Plan/src/main/resources/analysis.html b/Plan/src/main/resources/analysis.html index 78927aebe..dd115a49b 100644 --- a/Plan/src/main/resources/analysis.html +++ b/Plan/src/main/resources/analysis.html @@ -129,7 +129,7 @@ color: white; background-color: #348e0f; padding: 8px 14px; - border-radius: 10px; + border-radius: 6px; float: right; } .info-text { @@ -155,7 +155,7 @@ border-style: solid; border-color: #348e0f; padding: 8px 14px; - border-radius: 10px; + border-radius: 3px; width: 95%; } .header-icon { @@ -389,65 +389,8 @@ class="fa fa-crosshairs" aria-hidden="true"> Mob kills: %mobkills% | Deaths: %deaths%

-
-

Gamemode Usage


-
-
-
- -
-
-
- %gm0% -
-
- Survival -
-
-
-
-
- -
-
-
- %gm1% -
-
- Creative -
-
-
-
-
- -
-
-
- %gm2% -
-
- Adventure -
-
-
-
-
- -
-
-
- %gm3% -
-
- Spectator -
-
-
-
- +
+
@@ -536,10 +479,10 @@
-
+
Playerbase Composition
+ class="header-text"> Playerbase
@@ -555,63 +498,7 @@
-
-
-
- -
-
-
- %active% -
-
- __Active -
-
-
-
-
- -
-
-
- %inactive% -
-
- Inactive -
-
-
-
-
- -
-
-
- %joinleaver% -
-
- Single_join -
-
-
-
-
- -
-
-
- %banned% -
-
- Banned -
-
-
-
-

- -
+

+ - - +

\ No newline at end of file diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java index dfa447914..40b0a54c2 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/HtmlUtilsTest.java @@ -47,7 +47,7 @@ public class HtmlUtilsTest { public void testGetHtmlStringFromResource() throws Exception { TestInit t = TestInit.init(); String fileName = "player.html"; - String result = HtmlUtils.getHtmlStringFromResource(fileName); + String result = HtmlUtils.getStringFromResource(fileName); assertTrue("Result empty", !result.isEmpty()); }