2020-12-01 10:09:28 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SearchServicePresenter < Gitlab::View::Presenter::Delegated
|
|
|
|
include RendersCommits
|
|
|
|
|
2021-09-21 05:12:21 -04:00
|
|
|
presents ::SearchService, as: :search_service
|
2020-12-01 10:09:28 -05:00
|
|
|
|
|
|
|
SCOPE_PRELOAD_METHOD = {
|
|
|
|
projects: :with_web_entity_associations,
|
|
|
|
issues: :with_web_entity_associations,
|
|
|
|
merge_requests: :with_web_entity_associations,
|
2021-03-29 11:09:30 -04:00
|
|
|
epics: :with_web_entity_associations,
|
2021-03-31 02:08:58 -04:00
|
|
|
notes: :with_web_entity_associations,
|
2021-04-01 14:13:56 -04:00
|
|
|
milestones: :with_web_entity_associations,
|
|
|
|
commits: :with_web_entity_associations,
|
|
|
|
blobs: :with_web_entity_associations
|
2020-12-01 10:09:28 -05:00
|
|
|
}.freeze
|
|
|
|
|
2021-06-22 15:11:50 -04:00
|
|
|
SORT_ENABLED_SCOPES = %w(issues merge_requests epics).freeze
|
2020-12-01 10:09:28 -05:00
|
|
|
|
2021-09-21 05:12:21 -04:00
|
|
|
delegator_override :search_objects
|
2020-12-01 10:09:28 -05:00
|
|
|
def search_objects
|
|
|
|
@search_objects ||= begin
|
|
|
|
objects = search_service.search_objects(SCOPE_PRELOAD_METHOD[scope.to_sym])
|
|
|
|
|
|
|
|
case scope
|
|
|
|
when 'users'
|
2022-03-11 13:08:37 -05:00
|
|
|
objects.eager_load(:status) if objects.respond_to?(:eager_load) # rubocop:disable CodeReuse/ActiveRecord
|
2020-12-01 10:09:28 -05:00
|
|
|
when 'commits'
|
|
|
|
prepare_commits_for_rendering(objects)
|
|
|
|
else
|
|
|
|
objects
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_sort_dropdown?
|
|
|
|
SORT_ENABLED_SCOPES.include?(scope)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_results_status?
|
|
|
|
!without_count? || show_snippets? || show_sort_dropdown?
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_count?
|
|
|
|
search_objects.is_a?(Kaminari::PaginatableWithoutCount)
|
|
|
|
end
|
|
|
|
end
|