Session tab accodrdion

This commit is contained in:
Rsl1122 2017-11-22 12:36:45 +02:00
parent 3d84262fef
commit 32fd2dc5aa
9 changed files with 3980 additions and 102 deletions

View File

@ -82,8 +82,8 @@ public class API {
* @return {@code ../player/PlayerName}
*/
public String getPlayerInspectPageLink(String name) {
String link = "../player/" + name;
return link.replace(" ", "%20").replace(".", "%2E");
String link = "../player/" + name.replace(" ", "%20").replace(".", "%2E");
return link;
}
/**

View File

@ -64,7 +64,7 @@ public class JoinInfoPart extends RawData {
private void sessionTables() {
String[] tables = SessionsTableCreator.createTable(this);
String[] sessionContent = SessionTabStructureCreator.creteStructure(this);
addValue("contentSessions", sessionContent[0]);
addValue("accordionSessions", sessionContent[0]);
addValue("sessionTabGraphViewFunctions", sessionContent[1]);
addValue("tableBodySessions", tables[0]);
addValue("tableBodyRecentLogins", tables[1]);

View File

@ -11,7 +11,6 @@ import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.ParseException;
import main.java.com.djrapitops.plan.data.Action;
import main.java.com.djrapitops.plan.data.GeoInfo;
import main.java.com.djrapitops.plan.data.PlayerProfile;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
@ -52,7 +51,6 @@ public class InspectPageParser extends PageParser {
public String parse() throws ParseException {
try {
// TODO Player is online parts
Log.logDebug("Database", "Inspect Parse Fetch");
Benchmark.start("Inspect Parse, Fetch");
Database db = plugin.getDB();
@ -70,7 +68,9 @@ public class InspectPageParser extends PageParser {
String online = "Offline";
Optional<Session> activeSession = plugin.getInfoManager().getDataCache().getCachedSession(uuid);
if (activeSession.isPresent()) {
profile.addActiveSession(activeSession.get());
Session session = activeSession.get();
session.setSessionID(Integer.MAX_VALUE);
profile.addActiveSession(session);
online = serverNames.get(serverUuid);
}
activeSession.ifPresent(profile::addActiveSession);
@ -103,19 +103,6 @@ public class InspectPageParser extends PageParser {
addValue("tableBodyNicknames", NicknameTableCreator.createTable(profile.getNicknames(), serverNames));
addValue("tableBodyIPs", IpTableCreator.createTable(profile.getGeoInformation()));
// TODO REMOVE after 4.1.0
List<String> nicknames = profile.getNicknames().values().stream()
.flatMap(Collection::stream)
.distinct()
.map(HtmlUtils::swapColorsToSpan)
.collect(Collectors.toList());
List<String> geoLocations = profile.getGeoInformation().stream()
.map(GeoInfo::getGeolocation)
.collect(Collectors.toList());
addValue("nicknames", HtmlStructure.createDotList(nicknames.toArray(new String[nicknames.size()])));
addValue("geolocations", HtmlStructure.createDotList(geoLocations.toArray(new String[geoLocations.size()])));
//
Map<UUID, List<Session>> sessions = profile.getSessions();
Map<String, List<Session>> sessionsByServerName = sessions.entrySet().stream()
.collect(Collectors.toMap(entry -> serverNames.get(entry.getKey()), Map.Entry::getValue));
@ -125,7 +112,7 @@ public class InspectPageParser extends PageParser {
.collect(Collectors.toList());
String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessionsByServerName, allSessions, uuid);
addValue("contentSessions", sessionsTabContent[0]);
addValue("accordionSessions", sessionsTabContent[0]);
addValue("sessionTabGraphViewFunctions", sessionsTabContent[1]);
addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessionsByServerName));

View File

@ -34,6 +34,7 @@ public enum Html {
BUTTON("<a class=\"button\" href=\"${0}\">${1}</a>"),
BUTTON_CLASS("class=\"button\""),
LINK("<a class=\"link\" href=\"${0}\">${1}</a>"),
LINK_A("<a href=\"${0}\">${1}</a>"),
LINK_TOOLTIP("<a title=\"${2}\" class=\"link\" href=\"${0}\">${1}</a>"),
LINK_EXTERNAL("<a class=\"link\" target=\"_blank\" href=\"${0}\">${1}</a>"),
LINK_CLASS("class=\"link\""),
@ -49,9 +50,9 @@ public enum Html {
ROW("<div class=\"row\">${0}</div>"),
//
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_START_2("<table class=\"table table-striped\"><thead><tr><th>${0}</th><th>${1}</th></tr></thead><tbody>"),
TABLE_START_3("<table class=\"table table-striped\"><thead><tr><th>${0}</th><th>${1}</th><th>${2}</th></tr></thead><tbody>"),
TABLE_START_4("<table class=\"table table-striped\"><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") + "${3}" + TABLE_END.parse())
),

View File

@ -92,7 +92,6 @@ public class HtmlStructure {
return builder.toString();
}
@Deprecated
public static String[] createSessionsTabContentInspectPage(Map<String, List<Session>> sessions, List<Session> allSessions, UUID uuid) {
Map<UUID, Map<String, List<Session>>> map = new HashMap<>();
map.put(uuid, sessions);
@ -357,9 +356,9 @@ public class HtmlStructure {
StringBuilder html = new StringBuilder("<p>");
if (offline) {
html.append(Html.FA_COLORED_ICON.parse("red", "ball")).append(" ").append(online);
html.append(Html.FA_COLORED_ICON.parse("red", "circle")).append(" ").append(online);
} else {
html.append(Html.FA_COLORED_ICON.parse("green", "ball")).append(" ").append(online);
html.append(Html.FA_COLORED_ICON.parse("green", "circle")).append(" Online (").append(online).append(")");
}
html.append("</p>");
if (op) {

View File

@ -38,16 +38,14 @@ public class SessionTabStructureCreator {
}
if (Verify.isEmpty(allSessions)) {
return new String[]{"<div class=\"session column\">" +
"<div class=\"session-header\">" +
"<div class=\"session-col\" style=\"width: 200%;\">" +
return new String[]{"<div class=\"body\">" +
"<h3>No Sessions</h3>" +
"</div></div></div>", ""};
"</div>", ""};
}
Map<Integer, String> serverNameIDMap = generateIDtoServerNameMap(sessions);
StringBuilder html = new StringBuilder();
StringBuilder html = new StringBuilder("<div class=\"panel-group scrollbar\" id=\"session_accordion\" role=\"tablist\" aria-multiselectable=\"true\">");
StringBuilder viewScript = new StringBuilder();
int i = 0;
for (Session session : allSessions) {
@ -61,79 +59,90 @@ public class SessionTabStructureCreator {
String sessionStart = FormatUtils.formatTimeStampYear(session.getSessionStart());
String sessionLength = FormatUtils.formatTimeAmount(session.getLength());
String sessionEnd = FormatUtils.formatTimeStampYear(session.getSessionEnd());
String sessionEnd = session.getSessionEnd() == -1 ? "Online" : FormatUtils.formatTimeStampYear(session.getSessionEnd());
int playerKillCount = session.getPlayerKills().size();
String name = Plan.getInstance().getDataCache().getName(uuid);
String link = Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(name), name);
String link = Plan.getPlanAPI().getPlayerInspectPageLink(name);
String dotSeparated = appendName ?
HtmlStructure.separateWithDots(link, sessionStart, sessionLength) :
HtmlStructure.separateWithDots(sessionStart, sessionLength);
// Session-column starts & header.
html.append("<div class=\"session column\">")
.append("<div title=\"Session ID: ").append(sessionID).append("\" class=\"session-header\">")
.append("<div class=\"session-col\" style=\"width: 200%;\">")
.append("<h3><i style=\"color:#777\" class=\"fa fa-chevron-down\" aria-hidden=\"true\"></i> ").append(dotSeparated).append("</h3>")
.append("</div>")
.append("</div>");
// Left side of Session box
html.append("<div class=\"session-content\">")
.append("<div class=\"row\">") //
.append("<div class=\"session-col\" style=\"padding: 0px;\">");
// Left side header
html.append("<div class=\"box-header\" style=\"margin: 0px;\">")
.append("<h2><i class=\"fa fa-calendar\" aria-hidden=\"true\"></i> ")
.append(sessionStart)
.append("</h2>")
.append("</div>");
// Left side content
html.append("<div class=\"box\" style=\"margin: 0px;\">")
.append("<p>Session Length: ").append(sessionLength).append("<br>")
.append("Session Ended: ").append(sessionEnd).append("<br>")
.append("Server: ").append(serverName).append("<br><br>")
.append("Mob Kills: ").append(session.getMobKills()).append("<br>")
.append("Deaths: ").append(session.getDeaths()).append("</p>");
html.append(KillsTableCreator.createTable(session.getPlayerKills()))
.append("</div>"); // Left Side content ends
// Left side ends & Right side starts
html.append("</div>")
.append("<div class=\"session-col\">");
HtmlStructure.separateWithDots(name, sessionStart) :
sessionStart;
String id = "worldPie" + session.getSessionStart() + i;
html.append("<div id=\"").append(id).append("\" style=\"width: 100%; height: 400px;\"></div>");
WorldTimes worldTimes = session.getWorldTimes();
AnalysisUtils.addMissingWorlds(worldTimes);
String[] worldData = WorldPieCreator.createSeriesData(worldTimes);
html.append("<script>")
String killTable = KillsTableCreator.createTable(session.getPlayerKills());
// Accordion panel header
html.append("<div title=\"Session ID: ").append(sessionID).append("\"class=\"panel panel-col-teal\">")
.append("<div class=\"panel-heading\" role=\"tab\" id=\"heading_").append(sessionID).append("\">")
.append("<h4 class=\"panel-title\">")
.append("<a class=\"collapsed\" role=\"button\" data-toggle=\"collapse\" data-parent=\"#session_accordion\" ")
.append("href=\"#session_").append(sessionID).append("\" aria-expanded=\"false\" ")
.append("aria-controls=\"session_").append(sessionID).append("\">")
.append(dotSeparated).append("<span class=\"pull-right\">").append(sessionLength).append("</span>") // Title (header)
.append("</a></h4>") // Closes collapsed, panel title
.append("</div>"); // Closes panel heading
// Content
html.append("<div id=\"session_").append(sessionID).append("\" class=\"panel-collapse collapse\" role=\"tabpanel\"")
.append(" aria-labelledby=\"heading_").append(sessionID).append("\">")
.append("<div class=\"panel-body\"><div class=\"row clearfix\">")
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Left col-6
//
.append("<div class=\"font-bold m-b--35\"><i class=\"col-teal fa fa-clock-o\"></i> ")
.append(sessionStart).append(" -> ").append(sessionEnd).append(" </div>")
//
.append("<ul class=\"dashboard-stat-list\">")
// End
.append("<li><i class=\"col-teal fa fa-clock-o\"></i> Session Ended<span class=\"pull-right\"><b>").append(sessionEnd).append("</b></span></li>")
// Length
.append("<li><i class=\"col-teal fa fa-clock-o\"></i> Session Length<span class=\"pull-right\"><b>").append(sessionLength).append("</b></span></li>")
// Server
.append("<li><i class=\"col-light-green fa fa-server\"></i> Server<span class=\"pull-right\"><b>").append(serverName).append("</b></span></li>")
.append("<li></li>")
// Player Kills
.append("<li><i class=\"col-red fa fa-crosshairs\"></i> Player Kills<span class=\"pull-right\"><b>").append(playerKillCount).append("</b></span></li>")
// Mob Kills
.append("<li><i class=\"col-green fa fa-crosshairs\"></i> Mob Kills<span class=\"pull-right\"><b>").append(session.getMobKills()).append("</b></span></li>")
// Deaths
.append("<li><i class=\"col-red fa fa-frown-o\"></i> Deaths<span class=\"pull-right\"><b>").append(session.getDeaths()).append("</b></span></li>")
.append("</ul></div>") // Closes stat-list, Left col-6
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Right col-6
.append("<div id=\"").append(id).append("\" class=\"dashboard-donut-chart\"></div>")
// World Pie data script
.append("<script>")
.append("var ").append(id).append("series = {name:'World Playtime',colors: worldPieColors,colorByPoint:true,data:").append(worldData[0]).append("};")
.append("var ").append(id).append("gmseries = ").append(worldData[1]).append(";")
.append("</script>");
.append("</script>")
.append("</div>") // Right col-6
.append("</div>") // Closes row clearfix
.append("<div class=\"row clearfix\">")
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Left2 col-6
.append(killTable)
.append("</div>"); // Closes Left2 col-6
if (appendName) {
html.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Right2 col-6
.append("<button href=\"").append(link).append("\" type=\"button\" class=\"pull-right btn bg-blue waves-effect\"><i class=\"material-icons\">person</i><span>INSPECT PAGE</span></button>")
.append("</div>"); // Closes Right2 col-6
}
html.append("</div>") // Closes row clearfix
.append("</div>") // Closes panel-body
.append("</div>") // Closes panel-collapse
.append("</div>"); // Closes panel
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("</div>")
.append("</div>")
.append("</div>")
.append("</div>");
i++;
}
return new String[]{html.toString(), viewScript.toString()};
return new String[]{html.append("</div>").toString(), viewScript.toString()};
}
private static Map<Integer, String> generateIDtoServerNameMap(Map<UUID, Map<String, List<Session>>> sessions) {

View File

@ -452,7 +452,6 @@
</div>
<!-- #END# Server Preference Pie -->
</div>
</div>
</div>
<!-- #END# Tab Sessions -->

File diff suppressed because it is too large Load Diff

View File

@ -4,20 +4,16 @@ import main.java.com.djrapitops.plan.data.Session;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.plugin.java.JavaPlugin;
import org.junit.Before;
import org.junit.Ignore;
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;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
@ -45,17 +41,4 @@ public class HtmlStructureTest {
assertEquals(opened, closed);
}
@Test
// TODO fix DataCache mock dependency
@Ignore("Has some DataCache mock issue")
public void createSessionsTabContent() throws Exception {
List<Session> allSessions = sessions.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
String[] sessionsTab = HtmlStructure.createSessionsTabContentInspectPage(sessions, allSessions, MockUtils.getPlayerUUID());
int opened = StringUtils.countMatches(sessionsTab[0], "<div");
int closed = StringUtils.countMatches(sessionsTab[0], "</div");
assertEquals(opened, closed);
}
}