diff --git a/app/helpers/decidim/ideas/ideas_helper.rb b/app/helpers/decidim/ideas/ideas_helper.rb index 8ae1655..23d0b0a 100644 --- a/app/helpers/decidim/ideas/ideas_helper.rb +++ b/app/helpers/decidim/ideas/ideas_helper.rb @@ -26,12 +26,12 @@ def ideas_data_for_map(geocoded_ideas_data) end end - def ideas_map(geocoded_ideas) + def ideas_map(geocoded_ideas, **options) map_options = { type: "ideas", markers: geocoded_ideas } map_center = component_settings.default_map_center_coordinates map_options[:center_coordinates] = map_center.split(",").map(&:to_f) if map_center - dynamic_map_for(map_options) do + dynamic_map_for(map_options.merge(options)) do # These snippets need to be added AFTER the other map scripts have # been added which is why they cannot be within the block. Otherwise # e.g. the markercluser would not be available when the plans map is @@ -41,7 +41,11 @@ def ideas_map(geocoded_ideas) snippets.add(:foot, snippets.for(:plans_map_scripts)) end - yield + if block_given? + yield + else + "" + end end end diff --git a/app/models/decidim/ideas/idea.rb b/app/models/decidim/ideas/idea.rb index e763d57..80ce5c3 100644 --- a/app/models/decidim/ideas/idea.rb +++ b/app/models/decidim/ideas/idea.rb @@ -158,18 +158,26 @@ def self.geocoded_data_for(component) ) end + def self.area_scope_coordinates_for(component) + component.settings.area_scope_coordinates.to_h do |scope_id, coords| + latlng = coords.split(",") + next if latlng.length < 2 + + [ + scope_id.to_s.to_i, + [latlng[0].to_f, latlng[1].to_f] + ] + end.compact + end + def self.with_geocoded_area_scopes_for(component) # Fetch all the configured area scope coodinates and create a select # statement for each scope with its latitude and longitude in order to # combine this information with the base query. - scope_selects = component.settings.area_scope_coordinates.map do |scope_id, coords| - latlng = coords.split(",") - next if latlng.length < 2 + scope_selects = area_scope_coordinates_for(component).map do |scope_id, coords| + "SELECT #{scope_id} AS scope_id, #{coords[0]} AS latitude, #{coords[1]} AS longitude" + end - lat = latlng[0].to_f - lng = latlng[1].to_f - "SELECT #{scope_id} AS scope_id, #{lat} AS latitude, #{lng} AS longitude" - end.compact # The empty select ensures there is always at least one row for the # scope locations so that it will not break even when it is not # configured correctly. @@ -331,6 +339,25 @@ def within_edit_time_limit? Time.current < limit end + # Replicates the same data for a single idea as returned for a collection + # through the `#geocoded_data_for` method. + def geocoded_data + locale = I18n.locale.to_s + default_locale = I18n.default_locale.to_s + + scope_coordinates = self.class.area_scope_coordinates_for(component) + idea_scope_coordinates = scope_coordinates[area_scope.id] || [] + + [ + id, + title, + body, + address || area_scope.title[locale] || area_scope.title[default_locale], + latitude || idea_scope_coordinates[0], + longitude || idea_scope_coordinates[1] + ] + end + # Create i18n ransackers for :title and :body. # Create the :search_text ransacker alias for searching from both of these. ransacker_text_multi :search_text, [:title, :body] diff --git a/app/views/decidim/ideas/ideas/_count.html.erb b/app/views/decidim/ideas/ideas/_count.html.erb index 3945442..85d1f2d 100644 --- a/app/views/decidim/ideas/ideas/_count.html.erb +++ b/app/views/decidim/ideas/ideas/_count.html.erb @@ -1 +1 @@ -

<%= t(".ideas_count", count: @ideas.total_count) %>

+

<%= t(".ideas_count", count: @ideas.total_count) %>

diff --git a/app/views/decidim/ideas/ideas/_idea_actions.html.erb b/app/views/decidim/ideas/ideas/_idea_actions.html.erb index 99b137e..dc06730 100644 --- a/app/views/decidim/ideas/ideas/_idea_actions.html.erb +++ b/app/views/decidim/ideas/ideas/_idea_actions.html.erb @@ -4,12 +4,12 @@ <% end %> -<% if component_settings.geocoding_enabled? && idea.latitude.present? && idea.longitude.present? %> +<% if component_settings.geocoding_enabled? && idea.address.present? && idea.latitude.present? && idea.longitude.present? %>
- <%= link_to idea_map_link(idea), class: "action-link", target: "_blank", data: { external_link_spacer: "" } do %> + <%= t ".show_on_map" %> <%= icon "map-marker", role: "img", "aria-hidden": true %> - <% end %> +
<% end %> diff --git a/app/views/decidim/ideas/ideas/_idea_full.html.erb b/app/views/decidim/ideas/ideas/_idea_full.html.erb index 6fac086..653dbef 100644 --- a/app/views/decidim/ideas/ideas/_idea_full.html.erb +++ b/app/views/decidim/ideas/ideas/_idea_full.html.erb @@ -55,6 +55,8 @@ <% end %> + <%= render partial: "idea_map", locals: { idea: idea } %> +
<%= attachments_for idea %> diff --git a/app/views/decidim/ideas/ideas/_idea_map.html.erb b/app/views/decidim/ideas/ideas/_idea_map.html.erb new file mode 100644 index 0000000..fdbfb12 --- /dev/null +++ b/app/views/decidim/ideas/ideas/_idea_map.html.erb @@ -0,0 +1,7 @@ +<% if component_settings.geocoding_enabled? && idea.address.present? && idea.latitude.present? && idea.longitude.present? %> +
+

<%= t(".title") %>

+ + <%= ideas_map ideas_data_for_map([idea.geocoded_data]), type: "resource-markers" %> +
+<% end %> diff --git a/app/views/decidim/ideas/ideas/_map_template.html.erb b/app/views/decidim/ideas/ideas/_map_template.html.erb new file mode 100644 index 0000000..8dd1a36 --- /dev/null +++ b/app/views/decidim/ideas/ideas/_map_template.html.erb @@ -0,0 +1,21 @@ + diff --git a/app/views/decidim/ideas/ideas/index.html.erb b/app/views/decidim/ideas/ideas/index.html.erb index 9fb27ed..dc66c4d 100644 --- a/app/views/decidim/ideas/ideas/index.html.erb +++ b/app/views/decidim/ideas/ideas/index.html.erb @@ -55,19 +55,24 @@
-
-
- <%= order_selector available_orders, i18n_scope: "decidim.ideas.ideas.orders" %> +
+
+
+ <%= render partial: "count" %> +
- <% if false %> -
- <%= render partial: "decidim/shared/results_per_page" %> +
+
+
+ <%= order_selector available_orders, i18n_scope: "decidim.ideas.ideas.orders" %> +
+ <% if false %> +
+ <%= render partial: "decidim/shared/results_per_page" %> +
+ <% end %>
- <% end %> -
- -
- <%= render partial: "count" %> +
@@ -84,27 +89,7 @@ <% if component_settings.geocoding_enabled? %>
<%= ideas_map ideas_data_for_map(@geocoded_ideas) do %> - + <%= render partial: "map_template" %> <% end %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a980293..0bcd9e4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -420,8 +420,8 @@ en: title: Complete your idea count: ideas_count: - one: "%{count} idea" - other: "%{count} ideas" + one: "Found %{count} idea" + other: "Found %{count} ideas" edit: back: Back to previous page send: Save @@ -507,7 +507,6 @@ en: show_list: Show results as list show_map: Show results on map subtitle: Search and discover ideas! - view_idea: View idea map: dynamic: skip_button: Skip map @@ -556,13 +555,17 @@ en: edit_idea: Edit idea show_versions: Show version history subtitle: Idea + idea_map: + title: Idea on map ideas: empty: There are no ideas yet empty_filters: There isn't any idea with this criteria + map_template: + view_idea: View idea show: answer: Answer back_to: Back to - back_to_list: See other ideas + back_to_list: See all ideas changes_at_title: Amendment to "%{title}" feedback_title: Thank you for submitting an idea! link_to_promoted_emendation_help_text: This idea is a promoted emendation diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 4923001..201c3f7 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -420,8 +420,8 @@ fi: title: Viimeistele ideasi count: ideas_count: - one: "%{count} idea" - other: "%{count} ideaa" + one: "Löytyi %{count} idea" + other: "Löytyi %{count} ideaa" edit: back: Palaa edelliselle sivulle send: Tallenna @@ -507,7 +507,6 @@ fi: show_list: Näytä tulokset listana show_map: Näytä tulokset kartalla subtitle: Etsi ja tutki ideoita! - view_idea: Näytä idea map: dynamic: skip_button: Ohita kartta @@ -556,13 +555,17 @@ fi: edit_idea: Muokkaa ideaa show_versions: Näytä versiohistoria subtitle: Idea + idea_map: + title: Idea kartalla ideas: empty: Ei vielä ideoita empty_filters: Ideoita ei löytynyt valituilla hakuehdoilla + map_template: + view_idea: Näytä idea show: answer: Vastaa back_to: Takaisin - back_to_list: Näytä muut ideat + back_to_list: Näytä kaikki ideat changes_at_title: Muutokset kohteessa "%{title}" feedback_title: Kiitos idean jättämisestä! link_to_promoted_emendation_help_text: Tämä idea on peräisin toisen ehdotuksen muutoksesta diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 7f0ecaf..42376b7 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -420,8 +420,8 @@ sv: title: Komplettera din idé count: ideas_count: - one: "%{count} idé" - other: "%{count} idéer" + one: "Hittade %{count} idé" + other: "Hittade %{count} idéer" edit: back: Tillbaka till föregående sida send: Spara @@ -507,7 +507,6 @@ sv: show_list: Visa resultat som lista show_map: Visa resultat på kartan subtitle: Sök och utforska idéer! - view_idea: Visa idé map: dynamic: skip_button: Hoppa över karta @@ -556,13 +555,17 @@ sv: edit_idea: Redigera idé show_versions: Visa versionshistorik subtitle: Idén + idea_map: + title: Idé på kartan ideas: empty: Det finns inga idéer ännu empty_filters: Det finns ingen idé med dessa kriterier + map_template: + view_idea: Visa idé show: answer: Svara back_to: Tillbaka till - back_to_list: Visa andra idéer + back_to_list: Visa alla idéer changes_at_title: Ändring till %{title} feedback_title: Tack för att du skickade en idé! link_to_promoted_emendation_help_text: Denna idé är ett annonserat ändringsförslag