diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java index 4efd960eb..8b19eb2ca 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java @@ -44,6 +44,7 @@ import com.djrapitops.plan.storage.database.queries.objects.*; import com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery; import com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery; import com.djrapitops.plan.utilities.comparators.SessionStartComparator; +import com.djrapitops.plan.utilities.java.Maps; import javax.inject.Inject; import javax.inject.Singleton; @@ -222,14 +223,18 @@ public class JSONFactory { return servers; } - public List> pingPerGeolocation(UUID serverUUID) { + public Map pingPerGeolocation(UUID serverUUID) { Map pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID)); - return turnToTableEntries(pingByGeolocation); + return Maps.builder(String.class, Object.class) + .put("table", turnToTableEntries(pingByGeolocation)) + .build(); } - public List> pingPerGeolocation() { + public Map pingPerGeolocation() { Map pingByGeolocation = dbSystem.getDatabase().query(PingQueries.fetchPingDataOfNetworkByGeolocation()); - return turnToTableEntries(pingByGeolocation); + return Maps.builder(String.class, Object.class) + .put("table", turnToTableEntries(pingByGeolocation)) + .build(); } private List> turnToTableEntries(Map pingByGeolocation) { @@ -238,12 +243,12 @@ public class JSONFactory { String geolocation = entry.getKey(); Ping ping = entry.getValue(); - Map tableEntry = new HashMap<>(); - tableEntry.put("country", geolocation); - tableEntry.put("avg_ping", formatters.decimals().apply(ping.getAverage()) + " ms"); - tableEntry.put("min_ping", ping.getMin() + " ms"); - tableEntry.put("max_ping", ping.getMax() + " ms"); - tableEntries.add(tableEntry); + tableEntries.add(Maps.builder(String.class, Object.class) + .put("country", geolocation) + .put("avg_ping", formatters.decimals().apply(ping.getAverage()) + " ms") + .put("min_ping", ping.getMin() + " ms") + .put("max_ping", ping.getMax() + " ms") + .build()); } return tableEntries; } diff --git a/Plan/common/src/main/resources/assets/plan/web/js/pingTable.js b/Plan/common/src/main/resources/assets/plan/web/js/pingTable.js index 9ec78e052..b36ada6f9 100644 --- a/Plan/common/src/main/resources/assets/plan/web/js/pingTable.js +++ b/Plan/common/src/main/resources/assets/plan/web/js/pingTable.js @@ -1,32 +1,26 @@ function loadPingTable(json, error) { - pingTable = $("#geolocations").find("#data_ping_table").find("tbody"); + const pingTable = document.querySelector('#geolocations #data_ping_table tbody'); if (error) { - pingTable.append('Error: ' + error + '---'); + pingTable.innerHTML = `Error: ${error}---`; return; } - var countries = json; + const countries = json.table; if (!countries.length) { - pingTable.append('No Data---'); + pingTable.innerHTML = 'No Data---'; return; } - var tableHtml = ''; - - for (var i = 0; i < countries.length; i++) { - var country = countries[i]; - tableHtml += createPingTableRow(country); - } - - pingTable.append(tableHtml); + pingTable.innerHTML = countries.map(createPingTableRow).join(''); } function createPingTableRow(entry) { - return '' + entry.country + - '' + entry.avg_ping + - '' + entry.min_ping + - '' + entry.max_ping + - '' + return ` + ${entry.country} + ${entry.avg_ping} + ${entry.min_ping} + ${entry.max_ping} + ` } \ No newline at end of file