administrator dashboard for observing the Docker container pool
This commit is contained in:
35
app/assets/javascripts/dashboard.js
Normal file
35
app/assets/javascripts/dashboard.js
Normal file
@ -0,0 +1,35 @@
|
||||
$(function() {
|
||||
var 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();
|
||||
setInterval(refreshData, REFRESH_INTERVAL);
|
||||
}
|
||||
});
|
17
app/controllers/admin/dashboard_controller.rb
Normal file
17
app/controllers/admin/dashboard_controller.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module Admin
|
||||
class DashboardController < ApplicationController
|
||||
include DashboardHelper
|
||||
|
||||
def policy_class
|
||||
DashboardPolicy
|
||||
end
|
||||
|
||||
def show
|
||||
authorize(self)
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render(json: dashboard_data) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
app/helpers/admin/dashboard_helper.rb
Normal file
13
app/helpers/admin/dashboard_helper.rb
Normal file
@ -0,0 +1,13 @@
|
||||
module Admin
|
||||
module DashboardHelper
|
||||
def dashboard_data
|
||||
{docker: docker_data}
|
||||
end
|
||||
|
||||
def docker_data
|
||||
ExecutionEnvironment.order(:id).select(:id, :permitted_execution_time, :pool_size).map do |execution_environment|
|
||||
execution_environment.attributes.merge(quantity: DockerContainerPool.quantities[execution_environment.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
4
app/policies/admin/dashboard_policy.rb
Normal file
4
app/policies/admin/dashboard_policy.rb
Normal file
@ -0,0 +1,4 @@
|
||||
module Admin
|
||||
class DashboardPolicy < AdminOnlyPolicy
|
||||
end
|
||||
end
|
20
app/views/admin/dashboard/show.html.slim
Normal file
20
app/views/admin/dashboard/show.html.slim
Normal file
@ -0,0 +1,20 @@
|
||||
h1 = t('breadcrumbs.dashboard.show')
|
||||
|
||||
h2 Docker
|
||||
|
||||
- if DockerContainerPool.config[:active]
|
||||
.table-responsive
|
||||
table.table
|
||||
thead
|
||||
tr
|
||||
th = t('activerecord.models.execution_environment.one')
|
||||
th = t('activerecord.attributes.execution_environment.pool_size')
|
||||
th = t('.quantity')
|
||||
tbody
|
||||
- ExecutionEnvironment.order(:name).each do |execution_environment|
|
||||
tr data-id=execution_environment.id
|
||||
td = link_to(execution_environment, execution_environment)
|
||||
td.pool-size
|
||||
td.quantity = progress_bar(0)
|
||||
- else
|
||||
p = t('.inactive')
|
Reference in New Issue
Block a user