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
|
before_action :runner, except: :index
|
||||||
|
|
||||||
def 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
|
@active_runners_cnt = Ci::Runner.online.count
|
||||||
|
@sort = finder.sort_key
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -14,6 +14,14 @@ class Admin::RunnersFinder < UnionFinder
|
||||||
@runners
|
@runners
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_key
|
||||||
|
if @params[:sort] == 'contacted_asc'
|
||||||
|
'contacted_asc'
|
||||||
|
else
|
||||||
|
'created_date'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def search!
|
def search!
|
||||||
|
@ -33,7 +41,7 @@ class Admin::RunnersFinder < UnionFinder
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort!
|
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)
|
@runners = @runners.order(sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ module SortingHelper
|
||||||
sort_value_recently_updated => sort_title_recently_updated,
|
sort_value_recently_updated => sort_title_recently_updated,
|
||||||
sort_value_popularity => sort_title_popularity,
|
sort_value_popularity => sort_title_popularity,
|
||||||
sort_value_priority => sort_title_priority,
|
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
|
end
|
||||||
|
|
||||||
|
@ -228,6 +229,10 @@ module SortingHelper
|
||||||
s_('SortOptions|Most popular')
|
s_('SortOptions|Most popular')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_title_contacted_date
|
||||||
|
s_('SortOptions|Last Contact')
|
||||||
|
end
|
||||||
|
|
||||||
# Values.
|
# Values.
|
||||||
def sort_value_access_level_asc
|
def sort_value_access_level_asc
|
||||||
'access_level_asc'
|
'access_level_asc'
|
||||||
|
@ -348,4 +353,8 @@ module SortingHelper
|
||||||
def sort_value_upvotes
|
def sort_value_upvotes
|
||||||
'upvotes_desc'
|
'upvotes_desc'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_value_contacted_date
|
||||||
|
'contacted_asc'
|
||||||
|
end
|
||||||
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
|
= status.titleize
|
||||||
= button_tag class: %w[clear-search hidden] do
|
= button_tag class: %w[clear-search hidden] do
|
||||||
= icon('times')
|
= icon('times')
|
||||||
|
.filter-dropdown-container
|
||||||
|
= render 'sort_dropdown'
|
||||||
.clearfix
|
.clearfix
|
||||||
.float-right.light
|
.float-right.light
|
||||||
.prepend-top-10
|
.prepend-top-10
|
||||||
|
@ -103,7 +105,7 @@
|
||||||
%th Projects
|
%th Projects
|
||||||
%th Jobs
|
%th Jobs
|
||||||
%th Tags
|
%th Tags
|
||||||
%th= link_to 'Last contact', admin_runners_path(safe_params.slice(:search).merge(sort: 'contacted_asc'))
|
%th Last contact
|
||||||
%th
|
%th
|
||||||
|
|
||||||
- @runners.each do |runner|
|
- @runners.each do |runner|
|
||||||
|
|
|
@ -5175,6 +5175,9 @@ msgstr ""
|
||||||
msgid "SortOptions|Largest repository"
|
msgid "SortOptions|Largest repository"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "SortOptions|Last Contact"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgid "SortOptions|Last created"
|
msgid "SortOptions|Last created"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
||||||
describe "Admin Runners", :js do
|
describe "Admin Runners", :js do
|
||||||
include StubENV
|
include StubENV
|
||||||
include FilteredSearchHelpers
|
include FilteredSearchHelpers
|
||||||
|
include SortingHelper
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
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-b-1'
|
||||||
expect(page).not_to have_content 'runner-a-2'
|
expect(page).not_to have_content 'runner-a-2'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "when there are no runners" do
|
context "when there are no runners" do
|
||||||
|
|
|
@ -29,10 +29,10 @@ describe Admin::RunnersFinder do
|
||||||
|
|
||||||
context 'sort' do
|
context 'sort' do
|
||||||
context 'without sort param' do
|
context 'without sort param' do
|
||||||
it 'sorts by id' do
|
it 'sorts by created_at' do
|
||||||
runner1 = create :ci_runner
|
runner1 = create :ci_runner, created_at: '2018-07-12 07:00'
|
||||||
runner2 = create :ci_runner
|
runner2 = create :ci_runner, created_at: '2018-07-12 08:00'
|
||||||
runner3 = create :ci_runner
|
runner3 = create :ci_runner, created_at: '2018-07-12 09:00'
|
||||||
|
|
||||||
expect(described_class.new(params: {}).execute).to eq [runner3, runner2, runner1]
|
expect(described_class.new(params: {}).execute).to eq [runner3, runner2, runner1]
|
||||||
end
|
end
|
||||||
|
@ -52,8 +52,8 @@ describe Admin::RunnersFinder do
|
||||||
context 'paginate' do
|
context 'paginate' do
|
||||||
it 'returns the runners for the specified page' do
|
it 'returns the runners for the specified page' do
|
||||||
stub_const('Admin::RunnersFinder::NUMBER_OF_RUNNERS_PER_PAGE', 1)
|
stub_const('Admin::RunnersFinder::NUMBER_OF_RUNNERS_PER_PAGE', 1)
|
||||||
runner1 = create :ci_runner
|
runner1 = create :ci_runner, created_at: '2018-07-12 07:00'
|
||||||
runner2 = create :ci_runner
|
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: 1 }).execute).to eq [runner2]
|
||||||
expect(described_class.new(params: { page: 2 }).execute).to eq [runner1]
|
expect(described_class.new(params: { page: 2 }).execute).to eq [runner1]
|
||||||
|
|
Loading…
Reference in New Issue