add sort dropdown to admin runners page
This commit is contained in:
parent
89b30999c2
commit
34bdb74740
|
@ -2,8 +2,10 @@ class Admin::RunnersController < Admin::ApplicationController
|
|||
before_action :runner, except: :index
|
||||
|
||||
def index
|
||||
@runners = Admin::RunnersFinder.new(params: params).execute
|
||||
finder = Admin::RunnersFinder.new(params: params)
|
||||
@runners = finder.execute
|
||||
@active_runners_cnt = Ci::Runner.online.count
|
||||
@sort = finder.sort_key
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -14,6 +14,14 @@ class Admin::RunnersFinder < UnionFinder
|
|||
@runners
|
||||
end
|
||||
|
||||
def sort_key
|
||||
if @params[:sort] == 'contacted_asc'
|
||||
'contacted_asc'
|
||||
else
|
||||
'created_date'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def search!
|
||||
|
@ -33,7 +41,7 @@ class Admin::RunnersFinder < UnionFinder
|
|||
end
|
||||
|
||||
def sort!
|
||||
sort = @params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc }
|
||||
sort = sort_key == 'contacted_asc' ? { contacted_at: :asc } : { created_at: :desc }
|
||||
@runners = @runners.order(sort)
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ module SortingHelper
|
|||
sort_value_recently_updated => sort_title_recently_updated,
|
||||
sort_value_popularity => sort_title_popularity,
|
||||
sort_value_priority => sort_title_priority,
|
||||
sort_value_upvotes => sort_title_upvotes
|
||||
sort_value_upvotes => sort_title_upvotes,
|
||||
sort_value_contacted_date => sort_title_contacted_date
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -228,6 +229,10 @@ module SortingHelper
|
|||
s_('SortOptions|Most popular')
|
||||
end
|
||||
|
||||
def sort_title_contacted_date
|
||||
s_('SortOptions|Last Contact')
|
||||
end
|
||||
|
||||
# Values.
|
||||
def sort_value_access_level_asc
|
||||
'access_level_asc'
|
||||
|
@ -348,4 +353,8 @@ module SortingHelper
|
|||
def sort_value_upvotes
|
||||
'upvotes_desc'
|
||||
end
|
||||
|
||||
def sort_value_contacted_date
|
||||
'contacted_asc'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
- sorted_by = sort_options_hash[@sort]
|
||||
|
||||
.dropdown.inline.prepend-left-10
|
||||
%button.dropdown-toggle{ type: 'button', data: { toggle: 'dropdown', display: 'static' } }
|
||||
= sorted_by
|
||||
= icon('chevron-down')
|
||||
%ul.dropdown-menu.dropdown-menu-right.dropdown-menu-selectable.dropdown-menu-sort
|
||||
%li
|
||||
= sortable_item(sort_title_created_date, page_filter_path(sort: sort_value_created_date, label: true), sorted_by)
|
||||
= sortable_item(sort_title_contacted_date, page_filter_path(sort: sort_value_contacted_date, label: true), sorted_by)
|
||||
|
|
@ -82,6 +82,8 @@
|
|||
= status.titleize
|
||||
= button_tag class: %w[clear-search hidden] do
|
||||
= icon('times')
|
||||
.filter-dropdown-container
|
||||
= render 'sort_dropdown'
|
||||
.clearfix
|
||||
.float-right.light
|
||||
.prepend-top-10
|
||||
|
@ -103,7 +105,7 @@
|
|||
%th Projects
|
||||
%th Jobs
|
||||
%th Tags
|
||||
%th= link_to 'Last contact', admin_runners_path(safe_params.slice(:search).merge(sort: 'contacted_asc'))
|
||||
%th Last contact
|
||||
%th
|
||||
|
||||
- @runners.each do |runner|
|
||||
|
|
|
@ -5175,6 +5175,9 @@ msgstr ""
|
|||
msgid "SortOptions|Largest repository"
|
||||
msgstr ""
|
||||
|
||||
msgid "SortOptions|Last Contact"
|
||||
msgstr ""
|
||||
|
||||
msgid "SortOptions|Last created"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
|||
describe "Admin Runners", :js do
|
||||
include StubENV
|
||||
include FilteredSearchHelpers
|
||||
include SortingHelper
|
||||
|
||||
before do
|
||||
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
||||
|
@ -91,6 +92,35 @@ describe "Admin Runners", :js do
|
|||
expect(page).not_to have_content 'runner-b-1'
|
||||
expect(page).not_to have_content 'runner-a-2'
|
||||
end
|
||||
|
||||
it 'sorts by last contact date' do
|
||||
FactoryBot.create :ci_runner, description: 'runner-1', created_at: '2018-07-12 15:37', contacted_at: '2018-07-12 15:37'
|
||||
FactoryBot.create :ci_runner, description: 'runner-2', created_at: '2018-07-12 16:37', contacted_at: '2018-07-12 16:37'
|
||||
|
||||
visit admin_runners_path
|
||||
|
||||
within '.runners-content tbody' do
|
||||
within('tr:nth-child(1)') do
|
||||
expect(page).to have_content 'runner-2'
|
||||
end
|
||||
|
||||
within('tr:nth-child(2)') do
|
||||
expect(page).to have_content 'runner-1'
|
||||
end
|
||||
end
|
||||
|
||||
sorting_by 'Last Contact'
|
||||
|
||||
within '.runners-content tbody' do
|
||||
within('tr:nth-child(1)') do
|
||||
expect(page).to have_content 'runner-1'
|
||||
end
|
||||
|
||||
within('tr:nth-child(2)') do
|
||||
expect(page).to have_content 'runner-2'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are no runners" do
|
||||
|
|
|
@ -29,10 +29,10 @@ describe Admin::RunnersFinder do
|
|||
|
||||
context 'sort' do
|
||||
context 'without sort param' do
|
||||
it 'sorts by id' do
|
||||
runner1 = create :ci_runner
|
||||
runner2 = create :ci_runner
|
||||
runner3 = create :ci_runner
|
||||
it 'sorts by created_at' do
|
||||
runner1 = create :ci_runner, created_at: '2018-07-12 07:00'
|
||||
runner2 = create :ci_runner, created_at: '2018-07-12 08:00'
|
||||
runner3 = create :ci_runner, created_at: '2018-07-12 09:00'
|
||||
|
||||
expect(described_class.new(params: {}).execute).to eq [runner3, runner2, runner1]
|
||||
end
|
||||
|
@ -52,8 +52,8 @@ describe Admin::RunnersFinder do
|
|||
context 'paginate' do
|
||||
it 'returns the runners for the specified page' do
|
||||
stub_const('Admin::RunnersFinder::NUMBER_OF_RUNNERS_PER_PAGE', 1)
|
||||
runner1 = create :ci_runner
|
||||
runner2 = create :ci_runner
|
||||
runner1 = create :ci_runner, created_at: '2018-07-12 07:00'
|
||||
runner2 = create :ci_runner, created_at: '2018-07-12 08:00'
|
||||
|
||||
expect(described_class.new(params: { page: 1 }).execute).to eq [runner2]
|
||||
expect(described_class.new(params: { page: 2 }).execute).to eq [runner1]
|
||||
|
|
Loading…
Reference in New Issue