Skip to content

Commit 22a9fee

Browse files
microstudiElviaBth
andauthored
Import latest changes from 0.29 (#4)
* update latest changes * trigger CI * remove manifest name * fix locales * fix specs --------- Co-authored-by: elviabth <ejbenedith@gmail.com>
1 parent 757d5ff commit 22a9fee

File tree

24 files changed

+412
-76
lines changed

24 files changed

+412
-76
lines changed

app/cells/decidim/alternative_landing/content_blocks/alternative_upcoming_meetings_cell.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ def meetings
2929

3030
private
3131

32-
def manifest_name
33-
"meetings"
34-
end
35-
3632
# A MD5 hash of model attributes because is needed because
3733
# it ensures the cache version value will always be the same size
3834
def cache_hash

app/cells/decidim/alternative_landing/content_blocks/alternative_upcoming_meetings_settings_form/show.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
<%= t(".info", component: translated_attribute(component.name), space: translated_attribute(component.participatory_space.title)) %>
99
</p>
1010
<% end %>
11-
<%= settings_fields.select :component_id, available_components %>
11+
<%= settings_fields.select :component_id, available_components("meetings") %>
1212
<% end %>

app/cells/decidim/alternative_landing/content_blocks/alternative_upcoming_meetings_settings_form_cell.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module AlternativeLanding
55
module ContentBlocks
66
class AlternativeUpcomingMeetingsSettingsFormCell < BaseCell
77
alias form model
8-
9-
def manifest_name
10-
"meetings"
11-
end
128
end
139
end
1410
end

app/cells/decidim/alternative_landing/content_blocks/base_cell.rb

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,45 @@ def participatory_spaces
1818
].flatten.compact
1919
end
2020

21-
def available_components
22-
@available_components ||= components.where(manifest_name:).map do |component|
21+
def available_components(manifest_name)
22+
@available_components ||= {}
23+
@available_components[manifest_name] ||= components.where(manifest_name:).map do |component|
2324
["#{translated_attribute(component.name)} (#{translated_attribute(component.participatory_space.title)})", component.id]
2425
end.unshift [t(".all"), nil]
2526
end
2627

27-
def component
28-
@component ||= components.find_by(id: (defined?(form) ? form.object : model).settings.try(:component_id))
28+
def available_posts
29+
[
30+
[t("sidebar_right_stack_settings_form.filter_posts.all", scope: "decidim.alternative_landing.content_blocks"), "all"],
31+
[t("sidebar_right_stack_settings_form.filter_posts.organization", scope: "decidim.alternative_landing.content_blocks"), "organization"],
32+
[t("sidebar_right_stack_settings_form.filter_posts.users", scope: "decidim.alternative_landing.content_blocks"), "users"]
33+
]
34+
end
35+
36+
def available_meeting_components
37+
special_options = [
38+
[t(".all_meetings"), "all"],
39+
[t(".let_me_choose_individual_meetings"), "meeting-picker"]
40+
]
41+
42+
@available_meeting_components ||= special_options + available_components("meetings")
43+
end
44+
45+
def component(component_key = :component)
46+
@component_cache ||= {}
47+
@component_cache[component_key] ||= begin
48+
record = defined?(form) ? form.object : model
49+
component_id = record.settings.try("#{component_key}_id")
50+
component_relation.find_by(id: component_id) if component_id.present?
51+
end
2952
end
3053

3154
def components
3255
@components ||= Decidim::Component.where(participatory_space: participatory_spaces)
3356
end
3457

35-
def manifest_name
36-
raise NotImplementedError
58+
def component_relation
59+
components
3760
end
3861

3962
def colors

app/cells/decidim/alternative_landing/content_blocks/latest_blog_posts_cell.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ def post_path(post)
2020
end
2121

2222
def posts
23-
@posts ||= Blogs::Post.where(
24-
component: component || components
25-
).limit(posts_to_show).order(created_at: :desc)
26-
end
23+
scope = Blogs::Post.where(component: component || components)
2724

28-
private
25+
case model.settings[:filter]
26+
when "organization"
27+
scope = scope.where(decidim_author_type: "Decidim::Organization")
28+
when "users"
29+
scope = scope.where(decidim_author_type: "Decidim::UserBaseEntity")
30+
end
2931

30-
def manifest_name
31-
"blogs"
32+
scope.limit(posts_to_show).order(created_at: :desc)
3233
end
3334

35+
private
36+
3437
# A MD5 hash of model attributes because is needed because
3538
# it ensures the cache version value will always be the same size
3639
def cache_hash

app/cells/decidim/alternative_landing/content_blocks/latest_blog_posts_settings_form/show.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<%= t(".info", component: translated_attribute(component.name), space: translated_attribute(component.participatory_space.title)) %>
99
</p>
1010
<% end %>
11-
<%= settings_fields.select :component_id, available_components %>
11+
<%= settings_fields.select :component_id, available_components("blogs") %>
12+
<%= settings_fields.select :filter, available_posts, label: t("latest_blog_posts_settings_form.filter.name", scope: "decidim.alternative_landing.content_blocks") %>
1213
<% end %>

app/cells/decidim/alternative_landing/content_blocks/latest_blog_posts_settings_form_cell.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module AlternativeLanding
55
module ContentBlocks
66
class LatestBlogPostsSettingsFormCell < BaseCell
77
alias form model
8-
9-
def manifest_name
10-
"blogs"
11-
end
128
end
139
end
1410
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<label for="meetings_list">
2+
<%= t("name", scope: "decidim.components.meetings") %>
3+
4+
<select id="meetings_list"
5+
placeholder="<%= t("meetings_picker.choose_meetings", scope: "decidim.alternative_landing.content_blocks.sidebar_right_stack_settings_form") %>"
6+
data-tm-name="<%= form_name %>"
7+
data-tm-items="<%= selected_ids.to_json %>"
8+
data-tm-no-results="<%= t("meetings_picker.no_meetings", scope: "decidim.alternative_landing.content_blocks.sidebar_right_stack_settings_form") %>"
9+
class="mt-4" multiple>
10+
<% decorated_meetings do |meeting| %>
11+
<option value="<%= meeting.id %>"><%= decidim_sanitize translated_attribute(meeting.title) %> (<%= decidim_sanitize meeting.reference %>)</option>
12+
<% end %>
13+
</select>
14+
</label>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
module Decidim
4+
module AlternativeLanding
5+
module ContentBlocks
6+
class MeetingsPickerCell < BaseCell
7+
def show
8+
render
9+
end
10+
11+
alias component model
12+
13+
def form
14+
options[:form]
15+
end
16+
17+
def field
18+
options[:field]
19+
end
20+
21+
def form_name
22+
"#{form.object_name}[settings][#{field}]"
23+
end
24+
25+
def selected_ids
26+
form.object["settings"]&.meeting_ids&.map(&:to_i) || []
27+
end
28+
29+
def meetings
30+
@meetings ||= Meetings::Meeting.upcoming.where(
31+
component: component || components
32+
)
33+
end
34+
35+
def decorated_meetings
36+
meetings.map do |meeting|
37+
yield Decidim::Meetings::MeetingPresenter.new(meeting)
38+
end
39+
end
40+
end
41+
end
42+
end
43+
end

app/cells/decidim/alternative_landing/content_blocks/sidebar_right_stack/show.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<p><%= translated_body %></p>
1515
</div>
1616
<div>
17-
<a href="<%= translated_url("sidebar")%>" class="button button__sm md:button__lg button__secondary no-underline mt-4 mb-4">
17+
<a href="<%= translated_url("sidebar") %>" class="button button__sm md:button__lg button__secondary no-underline mt-4 mb-4">
1818
<%= translated_link_text("sidebar") %>
1919
</a>
2020
</div>
@@ -29,12 +29,12 @@
2929
<div class="splide__slider">
3030
<div class="splide__track">
3131
<ul class="splide__list">
32-
<% meetings.each do |meeting|%>
32+
<% meetings.each do |meeting| %>
3333
<li class="splide__slide min-h-[100px] ">
3434
<%
3535
formatted_date = l(meeting.start_time, format: :long)
3636
%>
37-
<h3 class="text-2xl"><%= translated_attribute(meeting.title) %></h3>
37+
<h3 class="text-2xl"><%= decidim_sanitize translated_attribute(meeting.title) %></h3>
3838
<p><%= "#{formatted_date}" %></p>
3939
</li>
4040
<% end %>
@@ -54,13 +54,13 @@
5454

5555
<div class="stack_two h-[40vh] w-[100vw] md:w-[50vw] grid grid-rows-3">
5656
<div class="w-[100vw] md:w-[50vw]">
57-
<h2 class="mt-4 mb-4 text-5xl font-bold uppercase"><%= decidim_sanitize translated_title("posts")%></h2>
57+
<h2 class="mt-4 mb-4 text-5xl font-bold uppercase"><%= decidim_sanitize translated_title("posts") %></h2>
5858
</div>
59-
<div id="alternative-landing-sidebar-splide-post"class="splide w-[100vw] md:w-[50vw] m-auto">
59+
<div id="alternative-landing-sidebar-splide-post" class="splide w-[100vw] md:w-[50vw] m-auto">
6060
<div class="splide__slider">
6161
<div class="splide__track">
6262
<ul class="splide__list">
63-
<% posts.each do |post|%>
63+
<% posts.each do |post| %>
6464
<li class="splide__slide post">
6565
<h3 class="text-2xl"><%= translated_attribute(post.title) %></h3>
6666
</li>

0 commit comments

Comments
 (0)