mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-05 16:30:24 +08:00
Started work on unifying session tabs on both pages. #354
- Config setting - Inspect page now can use a table.
This commit is contained in:
parent
fb1d7f625c
commit
c77891c53b
@ -26,6 +26,7 @@ public enum Settings {
|
||||
WRITE_NEW_LOCALE("Plugin.WriteNewLocaleFileOnStart"),
|
||||
DEV_MODE("Plugin.Dev"),
|
||||
USE_SERVER_TIME("Customization.UseServerTime"),
|
||||
DISPLAY_SESSIONS_AS_TABLE("Customization.Display.SessionsAsTable"),
|
||||
|
||||
// Integer
|
||||
WEBSERVER_PORT("WebServer.Port"),
|
||||
|
@ -61,7 +61,7 @@ public class JoinInfoPart extends RawData {
|
||||
}
|
||||
|
||||
private void sessionTables() {
|
||||
String[] tables = SessionsTableCreator.createTables(this);
|
||||
String[] tables = SessionsTableCreator.createTable(this);
|
||||
addValue("tableBodySessions", tables[0]);
|
||||
addValue("tableBodyRecentLogins", tables[1]);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class BukkitInformationManager extends InformationManager {
|
||||
HookHandler hookHandler = plugin.getHookHandler();
|
||||
List<PluginData> plugins = hookHandler.getAdditionalDataSources();
|
||||
Map<String, Serializable> replaceMap = hookHandler.getAdditionalInspectReplaceRules(uuid);
|
||||
String contents = HtmlStructure.createInspectPageTabContent(serverName, plugins, replaceMap);
|
||||
String contents = HtmlStructure.createInspectPluginsTabContent(serverName, plugins, replaceMap);
|
||||
cacheInspectPluginsTab(uuid, contents);
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ public class InspectPageParser extends PageParser {
|
||||
.sorted(new SessionStartComparator())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
String[] sessionsTabContent = HtmlStructure.createSessionsTabContent(sessions, allSessions);
|
||||
String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessions, allSessions, uuid);
|
||||
addValue("contentSessions", sessionsTabContent[0]);
|
||||
addValue("sessionTabGraphViewFunctions", sessionsTabContent[1]);
|
||||
addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessions));
|
||||
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.utilities.html;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -38,9 +37,22 @@ public enum Html {
|
||||
LINK_CLASS("class=\"link\""),
|
||||
IMG("<img src=\"${0}\">"),
|
||||
//
|
||||
PARAGRAPH("<p>${0}</p>"),
|
||||
HEADER("<h1>${0}</h1>"),
|
||||
HEADER_2("<h2>${0}</h2>"),
|
||||
//
|
||||
DIV_W_CLASS("<div class=\"${0}\">${1}</div>"),
|
||||
DIV_W_CLASS_STYLE("<div class=\"${0}\" style=\"${1}\">${2}</div>"),
|
||||
//
|
||||
ROW(DIV_W_CLASS.parse("row", "${0}")),
|
||||
//
|
||||
TABLE_END("</tbody></table>"),
|
||||
TABLE_START_2("<table class=\"sortable table\"><thead><tr><th>${0}</th><th>${1}</th></tr></thead><tbody>"),
|
||||
TABLE_START_3("<table class=\"sortable table\"><thead><tr><th>${0}</th><th>${1}</th><th>${2}</th></tr></thead><tbody>"),
|
||||
TABLE_START_4("<table class=\"sortable table\"><thead><tr><th>${0}</th><th>${1}</th><th>${2}</th><th>${3}</th></tr></thead><tbody>"),
|
||||
TABLE_SESSIONS(DIV_W_CLASS_STYLE.parse("box-footer scrollbar", "padding: 2px;",
|
||||
TABLE_START_4.parse("Player", "Started", "Length", "World - Time") + "${0}" + TABLE_END.parse())
|
||||
),
|
||||
TABLE_SESSIONS_START(TABLE_START_3.parse("Session Started", "Session Ended", "Session Length")),
|
||||
TABLE_KILLS_START(TABLE_START_3.parse(FONT_AWESOME_ICON.parse("clock-o") + " Time", "Killed", "With")),
|
||||
TABLE_FACTIONS_START(TABLE_START_4.parse(FONT_AWESOME_ICON.parse("flag") + " Faction", FONT_AWESOME_ICON.parse("bolt") + " Power", FONT_AWESOME_ICON.parse("map-o") + " Land", FONT_AWESOME_ICON.parse("user") + " Leader")),
|
||||
@ -50,8 +62,7 @@ public enum Html {
|
||||
TABLELINE_4("<tr><td><b>${0}</b></td><td>${1}</td><td>${2}</td><td>${3}</td></tr>"),
|
||||
TABLELINE_PLAYERS("<tr><td>${0}</td><td>${1}</td><td sorttable_customkey=\"${2}\">${3}</td><td>${4}</td><td sorttable_customkey=\"${5}\">${6}</td>" + "<td sorttable_customkey=\"${7}\">${8}</td><td>${9}</td></tr>"),
|
||||
TABLELINE_3_CUSTOMKEY("<tr><td sorttable_customkey=\"${0}\">${1}</td><td sorttable_customkey=\"${2}\">${3}</td><td sorttable_customkey=\"${4}\">${5}</td></tr>"),
|
||||
TABLELINE_3_CUSTOMKEY_1("<tr><td sorttable_customkey=\"${0}\">${1}</td><td>${2}</td><td>${3}</td></tr>"),
|
||||
TABLE_END("</tbody></table>");
|
||||
TABLELINE_3_CUSTOMKEY_1("<tr><td sorttable_customkey=\"${0}\">${1}</td><td>${2}</td><td>${3}</td></tr>");
|
||||
|
||||
private final String html;
|
||||
|
||||
|
@ -6,6 +6,7 @@ package main.java.com.djrapitops.plan.utilities.html;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
@ -14,6 +15,7 @@ import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.html.tables.KillsTableCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@ -92,7 +94,11 @@ public class HtmlStructure {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String[] createSessionsTabContent(Map<String, List<Session>> sessions, List<Session> allSessions) throws FileNotFoundException {
|
||||
public static String[] createSessionsTabContentInspectPage(Map<String, List<Session>> sessions, List<Session> allSessions, UUID uuid) throws FileNotFoundException {
|
||||
if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) {
|
||||
return getSessionsAsTable(sessions, allSessions, uuid);
|
||||
}
|
||||
|
||||
Map<Integer, String> serverNameIDRelationMap = new HashMap<>();
|
||||
|
||||
if (Verify.isEmpty(allSessions)) {
|
||||
@ -190,16 +196,27 @@ public class HtmlStructure {
|
||||
return new String[]{html.toString(), viewScript.toString()};
|
||||
}
|
||||
|
||||
public static String createInspectPageTabContent(String serverName, List<PluginData> plugins, Map<String, Serializable> replaceMap) {
|
||||
private static String[] getSessionsAsTable(Map<String, List<Session>> sessions, List<Session> allSessions, UUID uuid) {
|
||||
Map<Integer, UUID> uuidByID = new HashMap<>();
|
||||
for (List<Session> sessionList : sessions.values()) {
|
||||
for (Session session : sessionList) {
|
||||
uuidByID.put(session.getSessionID(), uuid);
|
||||
}
|
||||
}
|
||||
|
||||
return new String[]{Html.TABLE_SESSIONS.parse(SessionsTableCreator.createTable(uuidByID, allSessions)[0]), ""};
|
||||
}
|
||||
|
||||
public static String createInspectPluginsTabContent(String serverName, List<PluginData> plugins, Map<String, Serializable> replaceMap) {
|
||||
if (plugins.isEmpty()) {
|
||||
return "<div class=\"plugins-server\">" +
|
||||
"<div class=\"plugins-header\">" +
|
||||
"<div class=\"row\">" +
|
||||
"<div class=\"column\">" +
|
||||
"<div class=\"box-header\">" +
|
||||
"<h2><i class=\"fa fa-server\" aria-hidden=\"true\"></i> " + serverName +
|
||||
"</h2><p>No Compatible Plugins</p>" +
|
||||
"</div></div></div></div></div>";
|
||||
String icon = Html.FONT_AWESOME_ICON.parse("server");
|
||||
// TODO Move plain text to Locale
|
||||
String headerText = Html.HEADER_2.parse(icon + " " + serverName) + Html.PARAGRAPH.parse("No Compatible Plugins");
|
||||
return Html.DIV_W_CLASS.parse("plugins-server",
|
||||
Html.DIV_W_CLASS.parse("plugins-header",
|
||||
Html.ROW.parse(Html.DIV_W_CLASS.parse("box-header", headerText))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, List<String>> placeholders = getPlaceholdersInspect(plugins);
|
||||
|
@ -24,7 +24,7 @@ import java.util.*;
|
||||
*/
|
||||
public class SessionsTableCreator {
|
||||
|
||||
public static String[] createTables(JoinInfoPart joinInfoPart) {
|
||||
public static String[] createTable(JoinInfoPart joinInfoPart) {
|
||||
Map<Integer, UUID> uuidByID = new HashMap<>();
|
||||
for (Map.Entry<UUID, List<Session>> entry : joinInfoPart.getSessions().entrySet()) {
|
||||
List<Session> sessions = entry.getValue();
|
||||
@ -34,6 +34,10 @@ public class SessionsTableCreator {
|
||||
}
|
||||
|
||||
List<Session> allSessions = joinInfoPart.getAllSessions();
|
||||
return createTable(uuidByID, allSessions);
|
||||
}
|
||||
|
||||
public static String[] createTable(Map<Integer, UUID> uuidByID, List<Session> allSessions) {
|
||||
if (allSessions.isEmpty()) {
|
||||
return new String[]{Html.TABLELINE_4.parse("<b>No Sessions</b>", "", "", ""),
|
||||
Html.TABLELINE_2.parse("<b>No Sessions</b>", "")};
|
||||
|
@ -52,6 +52,8 @@ Data:
|
||||
|
||||
Customization:
|
||||
UseServerTime: true
|
||||
Display:
|
||||
SessionsAsTable: false
|
||||
Formatting:
|
||||
DecimalPoints: '#.##'
|
||||
TimeAmount:
|
||||
|
@ -8,6 +8,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.RandomData;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
@ -47,7 +48,7 @@ public class HtmlStructureTest {
|
||||
@Test
|
||||
public void createSessionsTabContent() throws Exception {
|
||||
List<Session> allSessions = sessions.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||
String[] sessionsTab = HtmlStructure.createSessionsTabContent(sessions, allSessions);
|
||||
String[] sessionsTab = HtmlStructure.createSessionsTabContentInspectPage(sessions, allSessions, MockUtils.getPlayerUUID());
|
||||
|
||||
int opened = StringUtils.countMatches(sessionsTab[0], "<div");
|
||||
int closed = StringUtils.countMatches(sessionsTab[0], "</div");
|
||||
|
Loading…
Reference in New Issue
Block a user