diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/application_helper.rb | 19 | ||||
-rw-r--r-- | app/helpers/leaflet_helper.rb | 11 | ||||
-rw-r--r-- | app/helpers/map_helper.rb | 19 | ||||
-rw-r--r-- | app/helpers/sections_helper.rb | 19 | ||||
-rw-r--r-- | app/helpers/taxonomies/filter_helper.rb | 2 |
5 files changed, 50 insertions, 20 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 15d5082..e39da5f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -6,25 +6,6 @@ module ApplicationHelper def current_agency current_user.agencies.where(agent: current_agent).first end - %w(observer editor maintainer leader).each do |role| - define_method :"current_user_#{role}?" do - current_agency.send(:"#{role}?") - end - end - - def map_container(map = Map.first) - raw tag.div( - tag.div(id: 'map', - data: { - target: 'map.container' - }), - data: { - controller: 'map', - 'map-latitude': map.latitude, - 'map-longitude': map.longitude, - 'map-zoom': map.zoom - }) - end # Markdown helper # Always use all extensions. Additional parser and render options may be diff --git a/app/helpers/leaflet_helper.rb b/app/helpers/leaflet_helper.rb new file mode 100644 index 0000000..6ca03f3 --- /dev/null +++ b/app/helpers/leaflet_helper.rb @@ -0,0 +1,11 @@ +module LeafletHelper + def marker_for(resource, options = {}) + coords = [resource.latitude, resource.longitude] + + "L.marker(#{coords}, #{options}).bindPopup(%s)" % popup_for(resource) + end + + def popup_for(resource) + render partial: 'resource/popup', locals: { resource: resource } + end +end diff --git a/app/helpers/map_helper.rb b/app/helpers/map_helper.rb new file mode 100644 index 0000000..3403801 --- /dev/null +++ b/app/helpers/map_helper.rb @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc> +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +module MapHelper + def map_container(map = Map.first) + raw tag.div( + tag.div(id: 'map', + data: { + target: 'map.container' + }), + data: { + controller: 'map', + 'map-latitude': map.latitude, + 'map-longitude': map.longitude, + 'map-zoom': map.zoom + }) + end +end diff --git a/app/helpers/sections_helper.rb b/app/helpers/sections_helper.rb new file mode 100644 index 0000000..8180fee --- /dev/null +++ b/app/helpers/sections_helper.rb @@ -0,0 +1,19 @@ +module SectionsHelper + # Render a section as a GeoJSON FeatureCollection + def geojson_feature_collection(section) + out = [] + class_name = { baseVal: "cat#{section.category_id} sec#{section.id}" } + style = { fill: section.category.color } + + section.resources.each do |marker| + # Add styling + marker = marker.to_geojson + marker['className'] = class_name + marker['style'] = style + + out << marker.to_json + end + + raw("{ \"type\": \"FeatureCollection\", \"features\": [ #{out.join(',')} ] }") + end +end diff --git a/app/helpers/taxonomies/filter_helper.rb b/app/helpers/taxonomies/filter_helper.rb index 97fe271..92a501f 100644 --- a/app/helpers/taxonomies/filter_helper.rb +++ b/app/helpers/taxonomies/filter_helper.rb @@ -11,7 +11,7 @@ module Taxonomies::FilterHelper @taxonomy.categories.each do |cat| list = [] cat.sections.each do |sec| - list << tag.li(h("#{sec.rank}. #{sec.name}"), id: "section-#{sec.id}", data: { action: "taxonomy#section", target: 'taxonomy.section', 'taxonomy-section-id': sec.id }) + list << tag.li(h("#{sec.rank}. #{sec.name}"), id: "section-#{sec.id}", data: { action: "click->taxonomy#section", target: 'taxonomy.section', 'taxonomy-section-id': sec.id }) end html << tag.li(h("#{cat.rank}. #{cat.name}") << tag.ol(list.join.html_safe), id: "category-#{cat.id}", |