Class: Autoselect::Otu::Levels::Smart

Inherits:
Levels::Smart show all
Defined in:
lib/autoselect/otu/levels/smart.rb

Overview

Delegates to the existing OTU autocomplete query. Handles the :new_record operator by returning a sentinel that triggers OtuNewModal on the client side.

Constant Summary

Constants inherited from Levels::Smart

Levels::Smart::RECENT_LIMIT, Levels::Smart::RECENT_WINDOW

Constants inherited from Level

Level::DEFAULT_FUSE_MS, Level::EXTERNAL_FUSE_MS, Level::MINIMUM_RESULTS

Instance Method Summary collapse

Methods inherited from Levels::Smart

#description, #filter_class, #key, #label, #pinboard_model_name, #pinboard_records, #pinboard_top_record, #recent_records, #recent_records_by_user

Methods inherited from Level

#description, #external?, #fuse_ms, #key, #label, #metadata, #minimum_results, #model_key, #record_info, #record_info_html, #record_label, #record_label_html

Instance Method Details

#call(term:, operator: nil, project_id: nil, user_id: nil, **kwargs) ⇒ Object



14
15
16
17
# File 'lib/autoselect/otu/levels/smart.rb', line 14

def call(term:, operator: nil, project_id: nil, user_id: nil, **kwargs)
  return new_otu_sentinel(term) if operator == :new_record
  super
end

#new_otu_sentinel(name_prefill) ⇒ Object (private)



21
22
23
24
25
26
27
28
# File 'lib/autoselect/otu/levels/smart.rb', line 21

def new_otu_sentinel(name_prefill)
  [OpenStruct.new(
    id: nil,
    name: name_prefill,
    taxon_name: nil,
    _otu_new_form: { mode: 'new_otu_form', name_prefill: }
  )]
end

#query_classObject



10
11
12
# File 'lib/autoselect/otu/levels/smart.rb', line 10

def query_class
  ::Queries::Otu::Autocomplete
end