Class: Kaui::HomeController

Inherits:
EngineController
  • Object
show all
Defined in:
app/controllers/kaui/home_controller.rb

Constant Summary collapse

QUERY_PARSE_REGEX =
['FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
'FIND:(?<object_type>.*) BY:(?<search_by>.*) FOR:(?<search_for>.*)',
'FIND:(?<object_type>.*) FOR:(?<search_for>.*) ONLY_FIRST:(?<fast>.*)',
'FIND:(?<object_type>.*) FOR:(?<search_for>.*)'].freeze
SIMPLE_PARSE_REGEX =
'(?<search_for>.*)'

Instance Method Summary collapse

Instance Method Details

#indexObject



12
13
14
15
16
17
18
19
# File 'app/controllers/kaui/home_controller.rb', line 12

def index
  @search_query = params[:q]
  @max_records = {}
  %w[account payment invoice].each do |type|
    model = "Kaui::#{type.capitalize}".constantize
    @max_records[type.to_sym] = model.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records
  end
end

#searchObject



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/kaui/home_controller.rb', line 21

def search
  object_type, search_query = splitting_new_search(params[:q])
  if search_query.nil?
    search_error('Please specify a search type (e.g., "Account: search_term")')
    return
  end
  object_type = object_type.tr(' ', '_').downcase
  cached_options_for_klient = options_for_klient
  send("#{object_type}_search", search_query, nil, 0, cached_options_for_klient)
end