From 4b1b7f78c310cfeb2d4ae91878a1e32c8dd02cca Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 19 Jul 2019 19:22:38 +0300 Subject: [PATCH] Server extensions data endpoint --- .../plan/system/json/PluginTabJSONParser.java | 77 +++++++++++ .../webserver/pages/json/RootJSONHandler.java | 2 + .../resources/assets/plan/web/server.html | 123 +++++------------- Plan/json-endpoints.md | 19 +++ 4 files changed, 132 insertions(+), 89 deletions(-) create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/system/json/PluginTabJSONParser.java diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/json/PluginTabJSONParser.java b/Plan/common/src/main/java/com/djrapitops/plan/system/json/PluginTabJSONParser.java new file mode 100644 index 000000000..c306dcb28 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/json/PluginTabJSONParser.java @@ -0,0 +1,77 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.system.json; + +import com.djrapitops.plan.api.exceptions.WebUserAuthException; +import com.djrapitops.plan.extension.implementation.results.server.ExtensionServerData; +import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery; +import com.djrapitops.plan.system.Identifiers; +import com.djrapitops.plan.system.database.DBSystem; +import com.djrapitops.plan.system.webserver.RequestTarget; +import com.djrapitops.plan.system.webserver.auth.Authentication; +import com.djrapitops.plan.system.webserver.pages.json.ServerTabJSONHandler; +import com.djrapitops.plan.utilities.formatting.Formatters; +import com.djrapitops.plan.utilities.html.pages.AnalysisPluginTabs; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.util.List; + +/** + * Parses JSON for with different plugin data html in it. + */ +@Singleton +public class PluginTabJSONParser extends ServerTabJSONHandler { + + @Inject + public PluginTabJSONParser( + DBSystem dbSystem, + Formatters formatters, + Identifiers identifiers + ) { + super(identifiers, serverUUID -> { + List extensionData = dbSystem.getDatabase() + .query(new ExtensionServerDataQuery(serverUUID)); + + AnalysisPluginTabs pluginTabs = new AnalysisPluginTabs(extensionData, formatters); + return new ExtensionTabs(pluginTabs.getNav(), pluginTabs.getTabs()); + }); + } + + @Override + public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException { + return auth.getWebUser().getPermLevel() <= 0; + } + + public static class ExtensionTabs { + private final String navigation; + private final String content; + + public ExtensionTabs(String navigation, String content) { + this.navigation = navigation; + this.content = content; + } + + public String getNavigation() { + return navigation; + } + + public String getContent() { + return content; + } + } +} diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/pages/json/RootJSONHandler.java b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/pages/json/RootJSONHandler.java index 86c66fdfd..cb94683ea 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/pages/json/RootJSONHandler.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/pages/json/RootJSONHandler.java @@ -45,6 +45,7 @@ public class RootJSONHandler extends TreePageHandler { GraphsJSONHandler graphsJSONHandler, SessionsJSONHandler sessionsJSONHandler, PlayersTableJSONHandler playersTableJSONHandler, + PluginTabJSONParser pluginTabJSONParser, ServerOverviewJSONParser serverOverviewJSONParser, OnlineActivityOverviewJSONParser onlineActivityOverviewJSONParser, SessionsOverviewJSONParser sessionsOverviewJSONParser, @@ -61,6 +62,7 @@ public class RootJSONHandler extends TreePageHandler { registerPage("sessions", sessionsJSONHandler); registerPage("kills", playerKillsJSONHandler); registerPage("graph", graphsJSONHandler); + registerPage("extensions", pluginTabJSONParser); registerPage("serverOverview", serverOverviewJSONParser); registerPage("onlineOverview", onlineActivityOverviewJSONParser); diff --git a/Plan/common/src/main/resources/assets/plan/web/server.html b/Plan/common/src/main/resources/assets/plan/web/server.html index 62a3a5b15..331c25ba9 100644 --- a/Plan/common/src/main/resources/assets/plan/web/server.html +++ b/Plan/common/src/main/resources/assets/plan/web/server.html @@ -118,11 +118,7 @@ Plugins - + @@ -1133,61 +1129,7 @@ -
-
- -
-

${serverDisplayName} - · Plugins Overview

- - - - - Network page - -
-
-
-
-
-
- AdvancedAchievements
-
-
-

Total Achievements9

-

Average Achievements / - Player9

-
-
-
-
-
-
-
- ViaVersion
-
- - - - - - - - - - - - - -
Version Users
1.12.11
-
-
-
-
-
+
@@ -1415,6 +1357,8 @@