37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
$(function() {
|
|
var DEFAULT_REFRESH_INTERVAL = 5000;
|
|
|
|
var refreshData = function() {
|
|
var jqxhr = $.ajax({
|
|
dataType: 'json',
|
|
method: 'GET'
|
|
});
|
|
jqxhr.done(updateView);
|
|
};
|
|
|
|
var updateProgressBar = function(progress_bar, data) {
|
|
var percentage = Math.round(data.quantity / data.pool_size * 100);
|
|
progress_bar.attr({
|
|
'aria-valuemax': data.pool_size,
|
|
'aria-valuenow': data.quantity,
|
|
style: 'width: ' + percentage + '%'
|
|
});
|
|
progress_bar.html(data.quantity);
|
|
};
|
|
|
|
var updateView = function(response) {
|
|
_.each(response.docker, function(data) {
|
|
var row = $('tbody tr[data-id=' + data.id + ']');
|
|
$('.pool-size', row).html(data.pool_size);
|
|
var progress_bar = $('.quantity .progress .progress-bar', row);
|
|
updateProgressBar(progress_bar, data);
|
|
});
|
|
};
|
|
|
|
if ($.isController('dashboard')) {
|
|
refreshData();
|
|
var refresh_interval = location.search.match(/interval=(\d+)/) ? parseInt(RegExp.$1) : DEFAULT_REFRESH_INTERVAL;
|
|
setInterval(refreshData, refresh_interval);
|
|
}
|
|
});
|