Module: OtusHelper

Defined in:
app/helpers/otus_helper.rb

Instance Method Summary collapse

Instance Method Details

Stub a smart link to browse OTUs

Parameters:

  • object (an instance of TaxonName or Otu)

    if TaxonName is provided JS UI will disambiguate if more options are possible



50
51
52
53
54
# File 'app/helpers/otus_helper.rb', line 50

def browse_otu_link(object)
  return nil if object.nil?
  otu = object.metamorphosize
  (:div, '', 'data-taxon-name' => object_tag(otu), 'data-redirect' => 'true', 'data-id' => otu.id, 'data-klass' => object.class.base_class.name.to_s, 'data-otu-button' => 'true')
end

#label_for_otu(otu) ⇒ Object



32
33
34
35
36
37
# File 'app/helpers/otus_helper.rb', line 32

def label_for_otu(otu)
  return nil if otu.nil?
  [otu.name,
   label_for_taxon_name(otu.taxon_name)
  ].compact.join(': ')
end

#next_otus(otu) ⇒ Array

Returns of OTUs.

Returns:

  • (Array)

    of OTUs



67
68
69
70
71
72
73
# File 'app/helpers/otus_helper.rb', line 67

def next_otus(otu)
  if otu.taxon_name_id
    otu.taxon_name.next_sibling&.otus || []
  else
    Otu.where(project_id: otu.id).where('id > ?', otu.id).all
  end
end

#otu_autocomplete_selected_tag(otu) ⇒ String

Returns no HTML inside <input>.

Returns:

  • (String)

    no HTML inside <input>



20
21
22
23
24
25
# File 'app/helpers/otus_helper.rb', line 20

def otu_autocomplete_selected_tag(otu)
  return nil if otu.nil? || (otu.new_record? && !otu.changed?)
  [otu.name,
   Utilities::Strings.nil_wrap('[',taxon_name_autocomplete_selected_tag(otu.taxon_name), ']')
  ].compact.join(' ')
end


27
28
29
30
# File 'app/helpers/otus_helper.rb', line 27

def otu_link(otu)
  return nil if otu.nil?
  link_to(otu_tag_elements(otu).join(' ').html_safe, otu)
end

#otu_tag(otu) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/otus_helper.rb', line 3

def otu_tag(otu)
  return nil if otu.nil?
  a = otu_tag_elements(otu)
  a.push taxon_name_type_short_tag(otu.taxon_name)
  (:span, a.compact.join(' ').html_safe, class: :otu_tag)
end

#otu_tag_elements(otu) ⇒ Object



10
11
12
13
14
15
16
# File 'app/helpers/otus_helper.rb', line 10

def otu_tag_elements(otu)
  return nil if otu.nil?
  [
    ( otu.name ? (:span, otu.name, class: :otu_tag_otu_name) : nil ),
    ( otu.taxon_name ? (:span, full_taxon_name_tag(otu.taxon_name).html_safe, class: :otu_tag_taxon_name, title: otu.taxon_name.id) : nil)
  ].compact
end


43
44
45
# File 'app/helpers/otus_helper.rb', line 43

def otus_link_list_tag(otus)
  otus.collect { |o| link_to(o.name, o) }.join(',')
end

#otus_radial(object) ⇒ Object



61
62
63
# File 'app/helpers/otus_helper.rb', line 61

def otus_radial(object)
  (:div, '', 'data-global-id' => object.to_global_id.to_s, 'data-otu-radial' => 'true')
end

#otus_radial_disambiguate(object) ⇒ Object



56
57
58
59
# File 'app/helpers/otus_helper.rb', line 56

def otus_radial_disambiguate(object)
  otu = object.metamorphosize
  (:div, '', 'data-taxon-name' => object_tag(otu), 'data-redirect' => 'false', 'data-id' => otu.id, 'data-klass' => object.class.base_class.name.to_s, 'data-otu-button' => 'true')
end

#otus_search_formObject



39
40
41
# File 'app/helpers/otus_helper.rb', line 39

def otus_search_form
  render('/otus/quick_search_form')
end

#parent_otus(otu) ⇒ Object



83
84
85
# File 'app/helpers/otus_helper.rb', line 83

def parent_otus(otu)
  otu.taxon_name&.parent&.otus&.all || []
end

#parents_by_nomenclature(otu) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'app/helpers/otus_helper.rb', line 87

def parents_by_nomenclature(otu)
  above = [ ]
  if otu.taxon_name_id
    otu.taxon_name.ancestors.select('taxon_names.*, taxon_name_hierarchies.generations').that_is_valid.joins(:otus).distinct.reorder('taxon_name_hierarchies.generations DESC, taxon_names.cached_valid_taxon_name_id').each do |t|
      above.push [t.cached, t.otus.to_a]
    end
  end
  above
end

#previous_otus(otu) ⇒ Object



75
76
77
78
79
80
81
# File 'app/helpers/otus_helper.rb', line 75

def previous_otus(otu)
  if otu.taxon_name_id
    otu.taxon_name.previous_sibling&.otus || []
  else
    Otu.where(project_id: otu.id).where('id < ?', otu.id).all
  end
end