From 4b26755d5b185fcf1b8790d50404cc8f8055c302 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 27 Oct 2017 19:08:48 +0300 Subject: [PATCH] Implemented unified Session display on both pages (#354) and added SessionID as a tooltip. (#332) --- .../java/com/djrapitops/plan/api/API.java | 27 ++- .../plan/data/analysis/JoinInfoPart.java | 4 + .../info/parsing/InspectPageParser.java | 2 +- .../djrapitops/plan/utilities/html/Html.java | 1 + .../plan/utilities/html/HtmlStructure.java | 106 +---------- .../structure/SessionTabStructureCreator.java | 177 ++++++++++++++++++ .../html/tables/SessionsTableCreator.java | 3 +- Plan/src/main/resources/html/server.html | 24 +-- 8 files changed, 216 insertions(+), 128 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java diff --git a/Plan/src/main/java/com/djrapitops/plan/api/API.java b/Plan/src/main/java/com/djrapitops/plan/api/API.java index 9dac148fc..722a3de1e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/api/API.java +++ b/Plan/src/main/java/com/djrapitops/plan/api/API.java @@ -27,14 +27,14 @@ import java.util.UUID; * @author Rsl1122 * @see PluginData * @see AnalysisType - * @since 2.0.0 + * @since 4.0.0 */ public class API { private final Plan plugin; /** - * Class Constructor. + * Creates a new API instance - not supposed to be called outside {@code Plan.onEnable}. * * @param plugin Current instance of Plan */ @@ -78,7 +78,7 @@ public class API { * {@code PlayerName} * * @param name Name of the player - * @return ./player/PlayerName + * @return {@code ../player/PlayerName} */ public String getPlayerInspectPageLink(String name) { String link = "../player/" + name; @@ -86,7 +86,7 @@ public class API { } /** - * Check if Players's Inspect page is cached to pagecache. + * Check if Players's Inspect page is cached to PageCache. * * @param uuid UUID of the player. * @return true/false @@ -97,12 +97,21 @@ public class API { return isPlayerHtmlCached(uuid); } + /** + * Check if Players's Inspect page is cached to PageCache of the providing WebServer. + *

+ * Using BungeeCord: Will send a {@code IsCachedWebAPI} request to check if the page is in Bungee's PageCache. + * Only Bukkit: Checks PageCache for page. + * + * @param uuid UUID of the player. + * @return true/false + */ public boolean isPlayerHtmlCached(UUID uuid) { return plugin.getInfoManager().isCached(uuid); } /** - * Cache Players's Inspect page to the PageCache of the WebServer. + * Cache Players's Inspect page to the PageCache of the providing WebServer. * * @param uuid UUID of the player. * @deprecated use {@code cachePlayerHtml} @@ -113,9 +122,13 @@ public class API { } /** - * Cache Players's Inspect page to the PageCache of the WebServer. + * Cache Players's Inspect page to the PageCache of the providing WebServer. + *

+ * Using BungeeCord: Will send a {@code PostHtmlWebAPI} request after calculating the inspect page. + * Only Bukkit: Calculates inspect page and places it in the PageCache. * * @param uuid UUID of the player. + * @deprecated use {@code cachePlayerHtml} */ public void cachePlayerHtml(UUID uuid) { plugin.getInfoManager().cachePlayer(uuid); @@ -124,7 +137,7 @@ public class API { /** * Used to get the full Html of the Inspect page as a string. *

- * Check if the data is cached to InspectCache before calling this. + * Re-calculates the inspect html on this server. * * @param uuid UUID of the player. * @return player.html with all placeholders replaced. diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java index 7038e974a..d95dbaa8d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/JoinInfoPart.java @@ -5,6 +5,7 @@ import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; +import main.java.com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator; import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; import java.util.*; @@ -62,6 +63,9 @@ public class JoinInfoPart extends RawData { private void sessionTables() { String[] tables = SessionsTableCreator.createTable(this); + String[] sessionContent = SessionTabStructureCreator.creteStructure(this); + addValue("contentSessions", sessionContent[0]); + addValue("sessionTabGraphViewFunctions", sessionContent[1]); addValue("tableBodySessions", tables[0]); addValue("tableBodyRecentLogins", tables[1]); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java index 3461e759b..74c28cf61 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/InspectPageParser.java @@ -98,7 +98,7 @@ public class InspectPageParser extends PageParser { Map> sessions = sessionsTable.getSessions(uuid); List allSessions = sessions.values().stream() .flatMap(Collection::stream) - .sorted(new SessionStartComparator()) + .sorted(new SessionStartComparator()) // Sorted Newest first. .collect(Collectors.toList()); String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessions, allSessions, uuid); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java index 67a70a8e3..2b9e0b2fe 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/Html.java @@ -33,6 +33,7 @@ public enum Html { BUTTON("${1}"), BUTTON_CLASS("class=\"button\""), LINK("${1}"), + LINK_TOOLTIP("${1}"), LINK_EXTERNAL("${1}"), LINK_CLASS("class=\"link\""), IMG(""), diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java index 56dffa0a0..83a90737f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java @@ -6,15 +6,13 @@ 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; import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager; 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.structure.SessionTabStructureCreator; import main.java.com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; import org.apache.commons.lang3.text.StrSubstitutor; @@ -95,105 +93,9 @@ public class HtmlStructure { } public static String[] createSessionsTabContentInspectPage(Map> sessions, List allSessions, UUID uuid) throws FileNotFoundException { - if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) { - return getSessionsAsTable(sessions, allSessions, uuid); - } - - Map serverNameIDRelationMap = new HashMap<>(); - - if (Verify.isEmpty(allSessions)) { - return new String[]{"

" + - "
" + - "
" + - "

No Sessions

" + - "
", ""}; - } - - for (Map.Entry> entry : sessions.entrySet()) { - String serverName = entry.getKey(); - List serverSessions = entry.getValue(); - for (Session session : serverSessions) { - serverNameIDRelationMap.put(session.getSessionID(), serverName); - } - } - - StringBuilder html = new StringBuilder(); - StringBuilder viewScript = new StringBuilder(); - int i = 0; - for (Session session : allSessions) { - if (i >= 50) { - break; - } - - String sessionStart = FormatUtils.formatTimeStampYear(session.getSessionStart()); - String sessionLength = FormatUtils.formatTimeAmount(session.getLength()); - String sessionEnd = FormatUtils.formatTimeStampYear(session.getSessionEnd()); - - String dotSeparated = separateWithDots(sessionStart, sessionLength); - - // Session-column starts & header. - html.append("
") - .append("
") - .append("
") - .append("

").append(dotSeparated).append("

") - .append("
") - .append("
"); - - String serverName = serverNameIDRelationMap.get(session.getSessionID()); - - // Left side of Session box - html.append("
") - .append("
") // - .append("
"); - - // Left side header - html.append("
") - .append("

") - .append(sessionStart) - .append("

") - .append("
"); - - // Left side content - html.append("
") - .append("

Session Length: ").append(sessionLength).append("
") - .append("Session Ended: ").append(sessionEnd).append("
") - .append("Server: ").append(serverName).append("

") - .append("Mob Kills: ").append(session.getMobKills()).append("
") - .append("Deaths: ").append(session.getDeaths()).append("

"); - - html.append(KillsTableCreator.createTable(session.getPlayerKills())) - .append("
"); // Left Side content ends - - // Left side ends & Right side starts - html.append("
") - .append("
"); - - String id = "worldPie" + session.getSessionStart() + i; - - html.append("
"); - - String[] worldData = WorldPieCreator.createSeriesData(session.getWorldTimes()); - - html.append(""); - - viewScript.append("worldPie(") - .append(id).append(", ") - .append(id).append("series, ") - .append(id).append("gmseries") - .append(");"); - - // Session-col, Row, Session-Content, Session-column ends. - html.append("
") - .append("
") - .append("
") - .append("
"); - - i++; - } - return new String[]{html.toString(), viewScript.toString()}; + Map>> map = new HashMap<>(); + map.put(uuid, sessions); + return SessionTabStructureCreator.creteStructure(map, allSessions, false); } private static String[] getSessionsAsTable(Map> sessions, List allSessions, UUID uuid) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java new file mode 100644 index 000000000..5e9c9439c --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java @@ -0,0 +1,177 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package main.java.com.djrapitops.plan.utilities.html.structure; + +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.analysis.JoinInfoPart; +import main.java.com.djrapitops.plan.utilities.FormatUtils; +import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparator; +import main.java.com.djrapitops.plan.utilities.html.Html; +import main.java.com.djrapitops.plan.utilities.html.HtmlStructure; +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 java.util.*; +import java.util.stream.Collectors; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class SessionTabStructureCreator { + + public static String[] creteStructure(Map>> sessions, List allSessions, boolean appendName) { + + Map uuidsByID = generateIDtoUUIDMap(sessions); + + if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) { + return new String[]{Html.TABLE_SESSIONS.parse(SessionsTableCreator.createTable(uuidsByID, allSessions)[0]), ""}; + } + + if (Verify.isEmpty(allSessions)) { + return new String[]{"
" + + "
" + + "
" + + "

No Sessions

" + + "
", ""}; + } + + Map serverNameIDMap = generateIDtoServerNameMap(sessions); + + StringBuilder html = new StringBuilder(); + StringBuilder viewScript = new StringBuilder(); + int i = 0; + for (Session session : allSessions) { + if (i >= 50) { + break; + } + + int sessionID = session.getSessionID(); + UUID uuid = uuidsByID.get(sessionID); + String serverName = serverNameIDMap.get(sessionID); + + String sessionStart = FormatUtils.formatTimeStampYear(session.getSessionStart()); + String sessionLength = FormatUtils.formatTimeAmount(session.getLength()); + String sessionEnd = FormatUtils.formatTimeStampYear(session.getSessionEnd()); + + String name = Plan.getInstance().getDataCache().getName(uuid); + String link = Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(name), name); + String dotSeparated = appendName ? + HtmlStructure.separateWithDots(link, sessionStart, sessionLength) : + HtmlStructure.separateWithDots(sessionStart, sessionLength); + + // Session-column starts & header. + html.append("
") + .append("
") + .append("
") + .append("

").append(dotSeparated).append("

") + .append("
") + .append("
"); + + + // Left side of Session box + html.append("
") + .append("
") // + .append("
"); + + // Left side header + html.append("
") + .append("

") + .append(sessionStart) + .append("

") + .append("
"); + + // Left side content + html.append("
") + .append("

Session Length: ").append(sessionLength).append("
") + .append("Session Ended: ").append(sessionEnd).append("
") + .append("Server: ").append(serverName).append("

") + .append("Mob Kills: ").append(session.getMobKills()).append("
") + .append("Deaths: ").append(session.getDeaths()).append("

"); + + html.append(KillsTableCreator.createTable(session.getPlayerKills())) + .append("
"); // Left Side content ends + + // Left side ends & Right side starts + html.append("
") + .append("
"); + + String id = "worldPie" + session.getSessionStart() + i; + + html.append("
"); + + String[] worldData = WorldPieCreator.createSeriesData(session.getWorldTimes()); + + html.append(""); + + viewScript.append("worldPie(") + .append(id).append(", ") + .append(id).append("series, ") + .append(id).append("gmseries") + .append(");"); + + // Session-col, Row, Session-Content, Session-column ends. + html.append("
") + .append("
") + .append("
") + .append("
"); + + i++; + } + return new String[]{html.toString(), viewScript.toString()}; + } + + private static Map generateIDtoServerNameMap(Map>> sessions) { + Map serverNameIDRelationMap = new HashMap<>(); + for (Map> map : sessions.values()) { + for (Map.Entry> entry : map.entrySet()) { + String serverName = entry.getKey(); + List serverSessions = entry.getValue(); + for (Session session : serverSessions) { + serverNameIDRelationMap.put(session.getSessionID(), serverName); + } + } + } + return serverNameIDRelationMap; + } + + private static Map generateIDtoUUIDMap(Map>> sessions) { + Map uuidsByID = new HashMap<>(); + for (Map.Entry>> entry : sessions.entrySet()) { + UUID uuid = entry.getKey(); + for (List sessionList : entry.getValue().values()) { + for (Session session : sessionList) { + uuidsByID.put(session.getSessionID(), uuid); + } + } + } + return uuidsByID; + } + + public static String[] creteStructure(JoinInfoPart joinInfoPart) { + Map>> map = new HashMap<>(); + Map> sessions = joinInfoPart.getSessions(); + for (Map.Entry> entry : sessions.entrySet()) { + Map> serverSpecificMap = new HashMap<>(); + serverSpecificMap.put("This server", entry.getValue()); + map.put(entry.getKey(), serverSpecificMap); + } + + List allSessions = sessions.values().stream() + .flatMap(Collection::stream) + .sorted(new SessionStartComparator()) + .collect(Collectors.toList()); + + return creteStructure(map, allSessions, true); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java index e8a466b21..3ff13a72d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java @@ -77,8 +77,9 @@ public class SessionsTableCreator { String world = getLongestWorldPlayed(session); String inspectUrl = Plan.getPlanAPI().getPlayerInspectPageLink(name); + String toolTip = "Session ID: " + (session.isFetchedFromDB() ? session.getSessionID() : "Not Saved."); sessionTableBuilder.append(Html.TABLELINE_4.parse( - Html.LINK.parse(inspectUrl, name), + Html.LINK_TOOLTIP.parse(inspectUrl, name, toolTip), start, length, world diff --git a/Plan/src/main/resources/html/server.html b/Plan/src/main/resources/html/server.html index 75dad1b6c..090d15ddd 100644 --- a/Plan/src/main/resources/html/server.html +++ b/Plan/src/main/resources/html/server.html @@ -14,6 +14,10 @@ +
@@ -183,21 +187,7 @@

50 Most Recent Sessions

- + ${contentSessions}
@@ -358,6 +348,7 @@ +