Skip to content

Commit

Permalink
Merge branch 'develop' into fix/scopes_not_modified
Browse files Browse the repository at this point in the history
  • Loading branch information
luciegrau authored Nov 28, 2024
2 parents 4d271f1 + cfe65a9 commit 474f643
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 20 deletions.
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 474f643

Please sign in to comment.