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("title", scope: "decidim.geo.admin.geo_configs.default_filter") %> +

+
+
+
+

<%= t("help_text", scope: "decidim.geo.admin.geo_configs.default_filter") %>

+
+
+
+ <%= form.select :default_geoencoded_filter, options_for_select(Decidim::Geo::GeoConfig::default_geoencoded_filters.map do |key, value| + [t(key, scope: "decidim.geo.admin.geo_configs.default_filter.geoencoded_filter.fields"), value] + end, form.object.default_geoencoded_filter), label: t("label", scope: "decidim.geo.admin.geo_configs.default_filter.geoencoded_filter") %> +
+
+
\ No newline at end of file diff --git a/config/locales/decidim-geo.en.yml b/config/locales/decidim-geo.en.yml index 0c9d3b6..d698de3 100644 --- a/config/locales/decidim-geo.en.yml +++ b/config/locales/decidim-geo.en.yml @@ -40,9 +40,20 @@ en: admin: geo_configs: map_config_title: Map Configurations - spaces_config_title: Participatory Spaces Configurations + spaces_config_title: Configurations for Participatory Spaces only_assemblies: Display only assemblies in Assemblies only_processes: Display only processes in Processes + + default_filter: + title: Available points + help_text: | + Configure the available points for Decidim Geo. This configuration applies to all the platform. + geoencoded_filter: + label: Filter points by location + fields: + force_geoencoded: "Only points in the map" + no_force_geoencoded: "All points" + default_geoencoded_filter: Filter index: title: Configurations save: Save diff --git a/db/migrate/20241014122841_add_geo_config_default_filters.rb b/db/migrate/20241014122841_add_geo_config_default_filters.rb new file mode 100644 index 0000000..0489e66 --- /dev/null +++ b/db/migrate/20241014122841_add_geo_config_default_filters.rb @@ -0,0 +1,5 @@ +class AddGeoConfigDefaultFilters < ActiveRecord::Migration[6.1] + def change + add_column :decidim_geo_configs, :default_geoencoded_filter, :integer, default: 0 + end +end diff --git a/lib/decidim/geo/filters/geo_query.rb b/lib/decidim/geo/filters/geo_query.rb index a42c391..4a5e799 100644 --- a/lib/decidim/geo/filters/geo_query.rb +++ b/lib/decidim/geo/filters/geo_query.rb @@ -16,10 +16,10 @@ def initialize(organization, current_user, params, locale) def results query = Decidim::Geo::Index.all + query = query.geolocated if geolocated? || config.force_geoencoded? return query.indexed if graphql_params.empty? query = query.indexed if only_indexed? - query = query.geolocated if geolocated? query = query.virtual if virtual? # Filter on scopes unless scope_ids_params.empty? @@ -83,6 +83,10 @@ def results private + def config + @config ||= Decidim::Geo::GeoConfig.geo_config_default + end + def active_manifests_names @active_manifests_names ||= ::Decidim::Geo.registry.active_manifests(&:keys) end