mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-08 09:27:45 +01:00
[Debt] Created factory for Accordion objects.
SessionAccordion and ServerAccordion are now constructed with a factory. Renamed: AbstractAccordion -> Accordion, as class was not abstract.
This commit is contained in:
parent
ad5837b519
commit
5fc5494da9
@ -21,6 +21,7 @@ import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.PingGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
||||
import com.djrapitops.plan.utilities.html.structure.Accordions;
|
||||
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
|
||||
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
@ -50,6 +51,7 @@ public class AnalysisContainer extends DataContainer {
|
||||
private ServerProperties serverProperties;
|
||||
private Graphs graphs;
|
||||
private HtmlTables tables;
|
||||
private Accordions accordions;
|
||||
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private Formatter<Long> secondLongFormatter;
|
||||
@ -260,7 +262,7 @@ public class AnalysisContainer extends DataContainer {
|
||||
private void addSessionSuppliers() {
|
||||
Key<SessionAccordion> sessionAccordion = new Key<>(SessionAccordion.class, "SESSION_ACCORDION");
|
||||
putSupplier(serverNames, () -> database.fetch().getServerNames());
|
||||
putSupplier(sessionAccordion, () -> SessionAccordion.forServer(
|
||||
putSupplier(sessionAccordion, () -> accordions.serverSessionAccordion(
|
||||
getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all(),
|
||||
getSupplier(serverNames),
|
||||
() -> getUnsafe(AnalysisKeys.PLAYER_NAMES)
|
||||
|
@ -26,6 +26,7 @@ import com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.calendar.PlayerCalendar;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.structure.Accordions;
|
||||
import com.djrapitops.plan.utilities.html.structure.ServerAccordion;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
@ -51,6 +52,7 @@ public class InspectPage implements Page {
|
||||
private final Theme theme;
|
||||
private final Graphs graphs;
|
||||
private final HtmlTables tables;
|
||||
private final Accordions accordions;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Timings timings;
|
||||
|
||||
@ -66,6 +68,7 @@ public class InspectPage implements Page {
|
||||
Theme theme,
|
||||
Graphs graphs,
|
||||
HtmlTables tables,
|
||||
Accordions accordions,
|
||||
Formatters formatters,
|
||||
ServerInfo serverInfo,
|
||||
Timings timings
|
||||
@ -77,6 +80,7 @@ public class InspectPage implements Page {
|
||||
this.theme = theme;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.accordions = accordions;
|
||||
this.serverInfo = serverInfo;
|
||||
this.timings = timings;
|
||||
|
||||
@ -169,13 +173,13 @@ public class InspectPage implements Page {
|
||||
if (config.isTrue(Settings.DISPLAY_SESSIONS_AS_TABLE)) {
|
||||
replacer.put("accordionSessions", tables.playerSessionTable(playerName, allSessions).parseHtml());
|
||||
} else {
|
||||
SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames);
|
||||
SessionAccordion sessionAccordion = accordions.playerSessionAccordion(allSessions, () -> serverNames);
|
||||
replacer.put("accordionSessions", sessionAccordion.toHtml());
|
||||
sessionAccordionViewScript = sessionAccordion.toViewScript();
|
||||
}
|
||||
}
|
||||
|
||||
ServerAccordion serverAccordion = new ServerAccordion(player, serverNames);
|
||||
ServerAccordion serverAccordion = accordions.serverAccordion(player, serverNames);
|
||||
|
||||
PlayerCalendar playerCalendar = graphs.calendar().playerCalendar(player);
|
||||
|
||||
|
@ -12,6 +12,7 @@ import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.structure.Accordions;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.benchmarking.Timings;
|
||||
import com.djrapitops.plugin.logging.debug.DebugLogger;
|
||||
@ -40,6 +41,7 @@ public class PageFactory {
|
||||
private final Lazy<ConnectionSystem> connectionSystem;
|
||||
private final Lazy<Graphs> graphs;
|
||||
private final Lazy<HtmlTables> tables;
|
||||
private final Lazy<Accordions> accordions;
|
||||
private final Lazy<Formatters> formatters;
|
||||
private final Lazy<HookHandler> hookHandler;
|
||||
private final Lazy<DebugLogger> debugLogger;
|
||||
@ -56,6 +58,7 @@ public class PageFactory {
|
||||
Lazy<ConnectionSystem> connectionSystem,
|
||||
Lazy<Graphs> graphs,
|
||||
Lazy<HtmlTables> tables,
|
||||
Lazy<Accordions> accordions,
|
||||
Lazy<Formatters> formatters,
|
||||
Lazy<HookHandler> hookHandler,
|
||||
Lazy<DebugLogger> debugLogger,
|
||||
@ -70,6 +73,7 @@ public class PageFactory {
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.accordions = accordions;
|
||||
this.formatters = formatters;
|
||||
this.hookHandler = hookHandler;
|
||||
this.debugLogger = debugLogger;
|
||||
@ -100,7 +104,8 @@ public class PageFactory {
|
||||
return new InspectPage(
|
||||
player, serverNames,
|
||||
version,
|
||||
config.get(), theme.get(), graphs.get(), tables.get(), formatters.get(),
|
||||
config.get(), theme.get(),
|
||||
graphs.get(), tables.get(), accordions.get(), formatters.get(),
|
||||
serverInfo.get(), timings.get()
|
||||
);
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ import java.util.List;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AbstractAccordion {
|
||||
public class Accordion {
|
||||
|
||||
private final String id;
|
||||
private final List<AccordionElement> elements;
|
||||
|
||||
private String emptyText = "No Data";
|
||||
|
||||
public AbstractAccordion(String id) {
|
||||
public Accordion(String id) {
|
||||
this.id = new Format(id)
|
||||
.removeSymbols()
|
||||
.removeWhitespace()
|
@ -0,0 +1,109 @@
|
||||
package com.djrapitops.plan.utilities.html.structure;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Factory class for different {@link Accordion} objects.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class Accordions {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
private final Graphs graphs;
|
||||
private final HtmlTables tables;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public Accordions(
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
Graphs graphs,
|
||||
HtmlTables tables,
|
||||
Formatters formatters
|
||||
) {
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Session accordion for a Player.
|
||||
*
|
||||
* @param sessions {@link Session}s of the Player.
|
||||
* @param serverNamesSupplier Supplier that provides server name map.
|
||||
* @return a new {@link SessionAccordion}.
|
||||
*/
|
||||
public SessionAccordion playerSessionAccordion(
|
||||
List<Session> sessions,
|
||||
Supplier<Map<UUID, String>> serverNamesSupplier
|
||||
) {
|
||||
boolean appendWorldPercentage = config.isTrue(Settings.APPEND_WORLD_PERC);
|
||||
int maxSessions = config.getNumber(Settings.MAX_SESSIONS);
|
||||
return new SessionAccordion(
|
||||
true, sessions,
|
||||
serverNamesSupplier, HashMap::new,
|
||||
appendWorldPercentage, maxSessions,
|
||||
theme, graphs, tables,
|
||||
formatters.year(), formatters.timeAmount()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Session accordion for a server.
|
||||
*
|
||||
* @param sessions Sessions that have occurred on a server.
|
||||
* @param serverNamesSupplier Supplier for server names.
|
||||
* @param playerNamesSupplier Supplier for names of players.
|
||||
* @return a new {@link SessionAccordion}
|
||||
*/
|
||||
public SessionAccordion serverSessionAccordion(
|
||||
List<Session> sessions,
|
||||
Supplier<Map<UUID, String>> serverNamesSupplier,
|
||||
Supplier<Map<UUID, String>> playerNamesSupplier
|
||||
) {
|
||||
boolean appendWorldPercentage = config.isTrue(Settings.APPEND_WORLD_PERC);
|
||||
int maxSessions = config.getNumber(Settings.MAX_SESSIONS);
|
||||
return new SessionAccordion(
|
||||
false, sessions,
|
||||
serverNamesSupplier, playerNamesSupplier,
|
||||
appendWorldPercentage, maxSessions,
|
||||
theme, graphs, tables,
|
||||
formatters.year(), formatters.timeAmount()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Server breakdown accordion for a player.
|
||||
*
|
||||
* @param player PlayerContainer of the Player.
|
||||
* @param serverNames Names of the servers.
|
||||
* @return a new {@link ServerAccordion}
|
||||
*/
|
||||
public ServerAccordion serverAccordion(PlayerContainer player, Map<UUID, String> serverNames) {
|
||||
return new ServerAccordion(
|
||||
player, serverNames,
|
||||
theme, graphs,
|
||||
formatters.yearLong(), formatters.timeAmount()
|
||||
);
|
||||
}
|
||||
}
|
@ -31,21 +31,30 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ServerAccordion extends AbstractAccordion {
|
||||
public class ServerAccordion extends Accordion {
|
||||
|
||||
private final StringBuilder viewScript;
|
||||
|
||||
private final Map<UUID, String> serverNames;
|
||||
private PerServerContainer perServer;
|
||||
|
||||
// TODO
|
||||
private Theme theme;
|
||||
private Graphs graphs;
|
||||
private Formatter<Long> yearLongFormatter;
|
||||
private Formatter<Long> timeAmountFormatter;
|
||||
private final Theme theme;
|
||||
private final Graphs graphs;
|
||||
private final Formatter<Long> yearLongFormatter;
|
||||
private final Formatter<Long> timeAmountFormatter;
|
||||
|
||||
public ServerAccordion(PlayerContainer container, Map<UUID, String> serverNames) {
|
||||
public ServerAccordion(
|
||||
PlayerContainer container, Map<UUID, String> serverNames,
|
||||
Theme theme,
|
||||
Graphs graphs,
|
||||
Formatter<Long> yearLongFormatter,
|
||||
Formatter<Long> timeAmountFormatter
|
||||
) {
|
||||
super("server_accordion");
|
||||
this.theme = theme;
|
||||
this.graphs = graphs;
|
||||
this.yearLongFormatter = yearLongFormatter;
|
||||
this.timeAmountFormatter = timeAmountFormatter;
|
||||
|
||||
viewScript = new StringBuilder();
|
||||
|
||||
|
@ -6,8 +6,6 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator;
|
||||
@ -27,7 +25,7 @@ import java.util.function.Supplier;
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.data.container.Session for object
|
||||
*/
|
||||
public class SessionAccordion extends AbstractAccordion {
|
||||
public class SessionAccordion extends Accordion {
|
||||
|
||||
private final boolean forPlayer;
|
||||
private final List<Session> sessions;
|
||||
@ -36,42 +34,43 @@ public class SessionAccordion extends AbstractAccordion {
|
||||
|
||||
private final StringBuilder viewScript;
|
||||
private final boolean appendWorldPercentage;
|
||||
private int maxSessions;
|
||||
private final int maxSessions;
|
||||
|
||||
// TODO
|
||||
private PlanConfig config;
|
||||
private Theme theme;
|
||||
private Graphs graphs;
|
||||
private HtmlTables tables;
|
||||
private Formatter<DateHolder> yearFormatter;
|
||||
private Formatter<Long> timeAmountFormatter;
|
||||
private final Theme theme;
|
||||
private final Graphs graphs;
|
||||
private final HtmlTables tables;
|
||||
private final Formatter<DateHolder> yearFormatter;
|
||||
private final Formatter<Long> timeAmountFormatter;
|
||||
|
||||
private SessionAccordion(boolean forPlayer, List<Session> sessions,
|
||||
Supplier<Map<UUID, String>> serverNamesSupplier,
|
||||
Supplier<Map<UUID, String>> playerNamesSupplier) {
|
||||
SessionAccordion(boolean forPlayer, List<Session> sessions,
|
||||
Supplier<Map<UUID, String>> serverNamesSupplier,
|
||||
Supplier<Map<UUID, String>> playerNamesSupplier,
|
||||
boolean appendWorldPercentage,
|
||||
int maxSessions,
|
||||
Theme theme,
|
||||
Graphs graphs,
|
||||
HtmlTables tables,
|
||||
Formatter<DateHolder> yearFormatter,
|
||||
Formatter<Long> timeAmountFormatter
|
||||
) {
|
||||
super("session_accordion");
|
||||
|
||||
this.forPlayer = forPlayer;
|
||||
this.sessions = sessions;
|
||||
this.serverNamesSupplier = serverNamesSupplier;
|
||||
this.playerNamesSupplier = playerNamesSupplier;
|
||||
this.appendWorldPercentage = appendWorldPercentage;
|
||||
this.maxSessions = maxSessions;
|
||||
this.theme = theme;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.yearFormatter = yearFormatter;
|
||||
this.timeAmountFormatter = timeAmountFormatter;
|
||||
viewScript = new StringBuilder();
|
||||
|
||||
maxSessions = config.getNumber(Settings.MAX_SESSIONS);
|
||||
appendWorldPercentage = config.isTrue(Settings.APPEND_WORLD_PERC);
|
||||
|
||||
addElements();
|
||||
}
|
||||
|
||||
public static SessionAccordion forServer(List<Session> sessions, Supplier<Map<UUID, String>> serverNamesSupplier,
|
||||
Supplier<Map<UUID, String>> playerNamesSupplier) {
|
||||
return new SessionAccordion(false, sessions, serverNamesSupplier, playerNamesSupplier);
|
||||
}
|
||||
|
||||
public static SessionAccordion forPlayer(List<Session> sessions, Supplier<Map<UUID, String>> serverNamesSupplier) {
|
||||
return new SessionAccordion(true, sessions, serverNamesSupplier, HashMap::new);
|
||||
}
|
||||
|
||||
public String toViewScript() {
|
||||
return viewScript.toString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user