From 6715244b2cc8ca53c369e823f5a81d64f2fb1386 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Thu, 11 Feb 2021 12:43:31 +0200 Subject: [PATCH] Made session accordion load again --- .../resolver/json/SessionsJSONResolver.java | 23 +++- .../assets/plan/web/js/sessionAccordion.js | 121 ++++++++++-------- .../resources/assets/plan/web/network.html | 2 +- .../resources/assets/plan/web/server.html | 2 +- 4 files changed, 88 insertions(+), 60 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/SessionsJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/SessionsJSONResolver.java index fc47016f7..5072a9185 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/SessionsJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/SessionsJSONResolver.java @@ -17,12 +17,14 @@ package com.djrapitops.plan.delivery.webserver.resolver.json; import com.djrapitops.plan.delivery.rendering.json.JSONFactory; +import com.djrapitops.plan.delivery.web.resolver.MimeType; import com.djrapitops.plan.delivery.web.resolver.Resolver; import com.djrapitops.plan.delivery.web.resolver.Response; import com.djrapitops.plan.delivery.web.resolver.request.Request; import com.djrapitops.plan.delivery.web.resolver.request.WebUser; +import com.djrapitops.plan.delivery.webserver.cache.AsyncJSONResolverService; import com.djrapitops.plan.delivery.webserver.cache.DataID; -import com.djrapitops.plan.delivery.webserver.cache.JSONCache; +import com.djrapitops.plan.delivery.webserver.cache.JSONStorage; import com.djrapitops.plan.identification.Identifiers; import javax.inject.Inject; @@ -40,14 +42,17 @@ import java.util.UUID; public class SessionsJSONResolver implements Resolver { private final Identifiers identifiers; + private final AsyncJSONResolverService jsonResolverService; private final JSONFactory jsonFactory; @Inject public SessionsJSONResolver( Identifiers identifiers, + AsyncJSONResolverService jsonResolverService, JSONFactory jsonFactory ) { this.identifiers = identifiers; + this.jsonResolverService = jsonResolverService; this.jsonFactory = jsonFactory; } @@ -62,11 +67,23 @@ public class SessionsJSONResolver implements Resolver { } private Response getResponse(Request request) { + return Response.builder() + .setMimeType(MimeType.JSON) + .setJSONContent(getStoredJSON(request).json) + .build(); + } + + private JSONStorage.StoredJSON getStoredJSON(Request request) { + long timestamp = Identifiers.getTimestamp(request); if (request.getQuery().get("server").isPresent()) { UUID serverUUID = identifiers.getServerUUID(request); - return JSONCache.getOrCache(DataID.SESSIONS, serverUUID, () -> Collections.singletonMap("sessions", jsonFactory.serverSessionsAsJSONMap(serverUUID))); + return jsonResolverService.resolve(timestamp, DataID.SESSIONS, serverUUID, + theUUID -> Collections.singletonMap("sessions", jsonFactory.serverSessionsAsJSONMap(theUUID)) + ); } // Assume network - return JSONCache.getOrCache(DataID.SESSIONS, () -> Collections.singletonMap("sessions", jsonFactory.networkSessionsAsJSONMap())); + return jsonResolverService.resolve(timestamp, DataID.SESSIONS, + () -> Collections.singletonMap("sessions", jsonFactory.networkSessionsAsJSONMap()) + ); } } \ No newline at end of file diff --git a/Plan/common/src/main/resources/assets/plan/web/js/sessionAccordion.js b/Plan/common/src/main/resources/assets/plan/web/js/sessionAccordion.js index 4678ec3ff..592944ba9 100644 --- a/Plan/common/src/main/resources/assets/plan/web/js/sessionAccordion.js +++ b/Plan/common/src/main/resources/assets/plan/web/js/sessionAccordion.js @@ -1,49 +1,48 @@ function loadSessionAccordion(json, error) { - sessionTable = $("#sessions-overview").find("#tableAccordion").find("tbody"); + const sessionTable = document.querySelector('#sessions-overview #tableAccordion tbody'); if (error) { - sessionTable.append(`
Failed to load player kills: ` + error + '
'); + $('#playerKillTable').replaceWith(`Failed to load player kills: ${error}
`); return; } $('#playerKillTable').replaceWith(createKillsTable(json.player_kills)); @@ -59,7 +58,7 @@ function loadPlayerKills(json, error) { function loadPlayerdeaths(json, error) { if (error) { - $('#playerDeathTable').replaceWith(`Failed to load player deaths: ` + error + '
'); + $('#playerDeathTable').replaceWith(`Failed to load player deaths: ${error}
`); return; } $('#playerDeathTable').replaceWith(createKillsTable(json.player_deaths)); @@ -67,50 +66,62 @@ function loadPlayerdeaths(json, error) { function createAccordionTitle(i, session) { let style = session.start.includes("Online") ? 'bg-teal' : 'bg-teal-outline'; - return `Ended` + session.end + `
` + - `Length` + session.length + `
` + - `AFK Time` + session.afk_time + `
` + - `Server` + session.server_name + `
` + - (session.avg_ping ? `Average Ping` + session.avg_ping + `
` : ``) + - `Player Kills` + session.player_kills.length + `
` + - `Mob Kills` + session.mob_kills + `
` + - `Deaths` + session.deaths + `
Ended${session.end}
+Length${session.length}
+AFK Time${session.afk_time}
+Server${session.server_name}
+ ${session.avg_ping ? `Average Ping` + session.avg_ping + `
` : ``} +Player Kills${session.player_kills.length}
+Mob Kills${session.mob_kills}
+Deaths${session.deaths}
+None | - | - |
' + kill.date + ' | ' + - '' + kill.killer + - (kill.killer === kill.victim ? '' : '') + - kill.victim + ' | ' + - '' + kill.weapon + ' |
${kill.date} | +${kill.killer} ${ + kill.killer === kill.victim + ? '' + : '' + } ${kill.victim} | +${kill.weapon} | +