Module: OtusHelper
- Defined in:
- app/helpers/otus_helper.rb
Instance Method Summary collapse
-
#browse_otu_link(object) ⇒ Object
Stub a smart link to browse OTUs.
- #label_for_otu(otu) ⇒ Object
-
#next_otus(otu) ⇒ Array
Of OTUs.
-
#otu_autocomplete_selected_tag(otu) ⇒ String
No HTML inside <input>.
-
#otu_distribution(otu, children = true) ⇒ Object
TODO:.
- #otu_link(otu) ⇒ Object
- #otu_tag(otu) ⇒ Object
- #otu_tag_elements(otu) ⇒ Object
- #otus_link_list_tag(otus) ⇒ Object
- #otus_radial(object) ⇒ Object
- #otus_radial_disambiguate(object) ⇒ Object
- #otus_search_form ⇒ Object
- #parent_otus(otu) ⇒ Object
-
#parents_by_nomenclature(otu) ⇒ Object
See also otus#ancestor_otu_ids ?.
-
#previous_otus(otu) ⇒ Array
Some OTUs don't have TaxonName, skip along until we hit one.
Instance Method Details
#browse_otu_link(object) ⇒ Object
Stub a smart link to browse OTUs
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. content_tag(: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
10 11 12 13 14 15 |
# File 'app/helpers/otus_helper.rb', line 10 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.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/otus_helper.rb', line 67 def next_otus(otu) if otu.taxon_name_id o = [] t = otu.taxon_name.next_sibling unless t.nil? while o.empty? o = t&.otus.to_a break if t.nil? t = t.next_sibling end end o 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>.
27 28 29 30 31 32 |
# File 'app/helpers/otus_helper.rb', line 27 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), ']')&.html_safe ].compact.join(' ') end |
#otu_distribution(otu, children = true) ⇒ Object
TODO:
* make properties universal
type: 'Model',
id: id,
label: <label>
-
merge origin_otu_id: id to reference coordinate OTUs
target:
type: Otu
label:
id
base: # one level above target (or one level below shape?!)
type:
id:
shape: # Either GeographicArea or Georeference
type
id
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'app/helpers/otus_helper.rb', line 158 def otu_distribution(otu, children = true) return {} if otu.nil? otus = if children otu.coordinate_otus_with_children else Otu.coordinate_otus(otu.id) end t = 40 if otus.size > t return { request_too_large: true, message: "The number of children (#{t}) of this OTU is too large to presently return." } end h = { 'type' => 'FeatureCollection', 'features' => [], 'properties' => { 'target' => { # Top level target 'id' => otu.id, 'label' => label_for_otu(otu), 'type' => 'Otu' } } } otus.each do |o| # internal target t = { 'id' => o.id, 'type' => 'Otu', 'label' => label_for_otu(otu) } o.current_collection_objects.each do |c| if g = collection_object_to_geo_json_feature(c) g['properties']['target'] = t h['features'].push g end end o.asserted_distributions.each do |a| if g = asserted_distribution_to_geo_json_feature(a) g['properties']['target'] = t h['features'].push g end end o.type_materials.each do |e| if g = type_material_to_geo_json_feature(e) g['properties']['target'] = t h['features'].push g end end end h end |
#otu_link(otu) ⇒ Object
34 35 36 37 |
# File 'app/helpers/otus_helper.rb', line 34 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) content_tag(:span, a.compact.join(' ').html_safe, class: :otu_tag) end |
#otu_tag_elements(otu) ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/helpers/otus_helper.rb', line 17 def otu_tag_elements(otu) return nil if otu.nil? [ ( otu.name ? content_tag(:span, otu.name, class: :otu_tag_otu_name, title: otu.id) : nil ), ( otu.taxon_name ? content_tag(:span, full_taxon_name_tag(otu.taxon_name).html_safe, class: :otu_tag_taxon_name, title: otu.taxon_name.id) : nil) ].compact end |
#otus_link_list_tag(otus) ⇒ Object
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) content_tag(: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. content_tag(: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_form ⇒ Object
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
105 106 107 |
# File 'app/helpers/otus_helper.rb', line 105 def parent_otus(otu) otu.taxon_name&.parent&.otus&.all || [] end |
#parents_by_nomenclature(otu) ⇒ Object
See also otus#ancestor_otu_ids ?
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/otus_helper.rb', line 110 def parents_by_nomenclature(otu) above = [ ] if otu.taxon_name_id TaxonName.ancestors_of(otu.taxon_name) .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] # TODO: to_a vs. pluck end end above end |
#previous_otus(otu) ⇒ Array
Some OTUs don't have TaxonName, skip along until we hit one.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/otus_helper.rb', line 88 def previous_otus(otu) if otu.taxon_name_id o = [] t = otu.taxon_name.previous_sibling unless t.nil? while o.empty? o = t&.otus.to_a break if t.nil? t = t.previous_sibling end end o else Otu.where(project_id: otu.id).where('id < ?', otu.id).all end end |