summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/runners_controller.rb4
-rw-r--r--app/finders/admin/runners_finder.rb10
-rw-r--r--app/helpers/sorting_helper.rb11
-rw-r--r--app/views/admin/runners/_sort_dropdown.html.haml11
-rw-r--r--app/views/admin/runners/index.html.haml4
-rw-r--r--locale/gitlab.pot3
-rw-r--r--spec/features/admin/admin_runners_spec.rb30
-rw-r--r--spec/finders/admin/runners_finder_spec.rb12
8 files changed, 75 insertions, 10 deletions
diff --git a/app/controllers/admin/runners_controller.rb b/app/controllers/admin/runners_controller.rb
index f36712c5c41..7b6517722ce 100644
--- a/app/controllers/admin/runners_controller.rb
+++ b/app/controllers/admin/runners_controller.rb
@@ -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
diff --git a/app/finders/admin/runners_finder.rb b/app/finders/admin/runners_finder.rb
index 19e1dc5e477..09329accf41 100644
--- a/app/finders/admin/runners_finder.rb
+++ b/app/finders/admin/runners_finder.rb
@@ -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
diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb
index 36a311dfa8a..2e46d3f93b9 100644
--- a/app/helpers/sorting_helper.rb
+++ b/app/helpers/sorting_helper.rb
@@ -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
diff --git a/app/views/admin/runners/_sort_dropdown.html.haml b/app/views/admin/runners/_sort_dropdown.html.haml
new file mode 100644
index 00000000000..b201e6bf10e
--- /dev/null
+++ b/app/views/admin/runners/_sort_dropdown.html.haml
@@ -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)
+
diff --git a/app/views/admin/runners/index.html.haml b/app/views/admin/runners/index.html.haml
index 0b4253286de..e3d2587b8e5 100644
--- a/app/views/admin/runners/index.html.haml
+++ b/app/views/admin/runners/index.html.haml
@@ -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|
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 73bff79aabe..7afdea46fe3 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -5175,6 +5175,9 @@ msgstr ""
msgid "SortOptions|Largest repository"
msgstr ""
+msgid "SortOptions|Last Contact"
+msgstr ""
+
msgid "SortOptions|Last created"
msgstr ""
diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb
index c4231c1ea42..de530eea10a 100644
--- a/spec/features/admin/admin_runners_spec.rb
+++ b/spec/features/admin/admin_runners_spec.rb
@@ -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
diff --git a/spec/finders/admin/runners_finder_spec.rb b/spec/finders/admin/runners_finder_spec.rb
index 757e4d52e90..30267ace5bc 100644
--- a/spec/finders/admin/runners_finder_spec.rb
+++ b/spec/finders/admin/runners_finder_spec.rb
@@ -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]