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 }
@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

View File

@@ -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)

View File

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

View File

@@ -2,14 +2,14 @@
<div class="small-12 column">
<div id="admin-map" class="map"
data-map
data-map-center-latitude="<%= Setting["map_latitude"] %>"
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"] %>
<div class="small-12 medium-6 large-4 margin-top">
<%= submit_tag t("admin.settings.index.map.form.submit"),