f0e7b5e7a3
In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/19625 some changes were introduced that do not meet our abstraction reuse rules. This commit cleans up some of these changes so the requirements are met. Most notably, sorting of the runners in Admin::RunnersFinder has been delegated to Ci::Runner.order_by, similar to how we order data in models that include the Sortable module. If we need more sort orders in the future we can include Sortable and have Ci::Runner.order_by call `super` to delegate to Sortable.order_by.
52 lines
952 B
Ruby
52 lines
952 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Admin::RunnersFinder < UnionFinder
|
|
NUMBER_OF_RUNNERS_PER_PAGE = 30
|
|
|
|
def initialize(params:)
|
|
@params = params
|
|
end
|
|
|
|
def execute
|
|
search!
|
|
filter_by_status!
|
|
sort!
|
|
paginate!
|
|
|
|
@runners
|
|
end
|
|
|
|
def sort_key
|
|
if @params[:sort] == 'contacted_asc'
|
|
'contacted_asc'
|
|
else
|
|
'created_date'
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def search!
|
|
@runners =
|
|
if @params[:search].present?
|
|
Ci::Runner.search(@params[:search])
|
|
else
|
|
Ci::Runner.all
|
|
end
|
|
end
|
|
|
|
def filter_by_status!
|
|
status = @params[:status_status]
|
|
if status.present? && Ci::Runner::AVAILABLE_STATUSES.include?(status)
|
|
@runners = @runners.public_send(status) # rubocop:disable GitlabSecurity/PublicSend
|
|
end
|
|
end
|
|
|
|
def sort!
|
|
@runners = @runners.order_by(sort_key)
|
|
end
|
|
|
|
def paginate!
|
|
@runners = @runners.page(@params[:page]).per(NUMBER_OF_RUNNERS_PER_PAGE)
|
|
end
|
|
end
|