debian-mirror-gitlab/app/presenters/search_service_presenter.rb

58 lines
1.5 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
class SearchServicePresenter < Gitlab::View::Presenter::Delegated
include RendersCommits
2023-06-20 00:43:36 +05:30
include RendersProjectsList
2021-02-22 17:27:13 +05:30
2021-11-18 22:05:49 +05:30
presents ::SearchService, as: :search_service
2021-02-22 17:27:13 +05:30
SCOPE_PRELOAD_METHOD = {
projects: :with_web_entity_associations,
issues: :with_web_entity_associations,
merge_requests: :with_web_entity_associations,
2021-04-29 21:17:54 +05:30
epics: :with_web_entity_associations,
notes: :with_web_entity_associations,
milestones: :with_web_entity_associations,
commits: :with_web_entity_associations,
blobs: :with_web_entity_associations
2021-02-22 17:27:13 +05:30
}.freeze
2021-09-30 23:02:18 +05:30
SORT_ENABLED_SCOPES = %w(issues merge_requests epics).freeze
2021-02-22 17:27:13 +05:30
2021-11-18 22:05:49 +05:30
delegator_override :search_objects
2021-02-22 17:27:13 +05:30
def search_objects
@search_objects ||= begin
objects = search_service.search_objects(SCOPE_PRELOAD_METHOD[scope.to_sym])
case scope
when 'users'
2023-03-04 22:38:38 +05:30
objects.respond_to?(:eager_load) ? objects.eager_load(:status) : objects # rubocop:disable CodeReuse/ActiveRecord
2021-02-22 17:27:13 +05:30
when 'commits'
prepare_commits_for_rendering(objects)
2023-06-20 00:43:36 +05:30
when 'projects'
prepare_projects_for_rendering(objects)
2021-02-22 17:27:13 +05:30
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
2023-03-04 22:38:38 +05:30
def advanced_search_enabled?
false
end
2021-02-22 17:27:13 +05:30
end
2023-03-04 22:38:38 +05:30
SearchServicePresenter.prepend_mod_with('SearchServicePresenter')