From e2fc40592f810796870708498588a2da3280e50f Mon Sep 17 00:00:00 2001 From: Guillaume MORET <90462045+AyakorK@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:42:31 +0100 Subject: [PATCH 1/2] fix: Remove caching from the geocoding elements to avoid map not reloading when refreshing (#638) --- .../proposals/proposals/index.html.erb | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/app/views/decidim/proposals/proposals/index.html.erb b/app/views/decidim/proposals/proposals/index.html.erb index 5bcaade268..d6ab9a56ed 100644 --- a/app/views/decidim/proposals/proposals/index.html.erb +++ b/app/views/decidim/proposals/proposals/index.html.erb @@ -1,30 +1,28 @@ <%= render partial: "decidim/shared/component_announcement" %> <% if component_settings.geocoding_enabled? %> - <% cache @all_geocoded_proposals do %> - <%= dynamic_map_for proposals_data_for_map(@all_geocoded_proposals) do %> - <% end %> <% end %> <%= render partial: "voting_rules" %> From cfe65a9f0e08842c22a1f82d94e1a260a09a8d99 Mon Sep 17 00:00:00 2001 From: Guillaume MORET <90462045+AyakorK@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:57:13 +0100 Subject: [PATCH 2/2] backport: Reorder scopes in meetings (#639) --- config/application.rb | 1 + config/locales/en.yml | 3 ++ config/locales/fr.yml | 3 ++ .../directory/application_helper_extends.rb | 39 ++++++++++++++ .../directory/application_helper_spec.rb | 53 +++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 lib/extends/helpers/decidim/meetings/directory/application_helper_extends.rb create mode 100644 spec/helpers/decidim/meetings/directory/application_helper_spec.rb diff --git a/config/application.rb b/config/application.rb index 1e45491268..26a54c15b8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -61,6 +61,7 @@ class Application < Rails::Application # Services require "extends/services/decidim/iframe_disabler_extends" # Helpers + require "extends/helpers/decidim/meetings/directory/application_helper_extends" require "extends/helpers/decidim/icon_helper_extends" require "extends/helpers/decidim/check_boxes_tree_helper_extends" # Forms diff --git a/config/locales/en.yml b/config/locales/en.yml index 89f03de8b5..6eaf94bee8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -145,6 +145,9 @@ en: see_all_initiatives: See all initiatives unavailable_scope: Unavailable scope meetings: + application_helper: + filter_scope_values: + all: All directory: meetings: index: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3bd7493ba8..d25c7083c1 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -147,6 +147,9 @@ fr: see_all_initiatives: Voir toutes les pétitions unavailable_scope: Portée indisponible meetings: + application_helper: + filter_scope_values: + all: Tous directory: meetings: index: diff --git a/lib/extends/helpers/decidim/meetings/directory/application_helper_extends.rb b/lib/extends/helpers/decidim/meetings/directory/application_helper_extends.rb new file mode 100644 index 0000000000..60e56f1f02 --- /dev/null +++ b/lib/extends/helpers/decidim/meetings/directory/application_helper_extends.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require "active_support/concern" +module ApplicationHelperExtends + extend ActiveSupport::Concern + include Decidim::CheckBoxesTreeHelper + + included do + def directory_filter_scopes_values + main_scopes = current_organization.scopes.top_level + scopes_values = main_scopes.includes(:scope_type, :children).sort_by(&:weight).flat_map do |scope| + TreeNode.new( + TreePoint.new(scope.id.to_s, translated_attribute(scope.name, current_organization)), + scope_children_to_tree(scope) + ) + end + + scopes_values.prepend(TreePoint.new("global", t("decidim.scopes.global"))) + + TreeNode.new( + TreePoint.new("", t("decidim.meetings.application_helper.filter_scope_values.all")), + scopes_values + ) + end + + def scope_children_to_tree(scope) + return unless scope.children.any? + + scope.children.includes(:scope_type, :children).sort_by(&:weight).flat_map do |child| + TreeNode.new( + TreePoint.new(child.id.to_s, translated_attribute(child.name, current_organization)), + scope_children_to_tree(child) + ) + end + end + end +end + +Decidim::Meetings::Directory::ApplicationHelper.include(ApplicationHelperExtends) diff --git a/spec/helpers/decidim/meetings/directory/application_helper_spec.rb b/spec/helpers/decidim/meetings/directory/application_helper_spec.rb new file mode 100644 index 0000000000..fc0075add0 --- /dev/null +++ b/spec/helpers/decidim/meetings/directory/application_helper_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Meetings + module Directory + describe ApplicationHelper do + let(:helper) do + Class.new(ActionView::Base) do + include ApplicationHelper + include CheckBoxesTreeHelper + include TranslatableAttributes + end.new(ActionView::LookupContext.new(ActionController::Base.view_paths), {}, []) + end + let!(:organization) { create(:organization) } + let!(:parent_scope) { create(:scope, organization: organization) } + let!(:scope_one) { create(:scope, organization: organization, parent: parent_scope, weight: 1) } + let!(:scope_two) { create(:scope, organization: organization, parent: parent_scope, weight: 2) } + let!(:scope_three) { create(:scope, organization: organization, parent: parent_scope, weight: 3) } + + before do + allow(helper).to receive(:current_organization).and_return(organization) + end + + describe "#directory_filter_scopes_values" do + let(:root) { helper.directory_filter_scopes_values } + let(:leaf) { root.leaf } + let(:nodes) { root.node } + + context "when the organization has a scope with children" do + it "returns all the children ordered by weight" do + expect(root).to be_a(Decidim::CheckBoxesTreeHelper::TreeNode) + expect(nodes.last.node.count).to eq(3) + expect(nodes.last.node.first.leaf.label).to eq(scope_one.name["en"]) + expect(nodes.last.node.last.leaf.label).to eq(scope_three.name["en"]) + end + + context "and the weight of scope's children changes" do + it "returns the children ordered by the new weight" do + scope_one.update(weight: 4) + expect(root).to be_a(Decidim::CheckBoxesTreeHelper::TreeNode) + expect(nodes.last.node.count).to eq(3) + expect(nodes.last.node.first.leaf.label).to eq(scope_two.name["en"]) + expect(nodes.last.node.last.leaf.label).to eq(scope_one.name["en"]) + end + end + end + end + end + end + end +end