Allow the server to control category visibility

This commit is contained in:
Cryptkeeper 2016-02-23 19:19:15 -06:00
parent 28160054c0
commit 9ac6502394
4 changed files with 21 additions and 19 deletions

@ -10,8 +10,6 @@ var isConnected = false;
var mojangServicesUpdater; var mojangServicesUpdater;
var sortServersTask; var sortServersTask;
var categoriesVisible = true;
function updateServerStatus(lastEntry) { function updateServerStatus(lastEntry) {
var info = lastEntry.info; var info = lastEntry.info;
var div = $('#status_' + safeName(info.name)); var div = $('#status_' + safeName(info.name));
@ -108,19 +106,6 @@ function sortServers() {
} }
} }
function setCategoriesVisible(newCategoriesVisible) {
categoriesVisible = newCategoriesVisible;
$('.category-header').css('display', (categoriesVisible ? 'block' : 'none'));
$('.server-container').css('margin', (categoriesVisible ? '10px auto' : '0 auto'));
sortServers();
if (typeof(localStorage)) {
localStorage.setItem('categoriesVisible', categoriesVisible);
}
}
function setAllGraphVisibility(visible) { function setAllGraphVisibility(visible) {
if (visible) { if (visible) {
var keys = Object.keys(hiddenGraphData); var keys = Object.keys(hiddenGraphData);
@ -305,8 +290,6 @@ $(document).ready(function() {
}); });
socket.on('add', function(servers) { socket.on('add', function(servers) {
createCategories();
if (Object.keys(publicConfig.categories).length > 0) { if (Object.keys(publicConfig.categories).length > 0) {
$('#category-controller').css('display', 'block'); $('#category-controller').css('display', 'block');
} }

@ -6,9 +6,26 @@ var lastMojangServiceUpdate;
var publicConfig; var publicConfig;
var createdCategories = false; var createdCategories = false;
var categoriesVisible;
function setPublicConfig(json) { function setPublicConfig(json) {
publicConfig = json; publicConfig = json;
$('#server-container-list').html('');
createdCategories = false;
createCategories();
setCategoriesVisible(publicConfig.categoriesVisible);
}
function setCategoriesVisible(newCategoriesVisible) {
categoriesVisible = newCategoriesVisible;
$('.category-header').css('display', (categoriesVisible ? 'block' : 'none'));
$('.server-container').css('margin', (categoriesVisible ? '10px auto' : '0 auto'));
sortServers();
} }
function createCategories() { function createCategories() {

@ -31,5 +31,6 @@
"major": "Major Networks", "major": "Major Networks",
"midsized": "Midsized Networks", "midsized": "Midsized Networks",
"small": "Small Networks" "small": "Small Networks"
} },
"categoriesVisible": true
} }

@ -67,7 +67,8 @@ function handleRequest(req, res) {
categories: categories, categories: categories,
graphDuration: config.graphDuration, graphDuration: config.graphDuration,
servers: servers, servers: servers,
bootTime: util.getBootTime() bootTime: util.getBootTime(),
categoriesVisible: config.categoriesVisible || false
}; };
res.write('setPublicConfig(' + JSON.stringify(publicConfig) + ');'); res.write('setPublicConfig(' + JSON.stringify(publicConfig) + ');');