mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Clean quick search [SCI-10246]
This commit is contained in:
parent
a2a3c0ab28
commit
c253d0ffcf
|
@ -225,14 +225,12 @@ class SearchController < ApplicationController
|
|||
|
||||
def quick
|
||||
results = if params[:filter].present?
|
||||
object_quick_search(params[:filter].singularize,
|
||||
search_by_id: Constants::QUICK_SEARCH_SEARCHABLE_BY_NAME
|
||||
.exclude?(params[:filter].singularize))
|
||||
object_quick_search(params[:filter].singularize)
|
||||
else
|
||||
Constants::QUICK_SEARCH_SEARCHABLE_OBJECTS.filter_map do |object|
|
||||
next if object == 'label_template' && !LabelTemplate.enabled?
|
||||
|
||||
object_quick_search(object, search_by_id: Constants::QUICK_SEARCH_SEARCHABLE_BY_NAME.exclude?(object))
|
||||
object_quick_search(object)
|
||||
end.flatten.sort_by(&:updated_at).reverse.take(Constants::QUICK_SEARCH_LIMIT)
|
||||
end
|
||||
|
||||
|
@ -241,8 +239,9 @@ class SearchController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def object_quick_search(class_name, search_by_id: true)
|
||||
search_method = class_name.to_s.camelize.constantize.method(search_by_id ? :search_by_name_and_id : :search_by_name)
|
||||
def object_quick_search(class_name)
|
||||
search_model = class_name.to_s.camelize.constantize
|
||||
search_method = search_model.method(search_model.respond_to?(:code) ? :search_by_name_and_id : :search_by_name)
|
||||
|
||||
search_method.call(current_user,
|
||||
current_team,
|
||||
|
|
|
@ -447,7 +447,6 @@ class Constants
|
|||
QUICK_SEARCH_LIMIT = 5
|
||||
QUICK_SEARCH_SEARCHABLE_OBJECTS = %w(project experiment my_module protocol repository_row
|
||||
report project_folder result label_template).freeze
|
||||
QUICK_SEARCH_SEARCHABLE_BY_NAME = %w(project_folder result label_template).freeze
|
||||
|
||||
# ) \ / (
|
||||
# /|\ )\_/( /|\
|
||||
|
|
Loading…
Reference in a new issue