Skip to content

Commit

Permalink
Merge pull request #227 from bmarkons/admin-ui
Browse files Browse the repository at this point in the history
Add admin UI
  • Loading branch information
tgxworld committed Jul 11, 2017
2 parents 85605f6 + 7562941 commit 6ae5be8
Show file tree
Hide file tree
Showing 23 changed files with 160 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bundler_args: --without development:production --deployment --retry=3 --jobs=3
before_script:
- bundle exec rake db:create
- bundle exec rake db:migrate
- bundle exec rake assets:precompile &> /dev/null
before_install:
- "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
- if [ $(phantomjs --version) != '2.1.1' ]; then
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gem 'responders'
gem 'jbuilder'
gem 'msgpack'
gem 'octokit'
gem 'bootstrap_sb_admin_base_v2'

group :development do
gem 'spring'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ GEM
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
bootstrap_sb_admin_base_v2 (0.3.6)
font-awesome-rails
jquery-rails
bugsnag (5.0.1)
builder (3.2.2)
bullet (5.4.2)
Expand Down Expand Up @@ -113,6 +116,8 @@ GEM
faraday (0.12.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.14)
font-awesome-rails (4.7.0.2)
railties (>= 3.2, < 5.2)
globalid (0.3.7)
activesupport (>= 4.1.0)
haml (4.0.7)
Expand Down Expand Up @@ -328,6 +333,7 @@ DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass
bootstrap_sb_admin_base_v2
bugsnag
bullet
byebug
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap_sb_admin_base_v2
//= require_tree ./admin
Empty file.
7 changes: 7 additions & 0 deletions app/assets/javascripts/admin/manual_run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$(document).on('turbolinks:load', function() {
$('#manual_run_form').submit(function(event) {
$('#notice').remove();
$('#wait_alert').removeClass('hidden');
});
});

7 changes: 3 additions & 4 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//= require bootstrap/transition.js
//= require bootstrap/modal.js
//= require bootstrap/collapse.js
//= require modules/release_chart
//= require modules/chart
//= require modules/sparkline
//= require_tree .
//= require_tree ./lib
//= require_tree ./modules
//= require_tree ./application
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/admin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import "bootstrap-sprockets";
@import "bootstrap";
@import "font-awesome";
@import "bootstrap_sb_admin_base_v2";
28 changes: 27 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,36 @@ class AdminController < ApplicationController
http_basic_authenticate_with(
name: 'admin',
password: Rails.application.secrets.admin_password
)
) unless Rails.env.test?

layout 'admin'

before_action :set_repos
before_action :set_repo, only: [:repo, :run]

def toggle_admin
session['admin'] = !session['admin']
redirect_to root_path
end

def home
end

def repo
end

def run
ManualRunner.new(@repo).run_last(params[:count].to_i)
redirect_to admin_repo_path(@repo.name), notice: "#{@repo.name.capitalize} suite is running for last #{params[:count].to_i} commits."
end

private

def set_repos
@repos = Repo.all
end

def set_repo
@repo = Repo.find_by(name: params[:repo_name])
end
end
2 changes: 2 additions & 0 deletions app/services/manual_runner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ManualRunner
OPTIONS = ['20', '100', '200', '500', '750', '2000']

def initialize(repo)
raise "Repo doesn't exist" unless Repo.exists?(repo.id)
@repo = repo
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/home.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- content_for(:page_header) do
= t('admin.dashboard')
19 changes: 19 additions & 0 deletions app/views/admin/repo.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- content_for(:page_header) do
= @repo.name.capitalize

.row
.col-lg-6
- if notice.present?
#notice.alert.alert-success
= notice

#wait_alert.alert.alert-warning.hidden
= t('admin.wait_manual_run')

.panel.panel-warning
.panel-body
= form_tag(admin_repo_run_path(@repo.name), id: 'manual_run_form') do
.form-group
= label_tag(t('admin.manual_run_label'))
= select_tag(:count, options_for_select(ManualRunner::OPTIONS, ManualRunner::OPTIONS.last), class: 'form-control')
= button_tag(t('admin.manual_run_button'), class: 'btn btn-default')
18 changes: 18 additions & 0 deletions app/views/layouts/admin.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%HTML{ lang: 'en' }
%head
%title RubyBench Admin

= stylesheet_link_tag 'admin', 'data-turbolinks-track' => 'reload'
= javascript_include_tag 'admin', 'data-turbolinks-track' => 'reload'
= csrf_meta_tags

%body
#wrapper
= render 'layouts/admin/navbar'

#page-wrapper
.row
.col-lg-12
%h1.page-header
= yield(:page_header)
= yield
28 changes: 28 additions & 0 deletions app/views/layouts/admin/_navbar.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
%nav.navbar.navbar-default.navbar-static-top{:role => "navigation", :style => "margin-bottom: 0"}
.navbar-header
%button.navbar-toggle{"data-target" => ".navbar-collapse", "data-toggle" => "collapse", :type => "button"}
%span.sr-only Toggle navigation
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.navbar-brand RubyBench Admin

%ul.nav.navbar-top-links.navbar-right.pull-right
%li.dropdown
= link_to root_path do
%i.fa.fa-sign-out

.navbar-default.sidebar{:role => "navigation"}
.sidebar-nav.navbar-collapse
%ul#side-menu.nav.in
%li
= link_to admin_path do
%i.fa.fa-dashboard.fa-fw
= t('admin.dashboard')
- @repos.each do |repo|
%li
= link_to admin_repo_path(repo.name) do
%i.fa.fa-suitcase.fa-fw
= repo.name.capitalize


6 changes: 3 additions & 3 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
= render 'layouts/typekit' if !Rails.env.test?

= stylesheet_link_tag 'https://fonts.googleapis.com/css?family=Montserrat:400,700',
"data-turbolinks-track" => true
'data-turbolinks-track' => 'reload'

= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => 'reload'

= render 'layouts/ga' if Rails.env.production?
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => 'reload'
= csrf_meta_tags

%body
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
Rails.application.config.assets.precompile += %w( admin.js admin.scss )
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ en:
desktop: 'Click and drag in the plot area to zoom in'
mobile: 'Pinch the chart to zoom in'
commit_url: Click on a point to view and compare commits on GitHub

admin:
wait_manual_run: 'Wait while selected runs are being queued...'
manual_run_label: 'Run last:'
manual_run_button: 'Run'
dashboard: 'Dashboard'
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
get 'hardware' => 'static_pages#hardware'
get 'contributing' => 'static_pages#contribute', as: :contribute
get 'sponsors' => 'static_pages#sponsors', as: :sponsors
get 'admin' => 'admin#toggle_admin'
get 'benchmarks' => 'organizations#index'
get ':organization_name/:repo_name/commits/overview' => 'repos#index', as: :overview
get ':organization_name/:repo_name/commits' => 'repos#commits', as: :commits
get ':organization_name/:repo_name/releases' => 'repos#releases', as: :releases

get 'admin' => 'admin#home'
get 'admin/repos/:repo_name' => 'admin#repo', as: :admin_repo
get 'admin/toggle' => 'admin#toggle_admin'
post 'admin/repos/:repo_name/run' => 'admin#run', as: :admin_repo_run
end
11 changes: 11 additions & 0 deletions test/acceptance/admin_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'acceptance/test_helper'

class AdminTest < AcceptanceTest
test 'Admin should be able to manually run suite for existing repo' do
repo = create(:repo)

visit admin_repo_path(repo.name)
page.has_css?('label', text: I18n.t('admin.manual_run_label'))
page.has_css?('button', text: I18n.t('admin.manual_run_button'))
end
end
11 changes: 11 additions & 0 deletions test/integration/manual_run_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test_helper'

class ManualRunTest < ActionDispatch::IntegrationTest
def test_running_commits_manually
@repo = create(:repo)

ManualRunner.any_instance.expects(:run_last).with(100)

post(admin_repo_run_path(@repo.name), params: { count: 100 })
end
end

0 comments on commit 6ae5be8

Please sign in to comment.