Skip to content

Commit

Permalink
Merge branch 'fix/process_groups_hide_scope' into 'main'
Browse files Browse the repository at this point in the history
refact: add is_group param to make things simpler

See merge request decidim/decidim-module-geo!171
  • Loading branch information
Hadrien Froger committed Dec 11, 2024
2 parents fc5e999 + d4f361e commit 67d8150
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 18 deletions.
9 changes: 7 additions & 2 deletions app/cells/decidim/geo/content_blocks/geo_maps_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def data_count
@data_count ||= ::Decidim::Geo::Api::GeoQuery.new(
current_organization,
current_user,
{ filters: filters, is_index: index? },
{ filters: filters, is_index: index?, is_group: group? },
current_locale
).results_count
end
Expand All @@ -50,7 +50,8 @@ def insert_map
filters: (@options[:filters] || []).concat([{ timeFilter: { time: "active" } }]),
map_config: map_config,
active_manifests: ::Decidim::Geo.registry.active_manifests(&:keys),
is_index: index?
is_index: index?,
is_group: @options[:is_group] || false,
}.with_indifferent_access

content_tag(
Expand All @@ -71,6 +72,10 @@ def index?
@options.has_key?(:is_index) ? @options[:is_index] : true
end

def group?
@options.has_key?(:is_group) ? @options[:is_group] : false
end

def insert_scopes_mobile
content_tag(:div, "", class: ["js-decidimgeo"])
end
Expand Down
13 changes: 9 additions & 4 deletions app/controllers/decidim/geo/points_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def index
private

def permitted_params
@permitted_params ||= params.permit(:first, :after, :locale, :is_index, :format, fields: [], filters: [])
@permitted_params ||= params.permit(:first, :after, :locale, :is_index, :is_group, :format, fields: [], filters: [])
end

def first_params
Expand All @@ -61,14 +61,19 @@ def query
current_user,
{
filters: filters_params,
is_index: index_params?
is_index: index?,
is_group: group?
},
locale_param
).results
end

def index_params?
@index_params ||= permitted_params[:is_index] || false
def index?
@index ||= permitted_params[:is_index] || false
end

def group?
@group ||= permitted_params[:is_group] || false
end

def locale_param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
id: "ProcessGroup",
filters: @group.participatory_processes.map {|process| { processFilter: { id: process.id } } },
scopes: @group.participatory_processes.scope.map{|s| s.id},
is_index: true
is_index: true,
is_group: true
) %>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ iter_children(current_participatory_space, assemblies) unless current_participat
id: "Assembly",
hide_empty: true,
is_index: false,
is_group: false,
filters: if current_participatory_space.scope.present?
[
{ scopeFilter: { scopeId: current_participatory_space.scope.id } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
id: "Process",
hide_empty: true,
is_index: false,
is_group: false,
filters: if current_participatory_space.scope.present?
# If the process has a scope, filter by its scope
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"decidim/geo/geo_collection_map",
id: "Indexes",
hide_empty: true,
is_index: false
is_index: true,
is_group: false
) %>
5 changes: 4 additions & 1 deletion app/packs/src/decidim/geo/api/countGeoDataSource.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _getGeoDataSource, _getGeoDataSourceIds } from "./queries";

const countGeoDataSource = async (params = {}, callback = undefined) => {
const { filters = [], locale, isIndex = false, after = 0, first = 50 } = params;
const { filters = [], locale, isIndex = false, isGroup=false, after = 0, first = 50 } = params;
const fields = [];

const searchParams = new URLSearchParams({
Expand All @@ -12,6 +12,9 @@ const countGeoDataSource = async (params = {}, callback = undefined) => {
if(isIndex){
searchParams.append("is_index", "true")
}
if(isGroup){
searchParams.append("is_group", "true")
}
filters.forEach((f) => {
searchParams.append("filters[]", JSON.stringify(f));
});
Expand Down
5 changes: 4 additions & 1 deletion app/packs/src/decidim/geo/api/getGeoDataSource.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _getGeoDataSource, _getGeoDataSourceIds } from "./queries";

const getGeoDataSource = async (params = {}, fetchAll = true, callback) => {
const { filters = [], locale, isIndex = false, after = 0, first = 50 } = params;
const { filters = [], locale, isIndex = false, isGroup=false, after = 0, first = 50 } = params;
const fields = fetchAll
? [
"resourceUrl",
Expand Down Expand Up @@ -33,6 +33,9 @@ const getGeoDataSource = async (params = {}, fetchAll = true, callback) => {
if(isIndex){
searchParams.append("is_index", "true")
}
if(isGroup){
searchParams.append("is_group", "true")
}
filters.forEach((f) => {
searchParams.append("filters[]", JSON.stringify(f));
});
Expand Down
1 change: 1 addition & 0 deletions app/packs/src/decidim/geo/stores/configStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const store = createStore(
i18n: mapConfig.i18n,
images: mapConfig.images || {},
isIndex: mapConfig.is_index === "true" || mapConfig.is_index === true,
isGroup: mapConfig.is_group === "true" || mapConfig.is_group === true,
activeManifests: mapConfig.active_manifests
}));

Expand Down
4 changes: 2 additions & 2 deletions app/packs/src/decidim/geo/stores/pointCounterStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const store = createStore(
isLoading: false,

async fetchCount(filters) {
const { locale, isIndex } = configStore.getState();
const { locale, isIndex, isGroup } = configStore.getState();
set(() => ({ isLoading: true }));
const count = await countGeoDataSource({ filters, locale: locale, isIndex });
const count = await countGeoDataSource({ filters, locale: locale, isIndex, isGroup});
set(() => ({ isLoading: false }));
return count;
},
Expand Down
8 changes: 4 additions & 4 deletions app/packs/src/decidim/geo/stores/pointStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ const store = createStore(
const { points: fetchedPoints } = store.getState();
if (fetchedPoints.length > 0) return;

const { locale, isIndex } = configStore.getState();
const { locale, isIndex, isGroup} = configStore.getState();

const promises = [];
const filterWithoutTime = filters.filter(
(f) => typeof f.timeFilter === "undefined"
);
set(({ fetchesRunning }) => ({ fetchesRunning: fetchesRunning + 1 }));
await getGeoDataSource(
{ filters: filterWithoutTime, locale, isIndex },
{ filters: filterWithoutTime, locale, isIndex, isGroup },
true,
(data, hasMore, meta) => {
const points = data.map(mapNodeToPoint).filter(Boolean);
Expand Down Expand Up @@ -140,7 +140,7 @@ const store = createStore(
},

pointsForFilters: async (filters = [], forceRefresh = false) => {
const { locale, isIndex } = configStore.getState();
const { locale, isIndex, isGroup } = configStore.getState();
const { _lastFilter: lastFilter, _lastResponse: lastResponse } = store.getState();
const cacheKey = JSON.stringify(filters);
// cache
Expand All @@ -153,7 +153,7 @@ const store = createStore(
}));
filteredIdsStore.setState(() => ({ activeFilterIds: [] }));

await getGeoDataSource({ filters, locale: locale, isIndex }, false, (data, hasMore) => {
await getGeoDataSource({ filters, locale: locale, isIndex, isGroup }, false, (data, hasMore) => {
filteredIdsStore.setState(({ activeFilterIds }) => ({
activeFilterIds: activeFilterIds.concat(data || [])
}));
Expand Down
3 changes: 1 addition & 2 deletions lib/decidim/geo/filters/geo_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def results

def indexed_query(query)
return query.indexed unless process_groups?

query.indexed.or(query.where(
participatory_space_id: process_params,
avoid_index: true
Expand Down Expand Up @@ -119,7 +118,7 @@ def only_indexed?
end

def process_groups?
process_params.size > 1
params.has_key?(:is_group) && params[:is_group]
end

def assembly_groups?
Expand Down

0 comments on commit 67d8150

Please sign in to comment.