Server extensions data endpoint

This commit is contained in:
Rsl1122 2019-07-19 19:22:38 +03:00
parent 4ff86347b0
commit 4b1b7f78c3
4 changed files with 132 additions and 89 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Object> {
@Inject
public PluginTabJSONParser(
DBSystem dbSystem,
Formatters formatters,
Identifiers identifiers
) {
super(identifiers, serverUUID -> {
List<ExtensionServerData> 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;
}
}
}

View File

@ -45,6 +45,7 @@ public class RootJSONHandler extends TreePageHandler {
GraphsJSONHandler graphsJSONHandler, GraphsJSONHandler graphsJSONHandler,
SessionsJSONHandler sessionsJSONHandler, SessionsJSONHandler sessionsJSONHandler,
PlayersTableJSONHandler playersTableJSONHandler, PlayersTableJSONHandler playersTableJSONHandler,
PluginTabJSONParser pluginTabJSONParser,
ServerOverviewJSONParser serverOverviewJSONParser, ServerOverviewJSONParser serverOverviewJSONParser,
OnlineActivityOverviewJSONParser onlineActivityOverviewJSONParser, OnlineActivityOverviewJSONParser onlineActivityOverviewJSONParser,
SessionsOverviewJSONParser sessionsOverviewJSONParser, SessionsOverviewJSONParser sessionsOverviewJSONParser,
@ -61,6 +62,7 @@ public class RootJSONHandler extends TreePageHandler {
registerPage("sessions", sessionsJSONHandler); registerPage("sessions", sessionsJSONHandler);
registerPage("kills", playerKillsJSONHandler); registerPage("kills", playerKillsJSONHandler);
registerPage("graph", graphsJSONHandler); registerPage("graph", graphsJSONHandler);
registerPage("extensions", pluginTabJSONParser);
registerPage("serverOverview", serverOverviewJSONParser); registerPage("serverOverview", serverOverviewJSONParser);
registerPage("onlineOverview", onlineActivityOverviewJSONParser); registerPage("onlineOverview", onlineActivityOverviewJSONParser);

View File

@ -118,11 +118,7 @@
Plugins Plugins
</div> </div>
<li class="nav-item nav-button"> <li class="plugin-nav" style="display: none;"></li>
<a class="nav-link" href="javascript:void(0)">
<i class="fas fa-fw fa-cubes"></i>
<span>Overview</span></a>
</li>
<!-- Divider --> <!-- Divider -->
<hr class="sidebar-divider"> <hr class="sidebar-divider">
@ -1133,61 +1129,7 @@
</div> <!-- /.container-fluid --> </div> <!-- /.container-fluid -->
</div> <!-- End of Performance tab --> </div> <!-- End of Performance tab -->
<!-- Begin Plugins Overview Tab --> <!-- Begin Plugins Overview Tab -->
<div class="tab"> <div class="plugin-tabs"></div>
<div class="container-fluid mt-4">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800"><i class="sidebar-toggler fa fa-fw fa-bars"></i>${serverDisplayName}
&middot; Plugins Overview</h1>
<a class="btn bg-plan btn-icon-split" href="network">
<span class="icon text-white-50">
<i class="fas fa-fw fa-arrow-left"></i><i class="fas fa-fw fa-cloud"></i>
</span>
<span class="text">Network page</span>
</a>
</div>
<div class="row">
<div class="col-lg-4 mb-4 col-sm-12">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold col-black"><i
class="fa fa-fw fa-star col-green"></i>
AdvancedAchievements</h6>
</div>
<div class="card-body">
<p><i class="far fa-fw fa-check-circle col-green"></i> Total Achievements<span
class="float-right"><b>9</b></p>
<p><i class="far fa-fw fa-check-circle col-green"></i> Average Achievements /
Player<span class="float-right"><b>9</b></p>
</div>
</div>
</div>
<div class="col-lg-4 mb-4 col-sm-12">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold col-black"><i
class="fa fa-fw fa-gamepad col-light-green"></i>
ViaVersion</h6>
</div>
<table class="table mb-0">
<thead class="bg-light-green">
<tr>
<th><i class=" fa fa-fw fa-signal"></i> Version</th>
<th><i class=" fa fa-fw fa-users"></i> Users</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.12.1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div> <!-- /.container-fluid -->
</div> <!-- End of Plugins Overview tab -->
<div class="tab"></div> <div class="tab"></div>
<div class="tab"></div> <div class="tab"></div>
</div> <!-- End of Main Content --> </div> <!-- End of Main Content -->
@ -1415,6 +1357,8 @@
<script src="js/charts/sessionAccordion.js"></script> <script src="js/charts/sessionAccordion.js"></script>
<script> <script>
var x = document.getElementById("content");
setLoadingText('Calculating values..'); setLoadingText('Calculating values..');
jsonRequest("../v1/serverOverview?server=${serverName}", loadServerOverviewValues); jsonRequest("../v1/serverOverview?server=${serverName}", loadServerOverviewValues);
jsonRequest("../v1/onlineOverview?server=${serverName}", loadOnlineActivityOverviewValues); jsonRequest("../v1/onlineOverview?server=${serverName}", loadOnlineActivityOverviewValues);
@ -1449,20 +1393,6 @@
diskMed: ${diskMedium}, diskMed: ${diskMedium},
diskHigh: ${diskHigh}, diskHigh: ${diskHigh},
firstDay: ${firstDay} firstDay: ${firstDay}
},
data: {
// activityPie: ${activityPieSeries},
// worldPie: ${worldSeries},
// worldPieDrillDown: ${gmSeries},
// geolocations: ${geoMapSeries},
// punchCard: ${punchCardSeries},
// activityStack: ${activityStackSeries},
// activityStackCategories: ${activityStackCategories},
// countryCategories: ${countryCategories},
// country: ${countrySeries},
// avgPing: ${avgPingSeries},
// maxPing: ${maxPingSeries},
// minPing: ${minPingSeries},
} }
}; };
@ -1706,22 +1636,19 @@
}); });
jsonRequest("../v1/kills?server=${serverName}", loadPlayerKills); jsonRequest("../v1/kills?server=${serverName}", loadPlayerKills);
jsonRequest("../v1/extensions?server=${serverName}", function (json, error) {
if (json) {
$('.plugin-nav').replaceWith(json.navigation);
$('.plugin-tabs').replaceWith(json.content);
openPageFunc();
} else if (error) {
$('.plugin-nav').remove();
$('.plugin-tabs').remove();
}
});
setLoadingText('Almost done..'); setLoadingText('Almost done..');
var navButtons = document.getElementsByClassName("nav-button"); openPageFunc();
var tabs = document.getElementsByClassName("tab");
var slideIndex = window.sessionStorage.getItem("server_slide_index");
if (slideIndex === null) {
slideIndex = 0;
}
var x = document.getElementById("content");
x.style.transform = "translate3d(0px,0px,0)";
x.style.width = "" + navButtons.length * 100 + "%";
for (var i = 0; i < navButtons.length; i++) {
navButtons[i].onclick = openFunc(i);
tabs[i].style.width = "" + 100 / navButtons.length + "%";
}
x.style.opacity = "1";
openFunc(slideIndex)();
jsonRequest("../v1/sessions?server=${serverName}", loadSessionAccordion); jsonRequest("../v1/sessions?server=${serverName}", loadSessionAccordion);
@ -1730,8 +1657,26 @@
$('.page-loader').fadeOut(); $('.page-loader').fadeOut();
}, 50); }, 50);
function openPageFunc() {
var navButtons = document.getElementsByClassName("nav-button");
var tabs = document.getElementsByClassName("tab");
var slideIndex = window.sessionStorage.getItem("server_slide_index");
if (slideIndex === null) {
slideIndex = 0;
}
x.style.transform = "translate3d(0px,0px,0)";
x.style.width = "" + navButtons.length * 100 + "%";
for (var i = 0; i < navButtons.length; i++) {
navButtons[i].onclick = openFunc(i);
tabs[i].style.width = "" + 100 / navButtons.length + "%";
}
x.style.opacity = "1";
openFunc(slideIndex)();
}
function openFunc(i) { function openFunc(i) {
return function () { return function () {
var navButtons = document.getElementsByClassName("nav-button");
var max = navButtons.length; var max = navButtons.length;
for (var j = 0; j < max; j++) { for (var j = 0; j < max; j++) {
if (navButtons[j].classList.contains('active')) { if (navButtons[j].classList.contains('active')) {

View File

@ -67,6 +67,25 @@ Parameter|Expected value|Description
--|--|-- --|--|--
`server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about `server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about
### `GET /v1/extensions`
Obtain html for data extension tabs and navigation.
Returns:
```javascript
{
navigation: String (html),
tabs: String (html)
}
```
Required parameters: `server`
Parameter|Expected value|Description
--|--|--
`server` | Name or UUID of a Plan server | Used for identifying Plan server that the data should be about
### `GET /v1/graph` ### `GET /v1/graph`
Obtain data for graphs. Obtain data for graphs.