Commit dbcee512 authored by Alexis Reigel's avatar Alexis Reigel Committed by Winnie Hellmann

add sort dropdown to admin runners page

(cherry picked from commit fae85677212906bb8dce2bf5dc797a71d1ee9d1b)

Conflicts:
	app/helpers/sorting_helper.rb
parent 37bdfa11
...@@ -2,8 +2,10 @@ class Admin::RunnersController < Admin::ApplicationController ...@@ -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 ...@@ -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 ...@@ -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
......
...@@ -25,7 +25,11 @@ module SortingHelper ...@@ -25,7 +25,11 @@ module SortingHelper
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,
<<<<<<< HEAD
sort_value_weight => sort_title_weight sort_value_weight => sort_title_weight
=======
sort_value_contacted_date => sort_title_contacted_date
>>>>>>> fae85677212... add sort dropdown to admin runners page
} }
end end
...@@ -243,6 +247,10 @@ module SortingHelper ...@@ -243,6 +247,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'
...@@ -372,7 +380,12 @@ module SortingHelper ...@@ -372,7 +380,12 @@ module SortingHelper
'upvotes_desc' 'upvotes_desc'
end end
<<<<<<< HEAD
def sort_value_weight def sort_value_weight
'weight' 'weight'
=======
def sort_value_contacted_date
'contacted_asc'
>>>>>>> fae85677212... add sort dropdown to admin runners page
end end
end end
- 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 @@ ...@@ -82,6 +82,8 @@
= status.titleize = status.titleize
%button.clear-search.hidden{ type: 'button' } %button.clear-search.hidden{ type: 'button' }
= 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 @@ ...@@ -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|
......
...@@ -6591,6 +6591,9 @@ msgstr "" ...@@ -6591,6 +6591,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' ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment