2018-08-21 02:35:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-08 10:47:46 -04:00
|
|
|
class Admin::RunnersFinder < UnionFinder
|
|
|
|
NUMBER_OF_RUNNERS_PER_PAGE = 30
|
|
|
|
|
|
|
|
def initialize(params:)
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
search!
|
|
|
|
filter_by_status!
|
2018-06-11 10:25:53 -04:00
|
|
|
filter_by_runner_type!
|
2018-06-13 05:18:47 -04:00
|
|
|
filter_by_tag_list!
|
2018-06-08 10:47:46 -04:00
|
|
|
sort!
|
|
|
|
paginate!
|
|
|
|
|
2019-02-26 14:30:43 -05:00
|
|
|
@runners.with_tags
|
2018-06-08 10:47:46 -04:00
|
|
|
end
|
|
|
|
|
2018-07-12 12:15:03 -04:00
|
|
|
def sort_key
|
|
|
|
if @params[:sort] == 'contacted_asc'
|
|
|
|
'contacted_asc'
|
|
|
|
else
|
|
|
|
'created_date'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-08 10:47:46 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def search!
|
|
|
|
@runners =
|
|
|
|
if @params[:search].present?
|
|
|
|
Ci::Runner.search(@params[:search])
|
|
|
|
else
|
|
|
|
Ci::Runner.all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_by_status!
|
2018-06-11 10:25:53 -04:00
|
|
|
filter_by!(:status_status, Ci::Runner::AVAILABLE_STATUSES)
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_by_runner_type!
|
|
|
|
filter_by!(:type_type, Ci::Runner::AVAILABLE_TYPES)
|
2018-06-08 10:47:46 -04:00
|
|
|
end
|
|
|
|
|
2018-06-13 05:18:47 -04:00
|
|
|
def filter_by_tag_list!
|
|
|
|
tag_list = @params[:tag_name].presence
|
|
|
|
|
|
|
|
if tag_list
|
|
|
|
@runners = @runners.tagged_with(tag_list)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-08 10:47:46 -04:00
|
|
|
def sort!
|
2018-09-14 09:05:46 -04:00
|
|
|
@runners = @runners.order_by(sort_key)
|
2018-06-08 10:47:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def paginate!
|
|
|
|
@runners = @runners.page(@params[:page]).per(NUMBER_OF_RUNNERS_PER_PAGE)
|
|
|
|
end
|
2018-06-11 10:25:53 -04:00
|
|
|
|
|
|
|
def filter_by!(scope_name, available_scopes)
|
|
|
|
scope = @params[scope_name]
|
|
|
|
|
|
|
|
if scope.present? && available_scopes.include?(scope)
|
|
|
|
@runners = @runners.public_send(scope) # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
end
|
|
|
|
end
|
2018-06-08 10:47:46 -04:00
|
|
|
end
|