add status filter to admin runners page
This commit is contained in:
parent
bbc305b1a2
commit
16d12491c5
4 changed files with 112 additions and 16 deletions
|
@ -5,6 +5,7 @@ class Admin::RunnersController < Admin::ApplicationController
|
|||
sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc }
|
||||
@runners = Ci::Runner.order(sort)
|
||||
@runners = @runners.search(params[:search]) if params[:search].present?
|
||||
@runners = @runners.public_send(params[:status]) if params[:status].present? && Ci::Runner::AVAILABLE_STATUSES.include?(params[:status])
|
||||
@runners = @runners.page(params[:page]).per(30)
|
||||
@active_runners_cnt = Ci::Runner.online.count
|
||||
end
|
||||
|
|
13
app/views/admin/runners/_statuses.html.haml
Normal file
13
app/views/admin/runners/_statuses.html.haml
Normal file
|
@ -0,0 +1,13 @@
|
|||
- active_status = params[:status].presence
|
||||
|
||||
- toggle_text = 'Status'
|
||||
- if active_status
|
||||
= hidden_field_tag :status, params[:status]
|
||||
- toggle_text = params[:status].titleize
|
||||
|
||||
= dropdown_tag(toggle_text, options: { wrapper_class: 'dropdown-menu-selectable', title: 'Statuses' }) do
|
||||
%ul
|
||||
%li= link_to 'Any Status', admin_runners_path(safe_params.slice(:search)), class: ('is-active' unless active_status)
|
||||
%li.divider
|
||||
- Ci::Runner::AVAILABLE_STATUSES.each do |status|
|
||||
%li= link_to status.titleize, admin_runners_path(safe_params.slice(:search).merge(status: status)), class: ('is-active' if active_status == status)
|
|
@ -42,14 +42,18 @@
|
|||
locals: { registration_token: Gitlab::CurrentSettings.runners_registration_token }
|
||||
|
||||
.append-bottom-20.clearfix
|
||||
.float-left
|
||||
= form_tag admin_runners_path, id: 'runners-search', class: 'form-inline', method: :get do
|
||||
.form-group
|
||||
= search_field_tag :search, params[:search], class: 'form-control input-short', placeholder: 'Runner description or token', spellcheck: false
|
||||
= submit_tag 'Search', class: 'btn'
|
||||
= form_tag admin_runners_path, id: 'runners-search', method: :get do
|
||||
.float-left
|
||||
.form-inline
|
||||
.form-group
|
||||
= search_field_tag :search, params[:search], class: 'form-control input-short', placeholder: 'Runner description or token', spellcheck: false
|
||||
= submit_tag 'Search', class: 'btn'
|
||||
|
||||
.float-right.light
|
||||
Runners currently online: #{@active_runners_cnt}
|
||||
.float-left.prepend-left-10
|
||||
= render 'statuses'
|
||||
|
||||
.float-right.light
|
||||
Runners currently online: #{@active_runners_cnt}
|
||||
|
||||
%br
|
||||
|
||||
|
|
|
@ -12,13 +12,11 @@ describe "Admin Runners" do
|
|||
let(:pipeline) { create(:ci_pipeline) }
|
||||
|
||||
context "when there are runners" do
|
||||
before do
|
||||
it 'has all necessary texts' do
|
||||
runner = FactoryBot.create(:ci_runner, contacted_at: Time.now)
|
||||
FactoryBot.create(:ci_build, pipeline: pipeline, runner_id: runner.id)
|
||||
visit admin_runners_path
|
||||
end
|
||||
|
||||
it 'has all necessary texts' do
|
||||
expect(page).to have_text "Setup a shared Runner manually"
|
||||
expect(page).to have_text "Runners currently online: 1"
|
||||
end
|
||||
|
@ -27,25 +25,105 @@ describe "Admin Runners" do
|
|||
before do
|
||||
FactoryBot.create :ci_runner, description: 'runner-foo'
|
||||
FactoryBot.create :ci_runner, description: 'runner-bar'
|
||||
|
||||
visit admin_runners_path
|
||||
end
|
||||
|
||||
it 'shows correct runner when description matches' do
|
||||
search_form = find('#runners-search')
|
||||
search_form.fill_in 'search', with: 'runner-foo'
|
||||
search_form.click_button 'Search'
|
||||
within '#runners-search' do
|
||||
fill_in 'search', with: 'runner-foo'
|
||||
click_button 'Search'
|
||||
end
|
||||
|
||||
expect(page).to have_content("runner-foo")
|
||||
expect(page).not_to have_content("runner-bar")
|
||||
end
|
||||
|
||||
it 'shows no runner when description does not match' do
|
||||
search_form = find('#runners-search')
|
||||
search_form.fill_in 'search', with: 'runner-baz'
|
||||
search_form.click_button 'Search'
|
||||
within '#runners-search' do
|
||||
fill_in 'search', with: 'runner-baz'
|
||||
click_button 'Search'
|
||||
end
|
||||
|
||||
expect(page).to have_text 'No runners found'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'filter by status', :js do
|
||||
it 'shows correct runner when status matches' do
|
||||
FactoryBot.create :ci_runner, description: 'runner-active', active: true
|
||||
FactoryBot.create :ci_runner, description: 'runner-paused', active: false
|
||||
|
||||
visit admin_runners_path
|
||||
|
||||
expect(page).to have_content 'runner-active'
|
||||
expect(page).to have_content 'runner-paused'
|
||||
|
||||
click_button 'Status'
|
||||
click_link 'Active'
|
||||
expect(page).to have_content 'runner-active'
|
||||
expect(page).not_to have_content 'runner-paused'
|
||||
end
|
||||
|
||||
it 'shows no runner when status does not match' do
|
||||
FactoryBot.create :ci_runner, :online, description: 'runner-active', active: true
|
||||
FactoryBot.create :ci_runner, :online, description: 'runner-paused', active: false
|
||||
|
||||
visit admin_runners_path
|
||||
|
||||
click_button 'Status'
|
||||
click_link 'Offline'
|
||||
|
||||
expect(page).not_to have_content 'runner-active'
|
||||
expect(page).not_to have_content 'runner-paused'
|
||||
|
||||
expect(page).to have_text 'No runners found'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'filter by status and enter search term', :js do
|
||||
before do
|
||||
FactoryBot.create :ci_runner, description: 'runner-a-1', active: true
|
||||
FactoryBot.create :ci_runner, description: 'runner-a-2', active: false
|
||||
FactoryBot.create :ci_runner, description: 'runner-b-1', active: true
|
||||
|
||||
visit admin_runners_path
|
||||
end
|
||||
|
||||
it 'shows correct runner when status is selected first and then search term is entered' do
|
||||
click_button 'Status'
|
||||
click_link 'Active'
|
||||
expect(page).to have_content 'runner-a-1'
|
||||
expect(page).to have_content 'runner-b-1'
|
||||
expect(page).not_to have_content 'runner-a-2'
|
||||
|
||||
within '#runners-search' do
|
||||
fill_in 'search', with: 'runner-a'
|
||||
click_button 'Search'
|
||||
end
|
||||
|
||||
expect(page).to have_content 'runner-a-1'
|
||||
expect(page).not_to have_content 'runner-b-1'
|
||||
expect(page).not_to have_content 'runner-a-2'
|
||||
end
|
||||
|
||||
it 'shows correct runner when search term is entered first and then status is selected' do
|
||||
within '#runners-search' do
|
||||
fill_in 'search', with: 'runner-a'
|
||||
click_button 'Search'
|
||||
end
|
||||
|
||||
expect(page).to have_content 'runner-a-1'
|
||||
expect(page).to have_content 'runner-a-2'
|
||||
expect(page).not_to have_content 'runner-b-1'
|
||||
|
||||
click_button 'Status'
|
||||
click_link 'Active'
|
||||
expect(page).to have_content 'runner-a-1'
|
||||
expect(page).not_to have_content 'runner-b-1'
|
||||
expect(page).not_to have_content 'runner-a-2'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are no runners" do
|
||||
|
|
Loading…
Reference in a new issue