From f63d9bba4b968f30214928252c60fc221cf5967d Mon Sep 17 00:00:00 2001 From: Nick Krecklow Date: Mon, 30 Mar 2020 01:06:30 -0500 Subject: [PATCH] remove legacy category system --- assets/css/main.css | 11 +++------ assets/html/index.html | 2 +- assets/js/site.js | 55 ++++++++++-------------------------------- assets/js/util.js | 47 ------------------------------------ config.json | 5 ---- lib/server.js | 25 ------------------- servers.json | 6 ++--- 7 files changed, 19 insertions(+), 132 deletions(-) diff --git a/assets/css/main.css b/assets/css/main.css index afc787b..076bccc 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -110,7 +110,9 @@ strong { /* Server listing */ .server-container { overflow: auto; - display: flex; flex-wrap: wrap; justify-content: center; + display: flex; + flex-wrap: wrap; + justify-content: center; } .server { @@ -155,13 +157,6 @@ strong { margin-bottom: 2px; } -.category-header { - margin-bottom: 10px; - margin-left: 15px; - text-align: left; - display: none; -} - .server-meta { font-size: 16px !important; } diff --git a/assets/html/index.html b/assets/html/index.html index e48d8e4..426ecf7 100644 --- a/assets/html/index.html +++ b/assets/html/index.html @@ -72,7 +72,7 @@ -
+
diff --git a/assets/js/site.js b/assets/js/site.js index 7acd849..40bd668 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -83,49 +83,22 @@ function updateServerStatus(lastEntry) { } function sortServers() { - if (categoriesVisible) { - var byCategories = getServersByCategory(); + var serverNames = []; - var categories = Object.keys(byCategories); + var keys = Object.keys(lastPlayerEntries); - for (var i = 0; i < categories.length; i++) { - var relevantPlayers = []; + for (var i = 0; i < keys.length; i++) { + serverNames.push(keys[i]); + } - for (var x = 0; x < byCategories[categories[i]].length; x++) { - var server = byCategories[categories[i]][x]; + serverNames.sort(function(a, b) { + return (lastPlayerEntries[b] || 0) - (lastPlayerEntries[a] || 0); + }); - relevantPlayers[server.name] = lastPlayerEntries[server.name]; - } - - var keys = Object.keys(relevantPlayers); - - keys.sort(function(a, b) { - return relevantPlayers[b] - relevantPlayers[a]; - }); - - for (var x = 0; x < keys.length; x++) { - $('#container_' + safeName(keys[x])).appendTo('#server-container-' + categories[i]); - $('#ranking_' + safeName(keys[x])).text('#' + (x + 1)); - } - } - } else { - var serverNames = []; - - var keys = Object.keys(lastPlayerEntries); - - for (var i = 0; i < keys.length; i++) { - serverNames.push(keys[i]); - } - - serverNames.sort(function(a, b) { - return (lastPlayerEntries[b] || 0) - (lastPlayerEntries[a] || 0); - }); - - for (var i = 0; i < serverNames.length; i++) { - $('#container_' + safeName(serverNames[i])).appendTo('#server-container-all'); - $('#ranking_' + safeName(serverNames[i])).text('#' + (i + 1)); - } - } + for (var i = 0; i < serverNames.length; i++) { + $('#container_' + safeName(serverNames[i])).appendTo('#server-container-list'); + $('#ranking_' + safeName(serverNames[i])).text('#' + (i + 1)); + } } function updatePercentageBar() { @@ -295,8 +268,6 @@ $(document).ready(function() { $('#server-container-list').html(''); - createdCategories = false; - $('#big-graph').html(''); $('#big-graph-checkboxes').html(''); $('#big-graph-controls').css('display', 'none'); @@ -437,7 +408,7 @@ $(document).ready(function() {
\
\
' - }).appendTo("#server-container-" + getServerByIp(info.ip).category); + }).appendTo("#server-container-list"); var favicon = MISSING_FAVICON_BASE64; diff --git a/assets/js/util.js b/assets/js/util.js index e1990c2..ca2fa92 100644 --- a/assets/js/util.js +++ b/assets/js/util.js @@ -5,9 +5,6 @@ var tooltip = $('#tooltip'); var lastMojangServiceUpdate; var publicConfig; -var createdCategories = false; -var categoriesVisible; - function showCaption(html) { var tagline = $('#tagline-text'); tagline.stop(true, false); @@ -23,51 +20,7 @@ function hideCaption() { function setPublicConfig(json) { publicConfig = json; - $('#server-container-list').html(''); - - createdCategories = false; - - createCategories(); - - if (publicConfig.categoriesVisible) { - $('.category-header').css('display', 'block'); - $('.server-container').css('margin', '10px auto'); - - sortServers(); - } -} - -function createCategories() { - if (!createdCategories) { - createdCategories = true; - - var keys = Object.keys(publicConfig.categories); - - for (var i = 0; i < keys.length; i++) { - var title = publicConfig.categories[keys[i]]; - - $('#server-container-list').append('

' + title + '

'); - } - - $('#server-container-list').append('
'); - } -} - -function getServersByCategory() { - var byCategory = {}; - - for (var i = 0; i < publicConfig.servers.length; i++) { - var entry = publicConfig.servers[i]; - - if (!byCategory[entry.category]) { - byCategory[entry.category] = []; - } - - byCategory[entry.category].push(entry); - } - - return byCategory; } function getServerByField(id, value) { diff --git a/config.json b/config.json index 395a461..846084f 100644 --- a/config.json +++ b/config.json @@ -22,10 +22,6 @@ }, "logToDatabase": false, "graphDuration": 86400000, - "serverCategories": { - "minigames": "Minigame Networks", - "pocket": "Pocket Edition Networks" - }, "versions": { "PC": [ 4, @@ -42,6 +38,5 @@ 0 ] }, - "categoriesVisible": true, "serverTypesVisible": true } diff --git a/lib/server.js b/lib/server.js index ccc7112..1d82f2d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -41,35 +41,10 @@ function handleRequest(req, res) { } else if (requestUrl === '/publicConfig.json') { res.setHeader('Content-Type', 'application/javascript'); - var categories = config.serverCategories; - - // Legacy support for people without categories configured. - if (!categories || Object.keys(categories).length === 0) { - categories = { - 'default': 'All Networks' - }; - } - - for (var i = 0; i < servers.length; i++) { - var entry = servers[i]; - - if (!entry.category) { - entry.category = 'default'; - - logger.warn('%s has no category, defaulting!', entry.name); - } else if (!categories[entry.category]) { - logger.warn('%s has an unknown category (%s), defaulting!', entry.name, entry.category); - - entry.category = 'default'; - } - } - var publicConfig = { - categories: categories, graphDuration: config.graphDuration, servers: servers, bootTime: util.getBootTime(), - categoriesVisible: config.categoriesVisible || false, serverTypesVisible: config.serverTypesVisible || false, minecraftVersions: minecraft.versions }; diff --git a/servers.json b/servers.json index 1030ef5..5fbba52 100644 --- a/servers.json +++ b/servers.json @@ -2,13 +2,11 @@ { "name": "Hypixel", "ip": "mc.hypixel.net", - "type": "PC", - "category": "minigames" + "type": "PC" }, { "name": "HiveMC", "ip": "play.hivemc.com", - "type": "PC", - "category": "minigames" + "type": "PC" } ]