Sammy Libre
8 years ago
6 changed files with 131 additions and 15 deletions
@ -1,38 +1,75 @@
@@ -1,38 +1,75 @@
|
||||
HandlebarsIntl.registerWith(Handlebars); |
||||
|
||||
$(function() { |
||||
window.state = {}; |
||||
switch (location.hash) { |
||||
case '#blocks': |
||||
window.homeTab = false; |
||||
break; |
||||
default: |
||||
window.homeTab = true; |
||||
} |
||||
var userLang = (navigator.language || navigator.userLanguage) || 'en-US'; |
||||
window.intlData = { locales: userLang }; |
||||
var source = $("#stats-template").html(); |
||||
var template = Handlebars.compile(source); |
||||
refreshStats(template); |
||||
var statsSource = $("#stats-template").html(); |
||||
var statsTemplate = Handlebars.compile(statsSource); |
||||
var blocksSource = $("#blocks-template").html(); |
||||
var blocksTemplate = Handlebars.compile(blocksSource); |
||||
refreshStats(statsTemplate, blocksTemplate); |
||||
|
||||
$('#homeTab').on('click', function() { |
||||
window.homeTab = true; |
||||
refreshStats(statsTemplate, blocksTemplate); |
||||
}); |
||||
$('#blocksTab').on('click', function() { |
||||
window.homeTab = false; |
||||
refreshStats(statsTemplate, blocksTemplate); |
||||
}); |
||||
setInterval(function() { |
||||
refreshStats(template); |
||||
refreshStats(statsTemplate, blocksTemplate); |
||||
}, 5000) |
||||
}); |
||||
|
||||
function refreshStats(template) { |
||||
function refreshStats(statsTemplate, blocksTemplate) { |
||||
$.getJSON("/stats", function(stats) { |
||||
$("#alert").addClass('hide'); |
||||
|
||||
// Sort miners by ID
|
||||
if (stats.miners) { |
||||
stats.miners = stats.miners.sort(compare) |
||||
stats.miners = stats.miners.sort(compareMiners); |
||||
} |
||||
// Reverse sort blocks by height
|
||||
if (stats.blocks) { |
||||
stats.blocks = stats.blocks.sort(compareBlocks); |
||||
} |
||||
|
||||
var html = null; |
||||
$('.nav-pills > li').removeClass('active'); |
||||
|
||||
if (window.homeTab) { |
||||
html = statsTemplate(stats, { data: { intl: window.intlData } }); |
||||
$('.nav-pills > li > #homeTab').parent().addClass('active'); |
||||
} else { |
||||
html = blocksTemplate(stats, { data: { intl: window.intlData } }); |
||||
$('.nav-pills > li > #blocksTab').parent().addClass('active'); |
||||
} |
||||
// Repaint stats
|
||||
var html = template(stats, { data: { intl: window.intlData } }); |
||||
$('#stats').html(html); |
||||
}).fail(function() { |
||||
$("#alert").removeClass('hide'); |
||||
}); |
||||
} |
||||
|
||||
function compare(a, b) { |
||||
function compareMiners(a, b) { |
||||
if (a.name < b.name) |
||||
return -1; |
||||
if (a.name > b.name) |
||||
return 1; |
||||
return 0; |
||||
} |
||||
|
||||
function compareBlocks(a, b) { |
||||
if (a.height > b.height) |
||||
return -1; |
||||
if (a.height < b.height) |
||||
return 1; |
||||
return 0; |
||||
} |
||||
|
Loading…
Reference in new issue