From dbac4bc222628648a55666c9c1ac2fa2832a6614 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:24:10 +0100 Subject: [PATCH] Change admin settings tab for maps - Rename map settings keys - Add fields for latitude, longitude and zoom - Add a callout message on how to enable map feature --- app/controllers/admin/settings_controller.rb | 7 ++++--- app/helpers/map_locations_helper.rb | 6 +++--- ....html.erb => _map_configuration_tab.html.erb} | 7 ++++++- app/views/admin/settings/_map_form.html.erb | 16 ++++++++-------- config/locales/en/admin.yml | 1 + config/locales/en/settings.yml | 13 +++++++------ config/locales/es/admin.yml | 1 + config/locales/es/settings.yml | 13 +++++++------ db/dev_seeds/budgets.rb | 6 +++--- db/dev_seeds/settings.rb | 6 +++--- db/seeds.rb | 6 +++--- spec/features/admin/settings_spec.rb | 6 ++++++ 12 files changed, 52 insertions(+), 36 deletions(-) rename app/views/admin/settings/{_map_configuration.html.erb => _map_configuration_tab.html.erb} (51%) diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index b13387269..509d6aa97 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -4,6 +4,7 @@ class Admin::SettingsController < Admin::BaseController all_settings = Setting.all.group_by { |setting| setting.type } @configuration_settings = all_settings["configuration"] @feature_settings = all_settings["feature"] + @map_configuration_settings = all_settings["map"] end def update @@ -13,9 +14,9 @@ class Admin::SettingsController < Admin::BaseController end def update_map - Setting["map_latitude"] = params[:latitude].to_f - Setting["map_longitude"] = params[:longitude].to_f - Setting["map_zoom"] = params[:zoom].to_i + Setting["map.latitude"] = params[:latitude].to_f + Setting["map.longitude"] = params[:longitude].to_f + Setting["map.zoom"] = params[:zoom].to_i redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update") end diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index a471d1b8d..d05f2c722 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -5,15 +5,15 @@ module MapLocationsHelper end def map_location_latitude(map_location) - map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map_latitude"] + map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"] end def map_location_longitude(map_location) - map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map_longitude"] + map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] end def map_location_zoom(map_location) - map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map_zoom"] + map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] end def map_location_input_id(prefix, attribute) diff --git a/app/views/admin/settings/_map_configuration.html.erb b/app/views/admin/settings/_map_configuration_tab.html.erb similarity index 51% rename from app/views/admin/settings/_map_configuration.html.erb rename to app/views/admin/settings/_map_configuration_tab.html.erb index 342e05f32..871739337 100644 --- a/app/views/admin/settings/_map_configuration.html.erb +++ b/app/views/admin/settings/_map_configuration_tab.html.erb @@ -1,8 +1,13 @@ <% if feature?(:map) %>

<%= t("admin.settings.index.map.title") %>

+ + <%= render "settings_table", settings: @map_configuration_settings %> +

<%= t("admin.settings.index.map.help") %>

<%= render "map_form" %> <% else %> -

No map to show.

+
+ <%= t("admin.settings.index.map.how_to_enable") %> +
<% end %> diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb index 4a25082f7..49d2496f2 100644 --- a/app/views/admin/settings/_map_form.html.erb +++ b/app/views/admin/settings/_map_form.html.erb @@ -2,14 +2,14 @@
" - data-map-center-longitude="<%= Setting["map_longitude"] %>" - data-map-zoom="<%= Setting["map_zoom"] %>" + data-map-center-latitude="<%= Setting["map.latitude"] %>" + data-map-center-longitude="<%= Setting["map.longitude"] %>" + data-map-zoom="<%= Setting["map.zoom"] %>" data-map-tiles-provider="<%= Rails.application.secrets.map_tiles_provider %>" data-map-tiles-provider-attribution="<%= Rails.application.secrets.map_tiles_provider_attribution %>" data-marker-editable="true" - data-marker-latitude="<%= Setting["map_latitude"] %>" - data-marker-longitude="<%= Setting["map_longitude"] %>" + data-marker-latitude="<%= Setting["map.latitude"] %>" + data-marker-longitude="<%= Setting["map.longitude"] %>" data-latitude-input-selector="#latitude" data-longitude-input-selector="#longitude" data-zoom-input-selector="#zoom"> @@ -17,9 +17,9 @@ <%= form_tag admin_update_map_path, method: :put, id: "map-form" do |f| %> - <%= hidden_field_tag :latitude, Setting["map_latitude"] %> - <%= hidden_field_tag :longitude, Setting["map_longitude"] %> - <%= hidden_field_tag :zoom, Setting["map_zoom"] %> + <%= hidden_field_tag :latitude, Setting["map.latitude"] %> + <%= hidden_field_tag :longitude, Setting["map.longitude"] %> + <%= hidden_field_tag :zoom, Setting["map.zoom"] %>
<%= submit_tag t("admin.settings.index.map.form.submit"), diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 656e102ea..bfbd5f9bd 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1188,6 +1188,7 @@ en: update: Map configuration updated succesfully. form: submit: Update + how_to_enable: 'To show the map to users you must enable "Proposals and budget investments geolocation" on "Features" tab.' setting: Feature setting_actions: Actions setting_name: Setting diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index 363c3b875..ab4b34803 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -52,12 +52,6 @@ en: related_content_score_threshold_description: "According to the rating of votes in a related content, hides content that users mark as unrelated" hot_score_period_in_days: "Period (days) used by the filter 'most active'" hot_score_period_in_days_description: "The filter 'most active' used in multiple sections will be based on the votes during the last X days" - map_latitude: "Latitude" - map_latitude_description: "Latitude to show the map position" - map_longitude: "Longitude" - map_longitude_description: "Longitude to show the position of the map" - map_zoom: "Zoom" - map_zoom_description: "Zoom to show the map position" mailer_from_name: "Sender email name" mailer_from_name_description: "This name will appear as sender name in emails sent from the application" mailer_from_address: "Sender email address" @@ -124,3 +118,10 @@ en: public_stats_description: "Display public stats in the Administration panel" help_page: "Help page" help_page_description: 'Displays a Help menu that contains a page with an info section about each enabled feature. Also custom pages and menus can be created in the "Custom pages" and "Custom content blocks" sections' + map: + latitude: "Latitude" + latitude_description: "Latitude to show the map position" + longitude: "Longitude" + longitude_description: "Longitude to show the position of the map" + zoom: "Zoom" + zoom_description: "Zoom to show the map position" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 36fc3d59b..037620ab8 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1187,6 +1187,7 @@ es: update: La configuración del mapa se ha guardado correctamente. form: submit: Actualizar + how_to_enable: 'Para mostrar el mapa a los usuarios se debe de activar "Geolocalización de propuestas y proyectos de gasto" en la pestaña "Funcionalidades".' setting: Funcionalidad setting_actions: Acciones setting_name: Configuración diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index 33f1c9d80..6a251102c 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -52,12 +52,6 @@ es: related_content_score_threshold_description: "Según la puntuación de votos en un contenido relacionado, oculta el contenido que los usuarios marquen como no relacionado" hot_score_period_in_days: "Periodo (días) usado para el filtro 'Más Activos'" hot_score_period_in_days_description: "El filtro 'Más Activos' usado en diferentes secciones se basará en los votos de los últimos X días" - map_latitude: "Latitud" - map_latitude_description: "Latitud para mostrar la posición del mapa" - map_longitude: "Longitud" - map_longitude_description: "Longitud para mostrar la posición del mapa" - map_zoom: "Zoom" - map_zoom_description: "Zoom para mostrar la posición del mapa" mailer_from_name: "Nombre email remitente" mailer_from_name_description: "Este nombre aparecerá como nombre del remitente en los emails enviados desde la aplicación" mailer_from_address: "Dirección email remitente" @@ -124,3 +118,10 @@ es: public_stats_description: "Muestra las estadísticas públicas en el panel de Administración" help_page: "Página de ayuda" help_page_description: 'Muestra un menú Ayuda que contiene una página con una sección de información sobre cada funcionalidad habilitada. También se pueden crear páginas y menús personalizados en las secciones "Personalizar páginas" y "Personalizar bloques"' + map: + latitude: "Latitud" + latitude_description: "Latitud para mostrar la posición del mapa" + longitude: "Longitud" + longitude_description: "Longitud para mostrar la posición del mapa" + zoom: "Zoom" + zoom_description: "Zoom para mostrar la posición del mapa" diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index f0f842d73..dc96d658c 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -151,9 +151,9 @@ end section "Geolocating Investments" do Budget.find_each do |budget| budget.investments.each do |investment| - MapLocation.create(latitude: Setting["map_latitude"].to_f + rand(-10..10)/100.to_f, - longitude: Setting["map_longitude"].to_f + rand(-10..10)/100.to_f, - zoom: Setting["map_zoom"], + MapLocation.create(latitude: Setting["map.latitude"].to_f + rand(-10..10)/100.to_f, + longitude: Setting["map.longitude"].to_f + rand(-10..10)/100.to_f, + zoom: Setting["map.zoom"], investment_id: investment.id) end end diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 6cecac651..5d4abbb6b 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -59,9 +59,9 @@ section "Creating Settings" do "transparent and democratic government") Setting.create(key: "meta_keywords", value: "citizen participation, open government") Setting.create(key: "min_age_to_participate", value: "16") - Setting.create(key: "map_latitude", value: 40.41) - Setting.create(key: "map_longitude", value: -3.7) - Setting.create(key: "map_zoom", value: 10) + Setting.create(key: "map.latitude", value: 40.4332002) + Setting.create(key: "map.longitude", value: -3.7009591) + Setting.create(key: "map.zoom", value: 10) Setting.create(key: "featured_proposals_number", value: 3) Setting.create(key: "proposal_notification_minimum_interval_in_days", value: 0) Setting.create(key: "direct_message_max_per_day", value: 3) diff --git a/db/seeds.rb b/db/seeds.rb index acd473e00..72e800f8d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -106,9 +106,9 @@ Setting["min_age_to_participate"] = 16 Setting["featured_proposals_number"] = 3 # City map feature default configuration (Greenwich) -Setting["map_latitude"] = 51.48 -Setting["map_longitude"] = 0.0 -Setting["map_zoom"] = 10 +Setting["map.latitude"] = 51.48 +Setting["map.longitude"] = 0.0 +Setting["map.zoom"] = 10 # Related content Setting["related_content_score_threshold"] = -0.3 diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index 954365d89..41d573299 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -37,6 +37,9 @@ feature "Admin settings" do visit admin_settings_path find("#map-tab").click + expect(page).to have_content 'To show the map to users you must enable ' \ + '"Proposals and budget investments geolocation" ' \ + 'on "Features" tab.' expect(page).not_to have_css("#admin-map") end @@ -48,6 +51,9 @@ feature "Admin settings" do find("#map-tab").click expect(page).to have_css("#admin-map") + expect(page).not_to have_content 'To show the map to users you must enable ' \ + '"Proposals and budget investments geolocation" ' \ + 'on "Features" tab.' end scenario "Should show successful notice" do