Module: GeographicAreasHelper

Defined in:
app/helpers/geographic_areas_helper.rb

Instance Method Summary collapse

Instance Method Details

#geographic_area_autocomplete_tag(geographic_area, term) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/geographic_areas_helper.rb', line 13

def geographic_area_autocomplete_tag(geographic_area, term)
  return nil if geographic_area.nil?

  if term
    s = geographic_area.name.gsub(/#{Regexp.escape(term)}/i, "<mark>#{term}</mark>") + ' '
  else
    s = geographic_area.name + ' '
  end
  
  s = [geographic_area&.parent&.parent&.name, geographic_area&.parent&.name, s].compact.join(': ').gsub('Earth: ', '')

  s += (:span, geographic_area.geographic_area_type.name, class: [:feedback, 'feedback-info', 'feedback-thin'])  unless geographic_area.geographic_area_type.nil?
  s += ' ' + (geographic_area.has_shape? ? (:span, 'has shape', class: [:feedback, 'feedback-success', 'feedback-thin']) : (:span, 'without shape', class: [:feedback, 'feedback-danger', 'feedback-thin']) )
  c = geographic_area.collecting_events.where(project_id: sessions_current_project_id).count + geographic_area.asserted_distributions.where(project_id: sessions_current_project_id).count
  s += ' ' + ( c > 0 ? (:span, "#{c.to_s}&nbsp;#{'use'.pluralize(c)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin']) : '' )

  s.html_safe
end

#geographic_area_data_origin_select_tagObject



52
53
54
# File 'app/helpers/geographic_areas_helper.rb', line 52

def geographic_area_data_origin_select_tag
  select_tag(:data_origin, options_for_select(GeographicArea.pluck(:data_origin).uniq), include_blank: true)
end


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

def geographic_area_link(geographic_area, link_text = nil)
  return nil if geographic_area.nil?
  link_text ||= geographic_area.name
  link_to(link_text, geographic_area)
end


46
47
48
49
50
# File 'app/helpers/geographic_areas_helper.rb', line 46

def geographic_area_link_list(geographic_areas)
  (:ul) do
    geographic_areas.collect { |a| (:li, geographic_area_link(a)) }.join.html_safe
  end
end

#geographic_area_tag(geographic_area) ⇒ Object



3
4
5
6
# File 'app/helpers/geographic_areas_helper.rb', line 3

def geographic_area_tag(geographic_area)
  return nil if geographic_area.nil?
  geographic_area.name
end


42
43
44
# File 'app/helpers/geographic_areas_helper.rb', line 42

def geographic_areas_link_list_tag(geographic_areas)
  geographic_areas.collect { |ga| link_to(ga.name, ga) }.join(',')
end

#geographic_areas_search_formObject



38
39
40
# File 'app/helpers/geographic_areas_helper.rb', line 38

def geographic_areas_search_form
  render('/geographic_areas/quick_search_form')
end

#label_for_geographic_area(geographic_area) ⇒ Object



8
9
10
11
# File 'app/helpers/geographic_areas_helper.rb', line 8

def label_for_geographic_area(geographic_area)
  return nil if geographic_area.nil?
  geographic_area.name
end