From 3d02472ecd17599b614dabc2df2cb7c3ea13026f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 2 Apr 2015 16:43:42 -0700 Subject: Search runners by token or description on admin/runners page --- CHANGELOG | 1 + app/controllers/admin/runners_controller.rb | 4 +++- app/models/runner.rb | 5 +++++ app/views/admin/runners/index.html.haml | 6 +++++- spec/features/admin/runners_spec.rb | 13 +++++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e3d6c28..f99b6d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ v7.10.0 - Fix GitLab and CI projects collision - Events for admin - Events per projects + - Search for runners in admin area v7.9.2 - [Security] Already existing projects should not be served by shared runners diff --git a/app/controllers/admin/runners_controller.rb b/app/controllers/admin/runners_controller.rb index 41ee5b8..fd1b6b2 100644 --- a/app/controllers/admin/runners_controller.rb +++ b/app/controllers/admin/runners_controller.rb @@ -2,7 +2,9 @@ class Admin::RunnersController < Admin::ApplicationController before_filter :runner, except: :index def index - @runners = Runner.page(params[:page]).per(30) + @runners = Runner.all + @runners = @runners.search(params[:search]) if params[:search].present? + @runners = @runners.page(params[:page]).per(30) end def show diff --git a/app/models/runner.rb b/app/models/runner.rb index ed70097..bfd5a54 100644 --- a/app/models/runner.rb +++ b/app/models/runner.rb @@ -28,6 +28,11 @@ class Runner < ActiveRecord::Base acts_as_taggable + def self.search(query) + where('LOWER(runners.token) LIKE :query OR LOWER(runners.description) like :query', + query: "%#{query.try(:downcase)}%") + end + def set_default_values self.token = SecureRandom.hex(15) if self.token.blank? end diff --git a/app/views/admin/runners/index.html.haml b/app/views/admin/runners/index.html.haml index abbcf8f..869561f 100644 --- a/app/views/admin/runners/index.html.haml +++ b/app/views/admin/runners/index.html.haml @@ -31,7 +31,11 @@ %span.label.label-danger paused \- runner will not receive any new build - +.append-bottom-20 + = form_tag admin_runners_path, class: 'form-inline', method: :get do + .form-group + = search_field_tag :search, params[:search], class: 'form-control', placeholder: 'Runner description or token' + = submit_tag 'Search', class: 'btn' %table.table %thead diff --git a/spec/features/admin/runners_spec.rb b/spec/features/admin/runners_spec.rb index 5fe1130..a966aee 100644 --- a/spec/features/admin/runners_spec.rb +++ b/spec/features/admin/runners_spec.rb @@ -16,6 +16,19 @@ describe "Admin Runners" do it { page.has_text? "Manage Runners" } it { page.has_text? "To register a new runner" } + + describe 'search' do + before do + FactoryGirl.create :runner, description: 'foo' + FactoryGirl.create :runner, description: 'bar' + + fill_in 'search', with: 'foo' + click_button 'Search' + end + + it { page.should have_content("foo") } + it { page.should_not have_content("bar") } + end end describe "GET /admin/runners/:id" do -- cgit v1.2.1