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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/geographic_areas_helper.rb', line 8

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>") + ' ' # weee bit simpler
  else
    s = geographic_area.name + ' '
  end
  s = [geographic_area&.parent&.parent&.name, geographic_area&.parent&.name, s].compact.join(': ').gsub('Earth: ', '')

#    s += " (#{geographic_area.parent.name}) " unless geographic_area.parent.nil?
  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



49
50
51
# File 'app/helpers/geographic_areas_helper.rb', line 49

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


29
30
31
32
33
# File 'app/helpers/geographic_areas_helper.rb', line 29

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


43
44
45
46
47
# File 'app/helpers/geographic_areas_helper.rb', line 43

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


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

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

#geographic_areas_search_formObject



35
36
37
# File 'app/helpers/geographic_areas_helper.rb', line 35

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