diff --git a/app/cells/decidim/geo/content_blocks/geo_maps_cell.rb b/app/cells/decidim/geo/content_blocks/geo_maps_cell.rb index 9ec0142..54d0b86 100644 --- a/app/cells/decidim/geo/content_blocks/geo_maps_cell.rb +++ b/app/cells/decidim/geo/content_blocks/geo_maps_cell.rb @@ -48,12 +48,7 @@ def insert_map not_geolocated: ActionController::Base.helpers.asset_pack_path("media/images/not-geolocated.svg") }, filters: (@options[:filters] || []).concat([{ timeFilter: { time: "active" } }]), - map_config: { - lat: geo_config[:latitude], - lng: geo_config[:longitude], - tile_layer: geo_config[:tile], - zoom: geo_config[:zoom], - }, + map_config: map_config, active_manifests: ::Decidim::Geo.registry.active_manifests(&:keys), is_index: index? }.with_indifferent_access @@ -149,17 +144,18 @@ def current_component? current_component.present? end - def geo_config + def map_config { - latitude: model.try(:latitude).nil? ? geo_config_default.latitude : model.latitude, - longitude: model.try(:longitude).nil? ? geo_config_default.longitude : model.longitude, - tile: Decidim::Geo::GeoConfig.geo_config_default.tile, - zoom: Decidim::Geo::GeoConfig.geo_config_default.zoom, + lat: model.try(:latitude).nil? ? config.latitude : model.latitude, + lng: model.try(:longitude).nil? ? config.longitude : model.longitude, + tile_layer: config.tile, + zoom: config.zoom, + force_geo_filter: config.default_geoencoded_filter }.to_h end - def geo_config_default - Decidim::Geo::GeoConfig.geo_config_default + def config + @config ||= Decidim::Geo::GeoConfig.geo_config_default end end end diff --git a/app/commands/decidim/geo/admin/update_geo_config.rb b/app/commands/decidim/geo/admin/update_geo_config.rb index 807a6c0..8861f95 100644 --- a/app/commands/decidim/geo/admin/update_geo_config.rb +++ b/app/commands/decidim/geo/admin/update_geo_config.rb @@ -46,7 +46,8 @@ def attributes zoom: form.zoom, tile: form.tile, only_assemblies: form.only_assemblies, - only_processes: form.only_processes + only_processes: form.only_processes, + default_geoencoded_filter: form.default_geoencoded_filter } end end diff --git a/app/forms/decidim/geo/admin/geo_config_form.rb b/app/forms/decidim/geo/admin/geo_config_form.rb index c9cce02..bc9d431 100644 --- a/app/forms/decidim/geo/admin/geo_config_form.rb +++ b/app/forms/decidim/geo/admin/geo_config_form.rb @@ -11,7 +11,8 @@ class GeoConfigForm < Form attribute :tile, String attribute :only_assemblies, Boolean attribute :only_processes, Boolean - + attribute :default_geoencoded_filter, Integer + alias organization current_organization end end diff --git a/app/models/decidim/geo/geo_config.rb b/app/models/decidim/geo/geo_config.rb index c976a4a..992e46a 100644 --- a/app/models/decidim/geo/geo_config.rb +++ b/app/models/decidim/geo/geo_config.rb @@ -5,7 +5,7 @@ module Geo # The data store for geo configuration default. class GeoConfig < ApplicationRecord self.table_name = "decidim_geo_configs" - + enum default_geoencoded_filter: { force_geoencoded: 0, no_force_geoencoded: 1 } validates :longitude, :latitude, :zoom, presence: true def self.geo_config_default @@ -13,7 +13,8 @@ def self.geo_config_default .first_or_create(latitude: 0, longitude: 0, zoom: 13, - tile: tile_layer_default) + tile: tile_layer_default, + default_geoencoded_filter: 1) end def self.tile_layer_default diff --git a/app/packs/src/decidim/geo/ui/FilterModal.js b/app/packs/src/decidim/geo/ui/FilterModal.js index da57501..6663a50 100644 --- a/app/packs/src/decidim/geo/ui/FilterModal.js +++ b/app/packs/src/decidim/geo/ui/FilterModal.js @@ -156,6 +156,8 @@ class FilterModal { ); } geoFields(points) { + const {map_config: mapConfig} = this.config(); + if(mapConfig?.force_geo_filter === "force_geoencoded") return; const i18n = this.i18n(); const i18nPrefix = "decidim_geo.filters"; diff --git a/app/views/decidim/geo/admin/geo_configs/_form.html.erb b/app/views/decidim/geo/admin/geo_configs/_form.html.erb index 7261e93..0a04dcf 100644 --- a/app/views/decidim/geo/admin/geo_configs/_form.html.erb +++ b/app/views/decidim/geo/admin/geo_configs/_form.html.erb @@ -44,4 +44,21 @@ +
<%= t("help_text", scope: "decidim.geo.admin.geo_configs.default_filter") %>
+