2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
class Admin::ProjectsFinder
|
2018-03-17 18:26:18 +05:30
|
|
|
attr_reader :params, :current_user
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
def initialize(params:, current_user:)
|
2018-03-17 18:26:18 +05:30
|
|
|
@params = params
|
2017-09-10 17:25:29 +05:30
|
|
|
@current_user = current_user
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
def execute
|
2018-11-18 11:00:15 +05:30
|
|
|
items = Project.without_deleted.with_statistics.with_route
|
2018-03-17 18:26:18 +05:30
|
|
|
items = by_namespace_id(items)
|
2019-12-26 22:10:19 +05:30
|
|
|
items = by_visibility_level(items)
|
2018-03-17 18:26:18 +05:30
|
|
|
items = by_with_push(items)
|
|
|
|
items = by_abandoned(items)
|
|
|
|
items = by_last_repository_check_failed(items)
|
|
|
|
items = by_archived(items)
|
|
|
|
items = by_personal(items)
|
|
|
|
items = by_name(items)
|
2018-11-18 11:00:15 +05:30
|
|
|
items = items.includes(namespace: [:owner, :route])
|
2018-03-27 19:54:05 +05:30
|
|
|
sort(items).page(params[:page])
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def by_namespace_id(items)
|
|
|
|
params[:namespace_id].present? ? items.in_namespace(params[:namespace_id]) : items
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2019-12-26 22:10:19 +05:30
|
|
|
def by_visibility_level(items)
|
2018-03-17 18:26:18 +05:30
|
|
|
params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def by_with_push(items)
|
|
|
|
params[:with_push].present? ? items.with_push : items
|
|
|
|
end
|
|
|
|
|
|
|
|
def by_abandoned(items)
|
|
|
|
params[:abandoned].present? ? items.abandoned : items
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
def by_last_repository_check_failed(items)
|
|
|
|
params[:last_repository_check_failed].present? ? items.where(last_repository_check_failed: true) : items
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def by_archived(items)
|
|
|
|
if params[:archived] == 'only'
|
|
|
|
items.archived
|
|
|
|
elsif params[:archived].blank?
|
|
|
|
items.non_archived
|
|
|
|
else
|
|
|
|
items
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def by_personal(items)
|
|
|
|
params[:personal].present? ? items.personal(current_user) : items
|
|
|
|
end
|
|
|
|
|
|
|
|
def by_name(items)
|
|
|
|
params[:name].present? ? items.search(params[:name]) : items
|
|
|
|
end
|
|
|
|
|
|
|
|
def sort(items)
|
2022-05-07 20:08:51 +05:30
|
|
|
sort = params.fetch(:sort, 'latest_activity_desc')
|
2018-05-09 12:01:36 +05:30
|
|
|
items.sort_by_attribute(sort)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|