diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 9c04380920a..6f47714653b 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -21,7 +21,7 @@ def update_map 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") + redirect_to request.referer, notice: t("admin.settings.index.map.flash.update") end def update_content_types diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index eeab8681a03..7bbc6cd7b90 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -53,8 +53,9 @@ def prepare_map_settings(map_location, editable, parent_class, investments_coord map_center_latitude: map_location_latitude(map_location), map_center_longitude: map_location_longitude(map_location), map_zoom: map_location_zoom(map_location), - map_tiles_provider: Rails.application.secrets.map_tiles_provider, - map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution, + map_tiles_provider: Retrocompatibility.calculate_value("map.tiles_provider", "map_tiles_provider"), + map_tiles_provider_attribution: Retrocompatibility.calculate_value("map.tiles_provider_attribution", + "map_tiles_provider_attribution"), marker_editable: editable, marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", diff --git a/app/models/setting.rb b/app/models/setting.rb index a562c35114f..6e41df06866 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -115,6 +115,8 @@ def defaults "map.latitude": 51.48, "map.longitude": 0.0, "map.zoom": 10, + "map.tiles_provider": nil, + "map.tiles_provider_attribution": nil, "process.debates": true, "process.proposals": true, "process.polls": true, diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb index 49d2496f22f..7208b7e7c5c 100644 --- a/app/views/admin/settings/_map_form.html.erb +++ b/app/views/admin/settings/_map_form.html.erb @@ -5,8 +5,9 @@ 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-map-tiles-provider="<%= Retrocompatibility.calculate_value("map.tiles_provider", "map_tiles_provider") %>" + data-map-tiles-provider-attribution="<%= Retrocompatibility.calculate_value("map.tiles_provider_attribution", + "map_tiles_provider_attribution") %>" data-marker-editable="true" data-marker-latitude="<%= Setting["map.latitude"] %>" data-marker-longitude="<%= Setting["map.longitude"] %>" diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index 0927665f97f..ba4a5da7516 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -157,6 +157,10 @@ en: longitude_description: "Longitude to show the position of the map" zoom: "Zoom" zoom_description: "Zoom to show the map position" + tiles_provider: "TMS(Tile Map Service) Provider" + tiles_provider_description: "Example value: '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'" + tiles_provider_attribution: "Attribution from TMS Provider" + tiles_provider_attribution_description: "Example value: '© OpenStreetMap contributors'" process: debates: "Debates" debates_description: "The citizens' debate space is aimed at anyone who can present issues that concern them and about which they want to share their views with others" diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index 7378863762d..f42e5576a7e 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -157,6 +157,10 @@ es: longitude_description: "Longitud para mostrar la posición del mapa" zoom: "Zoom" zoom_description: "Zoom para mostrar la posición del mapa" + tiles_provider: "Proveedor de las especificaciones cartográficas - TMS(Tile Map Service)" + tiles_provider_description: "Valor de Ejemplo: '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'" + tiles_provider_attribution: "Atribución al Proveedor de las especificaciones cartográficas - TMS(Tile Map Service)" + tiles_provider_attribution_description: "Valor de ejemplo: '© OpenStreetMap contributors'" process: debates: "Debates" debates_description: "El espacio de debates ciudadanos está dirigido a que cualquier persona pueda exponer temas que le preocupan y sobre los que quiera compartir puntos de vista con otras personas" diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index 94d9731eb9f..775b7d8ec0e 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -96,6 +96,11 @@ expect(page).to have_content "Map configuration" expect(page).to have_css("#edit_setting_#{setting.id}") + expect(page).to have_content "Latitude" + expect(page).to have_content "Longitude" + expect(page).to have_content "Zoom" + expect(page).to have_content "TMS(Tile Map Service) Provider" + expect(page).to have_content "Attribution from TMS Provider" end scenario "Should display uploads settings section" do @@ -197,9 +202,6 @@ end expect(page).to have_content "Map configuration updated succesfully" - within "#map-section" do - click_link "Configure" - end expect(find("#latitude", visible: false).value).not_to eq "51.48" end diff --git a/spec/helpers/map_locations_helper_spec.rb b/spec/helpers/map_locations_helper_spec.rb new file mode 100644 index 00000000000..1070b7045ff --- /dev/null +++ b/spec/helpers/map_locations_helper_spec.rb @@ -0,0 +1,25 @@ +require "rails_helper" + +describe MapLocationsHelper do + + describe "#prepare_map_settings" do + + it "returns tiles provider values from Secrets when related settings do not exists" do + options = prepare_map_settings(MapLocation.new, false, "budgets", nil) + + expect(options[:map_tiles_provider]).to eq "//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" + expect(options[:map_tiles_provider_attribution]).to eq "© OpenStreetMap contributors" + end + + it "returns tiles provider values from Settings when related settings are definded" do + Setting["map.tiles_provider"] = "example_map_tiles_provider" + Setting["map.tiles_provider_attribution"] = "example_map_tiles_provider_attribution" + options = prepare_map_settings(MapLocation.new, false, "budgets", nil) + + expect(options[:map_tiles_provider]).to eq "example_map_tiles_provider" + expect(options[:map_tiles_provider_attribution]).to eq "example_map_tiles_provider_attribution" + end + + end + +end