remove legacy category system

This commit is contained in:
Nick Krecklow 2020-03-30 01:06:30 -05:00
parent a458038075
commit f63d9bba4b
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94
7 changed files with 19 additions and 132 deletions

@ -110,7 +110,9 @@ strong {
/* Server listing */ /* Server listing */
.server-container { .server-container {
overflow: auto; overflow: auto;
display: flex; flex-wrap: wrap; justify-content: center; display: flex;
flex-wrap: wrap;
justify-content: center;
} }
.server { .server {
@ -155,13 +157,6 @@ strong {
margin-bottom: 2px; margin-bottom: 2px;
} }
.category-header {
margin-bottom: 10px;
margin-left: 15px;
text-align: left;
display: none;
}
.server-meta { .server-meta {
font-size: 16px !important; font-size: 16px !important;
} }

@ -72,7 +72,7 @@
</div> </div>
<div id="server-container-list"></div> <div id="server-container-list" class="server-container"></div>
</div> </div>

@ -83,32 +83,6 @@ function updateServerStatus(lastEntry) {
} }
function sortServers() { function sortServers() {
if (categoriesVisible) {
var byCategories = getServersByCategory();
var categories = Object.keys(byCategories);
for (var i = 0; i < categories.length; i++) {
var relevantPlayers = [];
for (var x = 0; x < byCategories[categories[i]].length; x++) {
var server = byCategories[categories[i]][x];
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 serverNames = [];
var keys = Object.keys(lastPlayerEntries); var keys = Object.keys(lastPlayerEntries);
@ -122,10 +96,9 @@ function sortServers() {
}); });
for (var i = 0; i < serverNames.length; i++) { for (var i = 0; i < serverNames.length; i++) {
$('#container_' + safeName(serverNames[i])).appendTo('#server-container-all'); $('#container_' + safeName(serverNames[i])).appendTo('#server-container-list');
$('#ranking_' + safeName(serverNames[i])).text('#' + (i + 1)); $('#ranking_' + safeName(serverNames[i])).text('#' + (i + 1));
} }
}
} }
function updatePercentageBar() { function updatePercentageBar() {
@ -295,8 +268,6 @@ $(document).ready(function() {
$('#server-container-list').html(''); $('#server-container-list').html('');
createdCategories = false;
$('#big-graph').html(''); $('#big-graph').html('');
$('#big-graph-checkboxes').html(''); $('#big-graph-checkboxes').html('');
$('#big-graph-controls').css('display', 'none'); $('#big-graph-controls').css('display', 'none');
@ -437,7 +408,7 @@ $(document).ready(function() {
<div class="column" style="float: right;">\ <div class="column" style="float: right;">\
<div class="chart" id="chart_' + safeNameCopy + '"></div>\ <div class="chart" id="chart_' + safeNameCopy + '"></div>\
</div>' </div>'
}).appendTo("#server-container-" + getServerByIp(info.ip).category); }).appendTo("#server-container-list");
var favicon = MISSING_FAVICON_BASE64; var favicon = MISSING_FAVICON_BASE64;

@ -5,9 +5,6 @@ var tooltip = $('#tooltip');
var lastMojangServiceUpdate; var lastMojangServiceUpdate;
var publicConfig; var publicConfig;
var createdCategories = false;
var categoriesVisible;
function showCaption(html) { function showCaption(html) {
var tagline = $('#tagline-text'); var tagline = $('#tagline-text');
tagline.stop(true, false); tagline.stop(true, false);
@ -23,51 +20,7 @@ function hideCaption() {
function setPublicConfig(json) { function setPublicConfig(json) {
publicConfig = json; publicConfig = json;
$('#server-container-list').html(''); $('#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('<div id="server-container-' + keys[i] + '" class="container server-container"><h3 class="category-header">' + title + '</h3></div>');
}
$('#server-container-list').append('<div id="server-container-all" class="container server-container"></div>');
}
}
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) { function getServerByField(id, value) {

@ -22,10 +22,6 @@
}, },
"logToDatabase": false, "logToDatabase": false,
"graphDuration": 86400000, "graphDuration": 86400000,
"serverCategories": {
"minigames": "Minigame Networks",
"pocket": "Pocket Edition Networks"
},
"versions": { "versions": {
"PC": [ "PC": [
4, 4,
@ -42,6 +38,5 @@
0 0
] ]
}, },
"categoriesVisible": true,
"serverTypesVisible": true "serverTypesVisible": true
} }

@ -41,35 +41,10 @@ function handleRequest(req, res) {
} else if (requestUrl === '/publicConfig.json') { } else if (requestUrl === '/publicConfig.json') {
res.setHeader('Content-Type', 'application/javascript'); 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 = { var publicConfig = {
categories: categories,
graphDuration: config.graphDuration, graphDuration: config.graphDuration,
servers: servers, servers: servers,
bootTime: util.getBootTime(), bootTime: util.getBootTime(),
categoriesVisible: config.categoriesVisible || false,
serverTypesVisible: config.serverTypesVisible || false, serverTypesVisible: config.serverTypesVisible || false,
minecraftVersions: minecraft.versions minecraftVersions: minecraft.versions
}; };

@ -2,13 +2,11 @@
{ {
"name": "Hypixel", "name": "Hypixel",
"ip": "mc.hypixel.net", "ip": "mc.hypixel.net",
"type": "PC", "type": "PC"
"category": "minigames"
}, },
{ {
"name": "HiveMC", "name": "HiveMC",
"ip": "play.hivemc.com", "ip": "play.hivemc.com",
"type": "PC", "type": "PC"
"category": "minigames"
} }
] ]