administrator dashboard for observing the Docker container pool

This commit is contained in:
Hauke Klement
2015-02-10 12:23:26 +01:00
parent 7ab57403df
commit 59ca0a57c3
10 changed files with 147 additions and 0 deletions

View 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);
}
});

View 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

View 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

View File

@ -0,0 +1,4 @@
module Admin
class DashboardPolicy < AdminOnlyPolicy
end
end

View 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')

View File

@ -123,11 +123,18 @@ de:
models:
exercise:
at_most_one_main_file: dürfen höchstens eine Hauptdatei enthalten
admin:
dashboard:
show:
inactive: Der Container-Pool ist nicht aktiv.
quantity: Verfügbare Container
application:
not_authorized: Sie Sind nicht berechtigt, diese Aktion auszuführen.
breadcrumbs:
application:
welcome: Startseite
dashboard:
show: Dashboard
sessions:
destroy_through_lti: Code-Abgabe
consumers:

View File

@ -123,11 +123,18 @@ en:
models:
exercise:
at_most_one_main_file: must include at most one main file
admin:
dashboard:
show:
inactive: Container pooling is not enabled.
quantity: Available Containers
application:
not_authorized: You are not authorized to perform this action.
breadcrumbs:
application:
welcome: Cover Page
dashboard:
show: Dashboard
sessions:
destroy_through_lti: Code Submission
consumers:

View File

@ -3,6 +3,10 @@ FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
Rails.application.routes.draw do
root to: 'application#welcome'
namespace :admin do
get 'dashboard', to: 'dashboard#show'
end
get '/help', to: 'application#help'
resources :consumers

View File

@ -0,0 +1,21 @@
require 'rails_helper'
describe Admin::DashboardController do
before(:each) { allow(controller).to receive(:current_user).and_return(FactoryGirl.build(:admin)) }
describe 'GET #show' do
describe 'with format HTML' do
before(:each) { get :show }
expect_status(200)
expect_template(:show)
end
describe 'with format JSON' do
before(:each) { get :show, format: :json }
expect_json
expect_status(200)
end
end
end

View File

@ -0,0 +1,19 @@
require 'rails_helper'
describe Admin::DashboardPolicy do
subject { Admin::DashboardPolicy }
permissions :show? do
it 'grants access to admins' do
expect(subject).to permit(FactoryGirl.build(:admin), :dashboard)
end
it 'does not grant access to teachers' do
expect(subject).not_to permit(FactoryGirl.build(:teacher), :dashboard)
end
it 'does not grant access to external users' do
expect(subject).not_to permit(FactoryGirl.build(:external_user), :dashboard)
end
end
end