Module: AssertedDistributionsHelper

Defined in:
app/helpers/asserted_distributions_helper.rb

Instance Method Summary collapse

Instance Method Details



24
25
26
27
28
29
30
31
# File 'app/helpers/asserted_distributions_helper.rb', line 24

def asserted_distribution_link(asserted_distribution)
  return nil if asserted_distribution.nil?
  [
    link_to(otu_tag(asserted_distribution.otu).html_safe, asserted_distribution.otu),
    (asserted_distribution.is_absent ? (:span, ' not in ', class: :warning) : ' in '),
    link_to(geographic_area_tag(asserted_distribution.geographic_area).html_safe,
            asserted_distribution) ].join(' ').html_safe
end

#asserted_distribution_tag(asserted_distribution) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/asserted_distributions_helper.rb', line 3

def asserted_distribution_tag(asserted_distribution)
  return nil if asserted_distribution.nil?
  [
    otu_tag(asserted_distribution.otu).html_safe,
    (asserted_distribution.is_absent ? tag.span(' not in ', class: [:feedback, 'feedback-thin', 'feedback-warning']).html_safe : ' in ').html_safe,
    geographic_area_tag(asserted_distribution.geographic_area).html_safe
                                                                    #,
  # ' by ',
  # (asserted_distribution.source.cached_author_string ? asserted_distribution.source.cached_author_string
  # : content_tag(:span, '[source authors must be updated]', class: :warning))
  ].join(' ').html_safe
end

#asserted_distribution_to_geo_json_feature(asserted_distribution) ⇒ Hash

Returns GeoJSON feature.

Returns:

  • (Hash)

    GeoJSON feature



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/asserted_distributions_helper.rb', line 42

def asserted_distribution_to_geo_json_feature(asserted_distribution)
  return nil if asserted_distribution.nil?
  return nil unless asserted_distribution.has_shape?

  return {
    'type' => 'Feature',
    'geometry' => RGeo::GeoJSON.encode(asserted_distribution.geographic_area.geographic_items.first.geo_object), # TODO: optimize
    'properties' => {
      'base' => {
        'type' => 'AssertedDistribution',
        'id' => asserted_distribution.id,
        'label' => label_for_asserted_distribution(asserted_distribution) },
      'shape' => {
        'type' => 'GeographicArea',
        'id' => asserted_distribution.geographic_area_id },
      'is_absent' => asserted_distribution.is_absent
    }
  }
end

#asserted_distributions_search_formObject



33
34
35
# File 'app/helpers/asserted_distributions_helper.rb', line 33

def asserted_distributions_search_form
  render('/asserted_distributions/quick_search_form')
end

#label_for_asserted_distribution(asserted_distribution) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/asserted_distributions_helper.rb', line 16

def label_for_asserted_distribution(asserted_distribution)
  return nil if asserted_distribution.nil?
  [ label_for_otu(asserted_distribution.otu),
    label_for_geographic_area(asserted_distribution.geographic_area),
    label_for_source(asserted_distribution.source)
  ].compact.join(' in ')
end

#no_geographic_items?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/helpers/asserted_distributions_helper.rb', line 37

def no_geographic_items?
  ' (has no geographic items)' if @asserted_distribution.geographic_area.geographic_items.empty?
end