Skip to content

Commit

Permalink
release (rc): 2.5.1.1
Browse files Browse the repository at this point in the history
Sync branch with develop
  • Loading branch information
Quentinchampenois authored Nov 28, 2024
2 parents 1fe41e8 + 3271771 commit ecc27fa
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ module Decidim
module SimpleProposal
module ScopesHelperOverride
extend ActiveSupport::Concern

included do
def scopes_picker_field(form, name, root: false, options: { checkboxes_on_top: true, sort_by_weight: true })
def scopes_picker_field(form, name, root: false, options: { checkboxes_on_top: true })
options.merge!(selected: selected_scope(form)) if selected_scope(form)
form.select(name, simple_scope_options(root: root, options: options), include_blank: t("decidim.scopes.prompt"))
end
Expand All @@ -23,11 +22,9 @@ def selected_scope(form)
def simple_scope_options(root: false, options: {})
scopes_array = []
roots = root ? root.children : ancestors

roots.sort_by { |ancestor| ancestor.weight || 0 }.each do |ancestor|
children_after_parent(ancestor, scopes_array, "")
end

selected = options.has_key?(:selected) ? options[:selected] : params.dig(:filter, :decidim_scope_id)
options_for_select(scopes_array, selected)
end
Expand All @@ -37,7 +34,7 @@ def ancestors
end

def children_after_parent(ancestor, array, prefix)
array << ["#{prefix} #{translated_attribute(ancestor.name)}", ancestor.id, ancestor.weight]
array << ["#{prefix} #{translated_attribute(ancestor.name)}", ancestor.id]
ancestor.children.sort_by { |child| child.weight || 0 }.each do |child|
children_after_parent(child, array, "#{prefix}-")
end
Expand Down
38 changes: 18 additions & 20 deletions app/views/decidim/proposals/proposals/index.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
<template id="marker-popup">
<div class="map-info__content">
<h3>${title}</h3>
<div id="bodyContent">
<p>{{html body}}</p>
<div class="map__date-address">
<div class="address card__extra">
<div class="address__icon">{{html icon}}</div>
<div class="address__details">
<span>${address}</span><br>
</div>
<%= dynamic_map_for proposals_data_for_map(@all_geocoded_proposals) do %>
<template id="marker-popup">
<div class="map-info__content">
<h3>${title}</h3>
<div id="bodyContent">
<p>{{html body}}</p>
<div class="map__date-address">
<div class="address card__extra">
<div class="address__icon">{{html icon}}</div>
<div class="address__details">
<span>${address}</span><br>
</div>
</div>
<div class="map-info__button">
<a href="${link}" class="button button--sc">
<%= t(".view_proposal") %>
</a>
</div>
</div>
<div class="map-info__button">
<a href="${link}" class="button button--sc">
<%= t(".view_proposal") %>
</a>
</div>
</div>
</template>
<% end %>
</div>
</template>
<% end %>
<% end %>
<%= render partial: "voting_rules" %>
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
53 changes: 53 additions & 0 deletions spec/helpers/decidim/meetings/directory/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ecc27fa

Please sign in to comment.