Plan/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java

147 lines
7.1 KiB
Java
Raw Normal View History

/*
* 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.delivery.rendering.pages;
2019-09-28 09:56:03 +02:00
import com.djrapitops.plan.delivery.domain.container.CachingSupplier;
import com.djrapitops.plan.delivery.domain.container.DataContainer;
import com.djrapitops.plan.delivery.domain.container.RawDataContainer;
import com.djrapitops.plan.delivery.domain.keys.AnalysisKeys;
import com.djrapitops.plan.delivery.formatting.Formatters;
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
import com.djrapitops.plan.delivery.rendering.html.Html;
2019-09-28 09:56:03 +02:00
import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
Interface redesign package restructuring (#1146) * command.commands -> command.subcommands * command -> commands * commands -> system.commands * system.locale -> system.settings.locale * system.settings.changes -> system.settings.config.changes * system.settings.paths -> system.settings.config.paths * system.database -> system.storage.database * db -> system.storage.database * system.storage.database.access.queries -> system.storage.database.queries * system.storage.database.access.transactions -> system.storage.database.transactions * system.storage.database.access -> system.storage.database.operation * Moved Query classes to system.storage.database.queries * Moved Executable classes to system.storage.database.transactions * system.storage.database.patches -> system.storage.database.transactions.patches * system.file -> system.storage.file * system.settings.upkeep * system.storage.upkeep * system.server.info -> system.identification * system.importing -> system.gathering.importing * system.listeners -> system.gathering.listeners * system.gathering.timed * Removed duplicate class * data.container -> system.gathering.domain * data.plugin.PluginsConfigSection -> system.settings.config.ExtensionSettings * data.time -> system.gathering.domain * system.afk -> system.gathering.afk * system.cache -> system.gathering.cache * system.status -> system.gathering.listeners * system.export -> system.delivery.export * system.webserver -> system.delivery.webserver * system.json -> system.delivery.rendering.json * utilities.html -> system.delivery.rendering.html * system.delivery.rendering.html.graphs -> system.delivery.rendering.json.graphs * system.delivery.rendering.html.pages -> system.delivery.rendering.pages * system.delivery.upkeep * utilities.file -> system.settings.upkeep * data.store -> system.delivery.domain * system.update -> system.version * api.exceptions -> exceptions * ShutdownHook -> system.gathering * system.HtmlUtilities - > system.delivery.DeliveryUtilities * PeriodicAnalysisTask -> PeriodicServerExportTask * Deprecated APIv4 classes * Removed ServerTaskSystem (Reduces headache) * Moved & Fixed some tests
2019-08-30 11:36:38 +02:00
import com.djrapitops.plan.exceptions.ParseException;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.DisplaySettings;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.settings.theme.ThemeVal;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.version.VersionCheckSystem;
import java.io.IOException;
import java.util.List;
2019-09-28 09:56:03 +02:00
import java.util.UUID;
import static com.djrapitops.plan.delivery.domain.keys.AnalysisKeys.*;
/**
* Used for parsing a Html String out of server.html.
*
* @author Rsl1122
*/
public class ServerPage implements Page {
private final Server server;
private final PlanConfig config;
private final Theme theme;
private final VersionCheckSystem versionCheckSystem;
private final PlanFiles files;
private final DBSystem dbSystem;
2019-08-24 10:16:12 +02:00
private final ServerInfo serverInfo;
private final Formatters formatters;
ServerPage(
Server server,
PlanConfig config,
Theme theme,
VersionCheckSystem versionCheckSystem,
PlanFiles files,
DBSystem dbSystem,
2019-08-24 10:16:12 +02:00
ServerInfo serverInfo,
Formatters formatters
) {
this.server = server;
this.config = config;
this.theme = theme;
this.versionCheckSystem = versionCheckSystem;
this.files = files;
this.dbSystem = dbSystem;
2019-08-24 10:16:12 +02:00
this.serverInfo = serverInfo;
this.formatters = formatters;
}
@Override
public String toHtml() throws ParseException {
PlaceholderReplacer placeholders = new PlaceholderReplacer();
2019-09-28 09:56:03 +02:00
UUID serverUUID = server.getUuid();
placeholders.put("serverUUID", serverUUID.toString());
placeholders.put("serverName", server.getIdentifiableName());
placeholders.put("serverDisplayName", server.getName());
DataContainer constants = new RawDataContainer();
constants.putRawData(AnalysisKeys.TIME_ZONE, config.getTimeZoneOffsetHours());
// TODO Move these graph settings to the graph requests instead of placeholders
constants.putRawData(AnalysisKeys.FIRST_DAY, 1);
constants.putRawData(AnalysisKeys.TPS_MEDIUM, config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED));
constants.putRawData(AnalysisKeys.TPS_HIGH, config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_HIGH));
constants.putRawData(AnalysisKeys.DISK_MEDIUM, config.get(DisplaySettings.GRAPH_DISK_THRESHOLD_MED));
constants.putRawData(AnalysisKeys.DISK_HIGH, config.get(DisplaySettings.GRAPH_DISK_THRESHOLD_HIGH));
constants.putRawData(AnalysisKeys.ACTIVITY_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_ACTIVITY_PIE));
constants.putRawData(AnalysisKeys.GM_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_GM_PIE));
constants.putRawData(AnalysisKeys.PLAYERS_GRAPH_COLOR, theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
constants.putRawData(AnalysisKeys.TPS_LOW_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_LOW));
constants.putRawData(AnalysisKeys.TPS_MEDIUM_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_MED));
constants.putRawData(AnalysisKeys.TPS_HIGH_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_HIGH));
constants.putRawData(AnalysisKeys.WORLD_MAP_LOW_COLOR, theme.getValue(ThemeVal.WORLD_MAP_LOW));
constants.putRawData(AnalysisKeys.WORLD_MAP_HIGH_COLOR, theme.getValue(ThemeVal.WORLD_MAP_HIGH));
constants.putRawData(AnalysisKeys.WORLD_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
constants.putRawData(AnalysisKeys.AVG_PING_COLOR, theme.getValue(ThemeVal.GRAPH_AVG_PING));
constants.putRawData(AnalysisKeys.MAX_PING_COLOR, theme.getValue(ThemeVal.GRAPH_MAX_PING));
constants.putRawData(AnalysisKeys.MIN_PING_COLOR, theme.getValue(ThemeVal.GRAPH_MIN_PING));
placeholders.addAllPlaceholdersFrom(constants,
TIME_ZONE,
FIRST_DAY, TPS_MEDIUM, TPS_HIGH,
DISK_MEDIUM, DISK_HIGH,
PLAYERS_MAX, PLAYERS_ONLINE, PLAYERS_TOTAL,
WORLD_PIE_COLORS, GM_PIE_COLORS, ACTIVITY_PIE_COLORS,
PLAYERS_GRAPH_COLOR, TPS_HIGH_COLOR, TPS_MEDIUM_COLOR,
TPS_LOW_COLOR, WORLD_MAP_HIGH_COLOR, WORLD_MAP_LOW_COLOR,
AVG_PING_COLOR, MAX_PING_COLOR, MIN_PING_COLOR
);
2019-08-24 10:16:12 +02:00
placeholders.put("backButton", serverInfo.getServer().isProxy() ? Html.BACK_BUTTON_NETWORK.parse() : "");
2019-08-24 09:36:56 +02:00
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
2019-09-28 09:56:03 +02:00
CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
return new ServerPluginTabs(extensionData, formatters);
});
2019-09-28 09:56:03 +02:00
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
2019-09-28 09:58:32 +02:00
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs());
placeholders.put("navPluginsTabs", nav);
placeholders.put("tabsPlugins", tabs);
try {
return placeholders.apply(files.getCustomizableResourceOrDefault("web/server.html").asString());
} catch (IOException e) {
throw new ParseException(e);
}
}
}