Class: Admin::SearchController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/open_loam/install/templates/admin/search_controller.rb

Overview

One box, every entity. Results are grouped by entity and limited per group, so a broad query stays readable and cheap.

Tenant isolation needs no work here: each model's search returns its own tenant-scoped relation, so this can only ever find records the current tenant owns.

Constant Summary collapse

PER_ENTITY =
10

Constants included from Pagination

Pagination::PER_PAGE

Instance Method Summary collapse

Methods inherited from BaseController

skip_authorization!

Methods included from Pagination

#paginate

Instance Method Details

#index ⇒ Object



15
16
17
18
# File 'lib/generators/open_loam/install/templates/admin/search_controller.rb', line 15

def index
  @query = params[:q].to_s.strip
  @results = @query.blank? ? {} : search_all(@query)
end

#search_result_label(record) ⇒ Object

The first searchable column that has a value, plus the id — enough to recognise a record without OpenLoam having to know what a "title" is.



22
23
24
25
26
# File 'lib/generators/open_loam/install/templates/admin/search_controller.rb', line 22

def search_result_label(record)
  value = record.class.open_loam_searchable_columns.filter_map { |column| record.public_send(column).presence }.first

  [ value || record.model_name.human, "##{record.id}" ].join(" ")
end