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
This commit is contained in:
Julian Herrero
2019-03-13 12:24:10 +01:00
parent c0d2776e8d
commit dbac4bc222
12 changed files with 52 additions and 36 deletions

View File

@@ -4,6 +4,7 @@ class Admin::SettingsController < Admin::BaseController
all_settings = Setting.all.group_by { |setting| setting.type } all_settings = Setting.all.group_by { |setting| setting.type }
@configuration_settings = all_settings["configuration"] @configuration_settings = all_settings["configuration"]
@feature_settings = all_settings["feature"] @feature_settings = all_settings["feature"]
@map_configuration_settings = all_settings["map"]
end end
def update def update
@@ -13,9 +14,9 @@ class Admin::SettingsController < Admin::BaseController
end end
def update_map def update_map
Setting["map_latitude"] = params[:latitude].to_f Setting["map.latitude"] = params[:latitude].to_f
Setting["map_longitude"] = params[:longitude].to_f Setting["map.longitude"] = params[:longitude].to_f
Setting["map_zoom"] = params[:zoom].to_i Setting["map.zoom"] = params[:zoom].to_i
redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update") redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update")
end end

View File

@@ -5,15 +5,15 @@ module MapLocationsHelper
end end
def map_location_latitude(map_location) 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 end
def map_location_longitude(map_location) 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 end
def map_location_zoom(map_location) 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 end
def map_location_input_id(prefix, attribute) def map_location_input_id(prefix, attribute)

View File

@@ -1,8 +1,13 @@
<% if feature?(:map) %> <% if feature?(:map) %>
<h2><%= t("admin.settings.index.map.title") %></h2> <h2><%= t("admin.settings.index.map.title") %></h2>
<%= render "settings_table", settings: @map_configuration_settings %>
<p><%= t("admin.settings.index.map.help") %></p> <p><%= t("admin.settings.index.map.help") %></p>
<%= render "map_form" %> <%= render "map_form" %>
<% else %> <% else %>
<h3>No map to show.</h3> <div class="callout primary">
<%= t("admin.settings.index.map.how_to_enable") %>
</div>
<% end %> <% end %>

View File

@@ -2,14 +2,14 @@
<div class="small-12 column"> <div class="small-12 column">
<div id="admin-map" class="map" <div id="admin-map" class="map"
data-map data-map
data-map-center-latitude="<%= Setting["map_latitude"] %>" data-map-center-latitude="<%= Setting["map.latitude"] %>"
data-map-center-longitude="<%= Setting["map_longitude"] %>" data-map-center-longitude="<%= Setting["map.longitude"] %>"
data-map-zoom="<%= Setting["map_zoom"] %>" data-map-zoom="<%= Setting["map.zoom"] %>"
data-map-tiles-provider="<%= Rails.application.secrets.map_tiles_provider %>" data-map-tiles-provider="<%= Rails.application.secrets.map_tiles_provider %>"
data-map-tiles-provider-attribution="<%= Rails.application.secrets.map_tiles_provider_attribution %>" data-map-tiles-provider-attribution="<%= Rails.application.secrets.map_tiles_provider_attribution %>"
data-marker-editable="true" data-marker-editable="true"
data-marker-latitude="<%= Setting["map_latitude"] %>" data-marker-latitude="<%= Setting["map.latitude"] %>"
data-marker-longitude="<%= Setting["map_longitude"] %>" data-marker-longitude="<%= Setting["map.longitude"] %>"
data-latitude-input-selector="#latitude" data-latitude-input-selector="#latitude"
data-longitude-input-selector="#longitude" data-longitude-input-selector="#longitude"
data-zoom-input-selector="#zoom"> data-zoom-input-selector="#zoom">
@@ -17,9 +17,9 @@
<%= form_tag admin_update_map_path, method: :put, id: "map-form" do |f| %> <%= form_tag admin_update_map_path, method: :put, id: "map-form" do |f| %>
<%= hidden_field_tag :latitude, Setting["map_latitude"] %> <%= hidden_field_tag :latitude, Setting["map.latitude"] %>
<%= hidden_field_tag :longitude, Setting["map_longitude"] %> <%= hidden_field_tag :longitude, Setting["map.longitude"] %>
<%= hidden_field_tag :zoom, Setting["map_zoom"] %> <%= hidden_field_tag :zoom, Setting["map.zoom"] %>
<div class="small-12 medium-6 large-4 margin-top"> <div class="small-12 medium-6 large-4 margin-top">
<%= submit_tag t("admin.settings.index.map.form.submit"), <%= submit_tag t("admin.settings.index.map.form.submit"),

View File

@@ -1188,6 +1188,7 @@ en:
update: Map configuration updated succesfully. update: Map configuration updated succesfully.
form: form:
submit: Update 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: Feature
setting_actions: Actions setting_actions: Actions
setting_name: Setting setting_name: Setting

View File

@@ -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" 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: "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" 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: "Sender email name"
mailer_from_name_description: "This name will appear as sender name in emails sent from the application" mailer_from_name_description: "This name will appear as sender name in emails sent from the application"
mailer_from_address: "Sender email address" mailer_from_address: "Sender email address"
@@ -124,3 +118,10 @@ en:
public_stats_description: "Display public stats in the Administration panel" public_stats_description: "Display public stats in the Administration panel"
help_page: "Help page" 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' 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"

View File

@@ -1187,6 +1187,7 @@ es:
update: La configuración del mapa se ha guardado correctamente. update: La configuración del mapa se ha guardado correctamente.
form: form:
submit: Actualizar 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: Funcionalidad
setting_actions: Acciones setting_actions: Acciones
setting_name: Configuración setting_name: Configuración

View File

@@ -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" 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: "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" 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: "Nombre email remitente"
mailer_from_name_description: "Este nombre aparecerá como nombre del remitente en los emails enviados desde la aplicación" 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" 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" public_stats_description: "Muestra las estadísticas públicas en el panel de Administración"
help_page: "Página de ayuda" 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"' 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"

View File

@@ -151,9 +151,9 @@ end
section "Geolocating Investments" do section "Geolocating Investments" do
Budget.find_each do |budget| Budget.find_each do |budget|
budget.investments.each do |investment| budget.investments.each do |investment|
MapLocation.create(latitude: Setting["map_latitude"].to_f + rand(-10..10)/100.to_f, 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, longitude: Setting["map.longitude"].to_f + rand(-10..10)/100.to_f,
zoom: Setting["map_zoom"], zoom: Setting["map.zoom"],
investment_id: investment.id) investment_id: investment.id)
end end
end end

View File

@@ -59,9 +59,9 @@ section "Creating Settings" do
"transparent and democratic government") "transparent and democratic government")
Setting.create(key: "meta_keywords", value: "citizen participation, open government") Setting.create(key: "meta_keywords", value: "citizen participation, open government")
Setting.create(key: "min_age_to_participate", value: "16") Setting.create(key: "min_age_to_participate", value: "16")
Setting.create(key: "map_latitude", value: 40.41) Setting.create(key: "map.latitude", value: 40.4332002)
Setting.create(key: "map_longitude", value: -3.7) Setting.create(key: "map.longitude", value: -3.7009591)
Setting.create(key: "map_zoom", value: 10) Setting.create(key: "map.zoom", value: 10)
Setting.create(key: "featured_proposals_number", value: 3) Setting.create(key: "featured_proposals_number", value: 3)
Setting.create(key: "proposal_notification_minimum_interval_in_days", value: 0) Setting.create(key: "proposal_notification_minimum_interval_in_days", value: 0)
Setting.create(key: "direct_message_max_per_day", value: 3) Setting.create(key: "direct_message_max_per_day", value: 3)

View File

@@ -106,9 +106,9 @@ Setting["min_age_to_participate"] = 16
Setting["featured_proposals_number"] = 3 Setting["featured_proposals_number"] = 3
# City map feature default configuration (Greenwich) # City map feature default configuration (Greenwich)
Setting["map_latitude"] = 51.48 Setting["map.latitude"] = 51.48
Setting["map_longitude"] = 0.0 Setting["map.longitude"] = 0.0
Setting["map_zoom"] = 10 Setting["map.zoom"] = 10
# Related content # Related content
Setting["related_content_score_threshold"] = -0.3 Setting["related_content_score_threshold"] = -0.3

View File

@@ -37,6 +37,9 @@ feature "Admin settings" do
visit admin_settings_path visit admin_settings_path
find("#map-tab").click 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") expect(page).not_to have_css("#admin-map")
end end
@@ -48,6 +51,9 @@ feature "Admin settings" do
find("#map-tab").click find("#map-tab").click
expect(page).to have_css("#admin-map") 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 end
scenario "Should show successful notice" do scenario "Should show successful notice" do