Skip to content

Commit

Permalink
Release/v0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadrien Froger committed Sep 11, 2024
1 parent 9e7472f commit 8e29648
Show file tree
Hide file tree
Showing 42 changed files with 1,756 additions and 842 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center"><img src="https://github.com/octree-gva/meta/blob/main/decidim/static/header.png?raw=true" alt="Decidim - Octree Participatory democracy on a robust and open source solution" /></h1>
<h1 align="center"><img src="https://github.com/octree-gva/decidim-geo/blob/main/parners.png?raw=true" alt="Decidim - Octree Participatory democracy on a robust and open source solution" /></h1>
<h4 align="center">
<a href="https://octreegva.notion.site/Roadmap-Decidim-GEO-f191fcb9e220401f8135514a7bd41aab">Roadmap</a> |
<a href="https://drive.google.com/file/d/1lfQJumDg0Ic-RZi-R3MM8frYtKN7PB_S/view?usp=sharing">Presentation</a> |
Expand Down
8 changes: 5 additions & 3 deletions app/cells/decidim/geo/content_blocks/geo_maps_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def insert_map
images: {
not_geolocated: ActionController::Base.helpers.asset_pack_path("media/images/not-geolocated.svg")
},
filters: @options[:filters] || [],
filters: (@options[:filters] || []).concat([{ timeFilter: { time: "active" } }]),
map_config: {
lat: geo_config[:latitude],
lng: geo_config[:longitude],
Expand Down Expand Up @@ -99,8 +99,10 @@ def geo_i18n
"decidim_geo.filters.type.only_assemblies": t("decidim.geo.filters.type.only_assemblies"),
"decidim_geo.filters.type.only_proposals": t("decidim.geo.filters.type.only_proposals"),
"decidim_geo.filters.type.only_meetings": t("decidim.geo.filters.type.only_meetings"),
"decidim_geo.filters.type.only_debates": t("decidim.geo.filters.type.only_debates")

"decidim_geo.filters.type.only_debates": t("decidim.geo.filters.type.only_debates"),
"decidim_geo.filters.empty_message": t("decidim.geo.filters.empty.message"),
"decidim_geo.filters.empty_reset_button": t("decidim.geo.filters.empty.reset_button"),
"decidim_geo.actions.view": t("decidim.geo.actions.view")
}
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/decidim/debates/debate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Debate < Debates::ApplicationRecord
include Decidim::Endorsable
include Decidim::Randomable

if Decidim.version == "0.27.4"
if Decidim.version >= "0.27.4"
include Decidim::DownloadYourData
include Decidim::FilterableResource
end
Expand Down Expand Up @@ -59,7 +59,7 @@ class Debate < Debates::ApplicationRecord
)
}

scope_search_multi :with_any_state, [:open, :closed] if Decidim.version == "0.27.4"
scope_search_multi :with_any_state, [:open, :closed] if Decidim.version >= "0.27.4"

def self.log_presenter_class_for(_log)
Decidim::Debates::AdminLog::DebatePresenter
Expand Down
37 changes: 18 additions & 19 deletions app/packs/src/decidim/geo/api/getFirstGeoDataSource.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import {_getGeoDataSource, _getGeoDataSourceIds} from "./queries";
import { _getGeoDataSource, _getGeoDataSourceIds } from "./queries";

export const getFirstGeoDataSource = async (params = {}, fetchAll = true) => {
if (!params.variables) {
params.variables = {};
}
const apiQuery = fetchAll ? _getGeoDataSource : _getGeoDataSourceIds;
let page;
try {
page = await apiQuery(params);
} catch (error) {
console.error(error);
throw error;
}
if (!page) return { nodes: [], hasMore: false, endCursor: "" };
const { hasNextPage = false, endCursor = "" } = page?.pageInfo || {};
return { nodes: page.nodes, hasMore: hasNextPage, after: endCursor };
};
export const getFirstGeoDataSource = async (params = {}, fetchComplete = true) => {
if (!params.variables) {
params.variables = {};
}
const apiQuery = fetchComplete ? _getGeoDataSource : _getGeoDataSourceIds;
let page;
try {
page = await apiQuery(params);
} catch (error) {
console.error(error);
throw error;
}
if (!page) return { nodes: [], hasMore: false, endCursor: "" };
const { hasNextPage = false, endCursor = "" } = page?.pageInfo || {};
return { nodes: page.nodes, hasMore: hasNextPage, after: endCursor };
};


export default getFirstGeoDataSource;
export default getFirstGeoDataSource;
4 changes: 2 additions & 2 deletions app/packs/src/decidim/geo/api/getGeoDataSource.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {_getGeoDataSource, _getGeoDataSourceIds} from "./queries";
import { _getGeoDataSource, _getGeoDataSourceIds } from "./queries";

const getGeoDataSource = async (params = {}, fetchAll = true) => {
let results = [];
Expand Down Expand Up @@ -33,4 +33,4 @@ const getGeoDataSource = async (params = {}, fetchAll = true) => {

return { nodes: results };
};
export default getGeoDataSource;
export default getGeoDataSource;
4 changes: 2 additions & 2 deletions app/packs/src/decidim/geo/api/gql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const geoDatasource = `
query geoDatasourceQuery ($defaultLocale: String!, $locale: String!, $filters: [GeoDatasourceFilter!], $after: String) {
geoDatasource(filters: $filters, locale: $locale, after: $after, first: 500){
geoDatasource(filters: $filters, locale: $locale, after: $after, first: 50){
pageInfo {
hasPreviousPage
startCursor
Expand Down Expand Up @@ -45,7 +45,7 @@ export const geoDatasource = `
}`;
export const geoDatasourceIds = `
query geoDatasourceQueryIds ($locale: String!, $filters: [GeoDatasourceFilter!], $after: String) {
geoDatasource(filters: $filters, locale: $locale, after: $after){
geoDatasource(filters: $filters, locale: $locale, after: $after, first: 50){
pageInfo {
hasPreviousPage
startCursor
Expand Down
8 changes: 3 additions & 5 deletions app/packs/src/decidim/geo/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export { default as getGeoDataSource } from "./getGeoDataSource";
export { default as getFirstGeoDataSource } from "./getFirstGeoDataSource";

export {default as getGeoDataSource, } from './getGeoDataSource'
export {default as getFirstGeoDataSource, } from './getFirstGeoDataSource'


export {getGeoConfig, getGeoScopes} from './queries'
export { getGeoConfig, getGeoScopes } from "./queries";
2 changes: 1 addition & 1 deletion app/packs/src/decidim/geo/api/makeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ const makeQuery =
return response.data[_responseKey];
};

export default makeQuery
export default makeQuery;
2 changes: 1 addition & 1 deletion app/packs/src/decidim/geo/api/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export const _getGeoDataSource = makeQuery("geoDatasource");
export const _getGeoDataSourceIds = makeQuery("geoDatasourceIds", "geoDatasource");

export const getGeoConfig = makeQuery("geoConfig");
export const getGeoScopes = makeQuery("geoScope");
export const getGeoScopes = makeQuery("geoScope");
1 change: 1 addition & 0 deletions app/packs/src/decidim/geo/models/GeoDatasourceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class GeoDatasourceNode {
pinPoint == `${this.data.id}`
) {
this.marker.setStyle(this.selectedState);
this.marker.bringToFront();
} else {
this.marker.setStyle(this.staledState);
}
Expand Down
4 changes: 2 additions & 2 deletions app/packs/src/decidim/geo/models/GeoScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class GeoScope {
}

isEmpty() {
if(this.data.geom === null) return true
if (this.data.geom === null) return true;
const { points } = pointStore.getState();
const currentScopeId = this.id;
return !points.find(({ scopeId }) => `${scopeId}` === `${currentScopeId}`);
Expand Down Expand Up @@ -90,7 +90,7 @@ export default class GeoScope {
);
}
scopeClickHandler() {
this.select("layer")
this.select("layer");
}
init() {
const { map } = configStore.getState();
Expand Down
1 change: 1 addition & 0 deletions app/packs/src/decidim/geo/stores/dropdownFilterStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const store = createStore(
setFilter(name, value) {
set((state) => ({
selectedFilters: {
...state.defaultFilters,
...state.selectedFilters,
[`${name}`]: value || state.defaultFilters[`${name}`]
}
Expand Down
4 changes: 3 additions & 1 deletion app/packs/src/decidim/geo/stores/filterStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const store = createStore(
const activeFilters = _.sortBy(filters, [sortingIteratee]);
set((state) => {
if (_.isEqual(state.activeFilters, activeFilters)) return {};
return { activeFilters: activeFilters };
return { activeFilters };
});
},
resetFilters: () => {
Expand Down Expand Up @@ -84,11 +84,13 @@ const store = createStore(
const timeFilterMatch = filters.find(
({ timeFilter = undefined }) => timeFilter
);

if (!timeFilterMatch) return defaultFilters.GeoTimeFilter;
const timeFilter = timeFilterMatch.timeFilter.time;
if (timeFilter === "past") return "only_past";
if (timeFilter === "active") return "only_active";
if (timeFilter === "future") return "only_future";
if (timeFilter === "all") return "all";
return defaultFilters.GeoTimeFilter;
case "GeoType":
const typeFilterMatch = filters.find(
Expand Down
18 changes: 12 additions & 6 deletions app/packs/src/decidim/geo/stores/pointStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const store = createStore(
_lastFilter: "",
_lastResponse: [],
scopeForId: (scopeId) => {
const scope = get().scopes.find(({ data }) => `${data.id}` === `${scopeId}`);
if(!scope || scope.isEmpty()) return null;
const scope = get().scopes.find(({ data }) => `${data.id}` === `${scopeId}`);
if (!scope || scope.isEmpty()) return null;
return scope;
},
clearCache: () => {
Expand All @@ -44,16 +44,19 @@ const store = createStore(
fetchAll: async (filters = []) => {
const { points: fetchedPoints } = store.getState();
if (fetchedPoints.length > 0) return;

const locale = configStore.getState().locale;
const defaultLocale = configStore.getState().defaultLocale;
set(({ isLoading }) => ({ isLoading: isLoading + 1 }));
const filterWithoutTime = filters.filter(
(f) => typeof f.timeFilter === "undefined"
);
const firstData = await getFirstGeoDataSource(
{
variables: { filters, locale, defaultLocale }
variables: { filters: filterWithoutTime, locale, defaultLocale }
},
true
);

set(() => ({ points: firstData.nodes.map(mapNodeToPoint).filter(Boolean) }));

const scopes = await getGeoScopes({
Expand All @@ -77,7 +80,11 @@ const store = createStore(
if (firstData.hasMore) {
const data = await getGeoDataSource(
{
variables: { filters: filters, locale: locale, after: firstData.after }
variables: {
filters: filterWithoutTime,
locale: locale,
after: firstData.after
}
},
true
);
Expand Down Expand Up @@ -122,7 +129,6 @@ const store = createStore(
_lastResponse: filteredPoints,
isLoading: isLoading - 1
}));
console.log(ids.nodes.length, "LAST RESPONSE", filteredPoints)
return filteredPoints;
}
}))
Expand Down
Loading

0 comments on commit 8e29648

Please sign in to comment.