Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ciudades abiertas/map configuration section #45

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/map_locations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")}",
Expand Down
2 changes: 2 additions & 0 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions app/views/admin/settings/_map_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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"] %>"
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '&copy; <a href=\"http://osm.org/copyright\">OpenStreetMap</a> 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"
Expand Down
4 changes: 4 additions & 0 deletions config/locales/es/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '&copy; <a href=\"http://osm.org/copyright\">OpenStreetMap</a> 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"
Expand Down
8 changes: 5 additions & 3 deletions spec/features/admin/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions spec/helpers/map_locations_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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 "&copy; <a href=\"http://osm.org/copyright\">OpenStreetMap</a> 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