Module: GeographicItemsHelper

Defined in:
app/helpers/geographic_items_helper.rb

Instance Method Summary collapse

Instance Method Details



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/geographic_items_helper.rb', line 36

def children_through_geographic_areas_links(geographic_item)
  data = {}
  geographic_item.geographic_areas.each do |a|
    a.children.collect{ |c|
      data[c] = c.geographic_items.all
    }
  end

  links = []
  data.each do |k,v|
    next if v.nil?
    links += v.collect{ |i| geographic_item_link(i, k.name) }
  end
  links.join(', ').html_safe
end


12
13
14
15
16
# File 'app/helpers/geographic_items_helper.rb', line 12

def geographic_item_link(geographic_item, link_text = nil)
  return nil if geographic_item.nil?
  link_text ||= geographic_item.to_param
  link_to(link_text, geographic_item_path(geographic_item), data: {turbolinks: false})
end


18
19
20
21
# File 'app/helpers/geographic_items_helper.rb', line 18

def geographic_item_links(geographic_items)
  return (:em, 'none') if geographic_items.count == 0
  geographic_items.collect { |a| geographic_item_link(a) }.join(', ').html_safe
end


23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/geographic_items_helper.rb', line 23

def geographic_item_parent_nav_links(geographic_item)
  data = {}
  geographic_item.parent_geographic_areas.each do |a|
    data[a] = a.geographic_items
  end

  (:div,
              data.collect { |k, v| [
                (:ul, v.collect { |b|
                  (:li, geographic_item_link(b, k.name)) }.join.html_safe)
              ] }.flatten.join.html_safe)
end

#geographic_item_tag(geographic_item) ⇒ Object



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

def geographic_item_tag(geographic_item)
  return nil if geographic_item.nil?
  geographic_item.to_param
end

#json_tag(geographic_item) ⇒ Object



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

def json_tag(geographic_item)
  geographic_item&.to_geo_json_feature.to_json
end