Version information to the pages

This commit is contained in:
Rsl1122 2019-08-24 10:36:56 +03:00
parent 3027de6327
commit b895bd1a8a
11 changed files with 89 additions and 139 deletions

View File

@ -47,7 +47,7 @@ public class APFModule {
@Named("currentVersion") @Named("currentVersion")
@Singleton @Singleton
String provideCurrentVersion(IPlugin plugin) { String provideCurrentVersion(IPlugin plugin) {
return plugin.getVersion(); return plugin.getVersion().replace("%buildNumber%", "?");
} }
@Provides @Provides

View File

@ -103,10 +103,45 @@ public class VersionCheckSystem implements SubSystem {
return Optional.ofNullable(newVersionAvailable); return Optional.ofNullable(newVersionAvailable);
} }
public Optional<String> getUpdateHtml() { public Optional<String> getUpdateButton() {
return getNewVersionAvailable() return getNewVersionAvailable()
.map(v -> v.isTrusted() ? "<a href=\"" + v.getChangeLogUrl() + "\" target=\"_blank\">" + .filter(VersionInfo::isTrusted)
"<h4 class=\"col-green\"><i class=\"" + (v.isRelease() ? "fa fa-download" : "fab fa-dev") + "\"></i> v" + v.getVersion().getVersionString() + " available!</h4></a>" : ""); .map(v -> "<button class=\"btn bg-white col-plan\" data-target=\"#updateModal\" data-toggle=\"modal\" type=\"button\">" +
"<i class=\"fa fa-fw fa-download\"></i> v." + v.getVersion().getVersionString() +
"</button>"
);
}
public String getCurrentVersionButton() {
return "<button class=\"btn bg-plan\" data-target=\"#updateModal\" data-toggle=\"modal\" type=\"button\">" +
"v." + getCurrentVersion() +
"</button>";
}
public String getUpdateModal() {
return getNewVersionAvailable()
.filter(VersionInfo::isTrusted)
.map(v -> "<div class=\"modal-header\">" +
"<h5 class=\"modal-title\" id=\"updateModalLabel\">" +
"<i class=\"fa fa-fw fa-download\"></i> Version " + v.getVersion().getVersionString() + " is Available!" +
"</h5><button aria-label=\"Close\" class=\"close\" data-dismiss=\"modal\" type=\"button\"><span aria-hidden=\"true\">&times;</span></button>" +
"</div>" + // Close modal-header
"<div class=\"modal-body\">" +
"<p>A new version has been released and is now available for download." +
(v.isRelease() ? "" : "<br>This version is a DEV release.") + "</p>" +
"<a class=\"btn col-plan\" href=\"" + v.getChangeLogUrl() + "\" rel=\"noopener noreferrer\" target=\"_blank\">" +
"<i class=\"fa fa-fw fa-list\"></i> View Changelog</a>" +
"<a class=\"btn col-plan\" href=\"" + v.getDownloadUrl() + "\" rel=\"noopener noreferrer\" target=\"_blank\">" +
"<i class=\"fa fa-fw fa-download\"></i> Download Plan-4.6.2.jar</a>" +
"</div>") // Close modal-body
.orElse("<div class=\"modal-header\">" +
"<h5 class=\"modal-title\" id=\"updateModalLabel\">" +
"<i class=\"far fa-fw fa-check-circle\"></i> You have version " + getCurrentVersion() + "" +
"</h5><button aria-label=\"Close\" class=\"close\" data-dismiss=\"modal\" type=\"button\"><span aria-hidden=\"true\">&times;</span></button>" +
"</div>" + // Close modal-header
"<div class=\"modal-body\">" +
"<p>You are running the latest version.</p>" +
"</div>"); // Close modal-body
} }
public String getCurrentVersion() { public String getCurrentVersion() {

View File

@ -48,15 +48,15 @@ public class ErrorResponse extends PageResponse {
} }
public void replacePlaceholders() { public void replacePlaceholders() {
Map<String, String> placeHolders = new HashMap<>(); Map<String, String> placeholders = new HashMap<>();
placeHolders.put("title", title); placeholders.put("title", title);
String[] split = title.split(">", 3); String[] split = title.split(">", 3);
placeHolders.put("titleText", split.length == 3 ? split[2] : title); placeholders.put("titleText", split.length == 3 ? split[2] : title);
placeHolders.put("paragraph", paragraph); placeholders.put("paragraph", paragraph);
placeHolders.put("version", versionCheckSystem.getCurrentVersion()); placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
placeHolders.put("update", versionCheckSystem.getUpdateHtml().orElse("")); placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
setContent(StringSubstitutor.replace(getContent(), placeHolders)); setContent(StringSubstitutor.replace(getContent(), placeholders));
} }
public void setTitle(String title) { public void setTitle(String title) {

View File

@ -85,7 +85,8 @@ public class NetworkPage implements Page {
placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING)); placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING));
placeholders.put("timeZone", config.getTimeZoneOffsetHours()); placeholders.put("timeZone", config.getTimeZoneOffsetHours());
placeholders.put("update", versionCheckSystem.getUpdateHtml().orElse("")); placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
List<ExtensionServerData> extensionData = dbSystem.getDatabase() List<ExtensionServerData> extensionData = dbSystem.getDatabase()
.query(new ExtensionServerDataQuery(serverUUID)); .query(new ExtensionServerDataQuery(serverUUID));

View File

@ -90,33 +90,33 @@ public class PlayerPage implements Page {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
UUID playerUUID = player.getUnsafe(PlayerKeys.UUID); UUID playerUUID = player.getUnsafe(PlayerKeys.UUID);
PlaceholderReplacer replacer = new PlaceholderReplacer(); PlaceholderReplacer placeholders = new PlaceholderReplacer();
replacer.put("refresh", clockLongFormatter.apply(now)); placeholders.put("refresh", clockLongFormatter.apply(now));
replacer.put("refreshFull", secondLongFormatter.apply(now)); placeholders.put("refreshFull", secondLongFormatter.apply(now));
replacer.put("version", versionCheckSystem.getCurrentVersion()); placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
replacer.put("update", versionCheckSystem.getUpdateHtml().orElse("")); placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
replacer.put("timeZone", config.getTimeZoneOffsetHours()); placeholders.put("timeZone", config.getTimeZoneOffsetHours());
String playerName = player.getValue(PlayerKeys.NAME).orElse(playerUUID.toString()); String playerName = player.getValue(PlayerKeys.NAME).orElse(playerUUID.toString());
replacer.put("playerName", playerName); placeholders.put("playerName", playerName);
replacer.put("worldPieColors", theme.getValue(ThemeVal.GRAPH_WORLD_PIE)); placeholders.put("worldPieColors", theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
replacer.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE)); placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
replacer.put("serverPieColors", theme.getValue(ThemeVal.GRAPH_SERVER_PREF_PIE)); placeholders.put("serverPieColors", theme.getValue(ThemeVal.GRAPH_SERVER_PREF_PIE));
replacer.put("firstDay", 1); placeholders.put("firstDay", 1);
if (serverInfo.getServer().isProxy()) { if (serverInfo.getServer().isProxy()) {
replacer.put("backButton", "<li><a title=\"to Network page\" href=\"/network\"><i class=\"material-icons\">arrow_back</i><i class=\"material-icons\">cloud</i></a></li>"); placeholders.put("backButton", "<li><a title=\"to Network page\" href=\"/network\"><i class=\"material-icons\">arrow_back</i><i class=\"material-icons\">cloud</i></a></li>");
} else { } else {
replacer.put("backButton", "<li><a title=\"to Server page\" href=\"/server\"><i class=\"material-icons\">arrow_back</i><i class=\"material-icons\">storage</i></a></li>"); placeholders.put("backButton", "<li><a title=\"to Server page\" href=\"/server\"><i class=\"material-icons\">arrow_back</i><i class=\"material-icons\">storage</i></a></li>");
} }
PlayerPluginTab pluginTabs = pageFactory.inspectPluginTabs(playerUUID); PlayerPluginTab pluginTabs = pageFactory.inspectPluginTabs(playerUUID);
replacer.put("navPluginsTabs", pluginTabs.getNav()); placeholders.put("navPluginsTabs", pluginTabs.getNav());
replacer.put("pluginsTabs", pluginTabs.getTab()); placeholders.put("pluginsTabs", pluginTabs.getTab());
return replacer.apply(files.getCustomizableResourceOrDefault("web/player.html").asString()); return placeholders.apply(files.getCustomizableResourceOrDefault("web/player.html").asString());
} }
} }

View File

@ -70,22 +70,22 @@ public class PlayersPage implements Page {
@Override @Override
public String toHtml() throws ParseException { public String toHtml() throws ParseException {
try { try {
PlaceholderReplacer placeholderReplacer = new PlaceholderReplacer(); PlaceholderReplacer placeholders = new PlaceholderReplacer();
placeholderReplacer.put("version", versionCheckSystem.getCurrentVersion()); placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
placeholderReplacer.put("update", versionCheckSystem.getUpdateHtml().orElse("")); placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
if (serverInfo.getServer().isProxy()) { if (serverInfo.getServer().isProxy()) {
placeholderReplacer.put("networkName", config.get(ProxySettings.NETWORK_NAME)); placeholders.put("networkName", config.get(ProxySettings.NETWORK_NAME));
} else { } else {
placeholderReplacer.put("networkName", config.get(PluginSettings.SERVER_NAME)); placeholders.put("networkName", config.get(PluginSettings.SERVER_NAME));
} }
timings.start("Players page players table parsing"); timings.start("Players page players table parsing");
List<PlayerContainer> playerContainers = database.query(ContainerFetchQueries.fetchAllPlayerContainers()); List<PlayerContainer> playerContainers = database.query(ContainerFetchQueries.fetchAllPlayerContainers());
placeholderReplacer.put("playersTable", tables.playerTableForPlayersPage(playerContainers).parseHtml()); placeholders.put("playersTable", tables.playerTableForPlayersPage(playerContainers).parseHtml());
timings.end("Pages", "Players page players table parsing"); timings.end("Pages", "Players page players table parsing");
return placeholderReplacer.apply(files.getCustomizableResourceOrDefault("web/players.html").asString()); return placeholders.apply(files.getCustomizableResourceOrDefault("web/players.html").asString());
} catch (Exception e) { } catch (Exception e) {
throw new ParseException(e); throw new ParseException(e);
} }

View File

@ -118,7 +118,8 @@ public class ServerPage implements Page {
} else { } else {
placeholders.put("backButton", ""); placeholders.put("backButton", "");
} }
placeholders.put("update", versionCheckSystem.getUpdateHtml().orElse("")); placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
List<ExtensionServerData> extensionData = dbSystem.getDatabase() List<ExtensionServerData> extensionData = dbSystem.getDatabase()
.query(new ExtensionServerDataQuery(server.getUuid())); .query(new ExtensionServerDataQuery(server.getUuid()));

View File

@ -56,9 +56,9 @@
<button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button"> <button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button">
<i class="fa fa-fw fa-question-circle"></i> <i class="fa fa-fw fa-question-circle"></i>
</button> </button>
<button class="btn bg-white col-plan" data-target="#updateModal" data-toggle="modal" type="button"> </div>
<b><i class="fa fa-fw fa-download"></i> v4.6.2</b> <div class="ml-3 align-items-center justify-content-between">
</button> ${version}
</div> </div>
</ul> </ul>
<!-- End of Sidebar --> <!-- End of Sidebar -->
@ -230,28 +230,7 @@
tabindex="-1"> tabindex="-1">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> ${updateModal}
<h5 class="modal-title" id="updateModalLabel"><i class="fa fa-fw fa-download"></i> Version 4.6.2
is
Available!
</h5>
<button aria-label="Close" class="close" data-dismiss="modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>A new version has been released and is now available for download.</p>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/tag/4.6.2-REL"
rel="noopener noreferrer" target="_blank">
<i class="fa fa-fw fa-list"></i> View Changelog
</a>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/download/4.6.2-REL/Plan-4.6.2.jar"
rel="noopener noreferrer" target="_blank">
<i class="fa fa-fw fa-download"></i> Download Plan-4.6.2.jar
</a>
</div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button> <button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>
</div> </div>

View File

@ -120,9 +120,9 @@
<button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button"> <button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button">
<i class="fa fa-fw fa-question-circle"></i> <i class="fa fa-fw fa-question-circle"></i>
</button> </button>
<button class="btn bg-white col-plan" data-target="#updateModal" data-toggle="modal" type="button"> </div>
<b><i class="fa fa-fw fa-download"></i> v4.6.2</b> <div class="ml-3 align-items-center justify-content-between">
</button> ${version}
</div> </div>
</ul> </ul>
<!-- End of Sidebar --> <!-- End of Sidebar -->
@ -801,29 +801,7 @@
tabindex="-1"> tabindex="-1">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> ${updateModal}
<h5 class="modal-title" id="updateModalLabel"><i class="fa fa-fw fa-download"></i> Version 4.6.2 is
Available!
</h5>
<button aria-label="Close" class="close" data-dismiss="modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>A new version has been released and is now available for download.</p>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/tag/4.6.2-REL"
rel="noopener noreferrer"
target="_blank">
<i class="fa fa-fw fa-list"></i> View Changelog
</a>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/download/4.6.2-REL/Plan-4.6.2.jar"
rel="noopener noreferrer"
target="_blank">
<i class="fa fa-fw fa-download"></i> Download Plan-4.6.2.jar
</a>
</div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button> <button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>
</div> </div>

View File

@ -108,9 +108,9 @@
<button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button"> <button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button">
<i class="fa fa-fw fa-question-circle"></i> <i class="fa fa-fw fa-question-circle"></i>
</button> </button>
<button class="btn bg-white col-plan" data-target="#updateModal" data-toggle="modal" type="button"> </div>
<b><i class="fa fa-fw fa-download"></i> v4.6.2</b> <div class="ml-3 align-items-center justify-content-between">
</button> ${version}
</div> </div>
</ul> </ul>
<!-- End of Sidebar --> <!-- End of Sidebar -->
@ -717,28 +717,7 @@
tabindex="-1"> tabindex="-1">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> ${updateModal}
<h5 class="modal-title" id="updateModalLabel"><i class="fa fa-fw fa-download"></i> Version 4.6.2
is
Available!
</h5>
<button aria-label="Close" class="close" data-dismiss="modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>A new version has been released and is now available for download.</p>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/tag/4.6.2-REL"
rel="noopener noreferrer" target="_blank">
<i class="fa fa-fw fa-list"></i> View Changelog
</a>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/download/4.6.2-REL/Plan-4.6.2.jar"
rel="noopener noreferrer" target="_blank">
<i class="fa fa-fw fa-download"></i> Download Plan-4.6.2.jar
</a>
</div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button> <button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>
</div> </div>

View File

@ -126,9 +126,9 @@
<button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button"> <button class="btn bg-plan" data-target="#informationModal" data-toggle="modal" type="button">
<i class="fa fa-fw fa-question-circle"></i> <i class="fa fa-fw fa-question-circle"></i>
</button> </button>
<button class="btn bg-white col-plan" data-target="#updateModal" data-toggle="modal" type="button"> </div>
<b><i class="fa fa-fw fa-download"></i> v4.6.2</b> <div class="ml-3 align-items-center justify-content-between">
</button> ${version}
</div> </div>
</ul> </ul>
<!-- End of Sidebar --> <!-- End of Sidebar -->
@ -1288,30 +1288,7 @@
tabindex="-1"> tabindex="-1">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> ${updateModal}
<h5 class="modal-title" id="updateModalLabel"><i class="fa fa-fw fa-download"></i> Version 4.6.2
is
Available!
</h5>
<button aria-label="Close" class="close" data-dismiss="modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>A new version has been released and is now available for download.</p>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/tag/4.6.2-REL"
rel="noopener noreferrer"
target="_blank">
<i class="fa fa-fw fa-list"></i> View Changelog
</a>
<a class="btn col-plan"
href="https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/download/4.6.2-REL/Plan-4.6.2.jar"
rel="noopener noreferrer"
target="_blank">
<i class="fa fa-fw fa-download"></i> Download Plan-4.6.2.jar
</a>
</div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button> <button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>
</div> </div>