Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDG view with related content #4292

Merged
merged 15 commits into from
Dec 28, 2020
Merged
Prev Previous commit
Next Next commit
Extract components for feeds
  • Loading branch information
javierm committed Dec 27, 2020
commit 330efe5a418e81dc19d56a054ab718e462ebddd9
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
@import "admin/*";
@import "sdg/**/*";
@import "sdg_management/*";
@import "widgets/**/*";
20 changes: 0 additions & 20 deletions app/assets/stylesheets/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2889,10 +2889,6 @@ table {

.feeds-list {

.proposal {
clear: both;
}

a {

&.see-all {
Expand All @@ -2906,22 +2902,6 @@ table {
}
}

.feed-image {
display: inline-block;
height: rem-calc(120);
overflow: hidden;
width: 100%;

@include breakpoint(medium) {
height: rem-calc(96);
}

img {
max-width: none;
width: 100%;
}
}

.feed-description {

p {
Expand Down
22 changes: 22 additions & 0 deletions app/assets/stylesheets/widgets/feeds/proposals.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.feed-proposals {

.proposal {
clear: both;

.feed-image {
display: inline-block;
height: rem-calc(120);
overflow: hidden;
width: 100%;

@include breakpoint(medium) {
height: rem-calc(96);
}

img {
max-width: none;
width: 100%;
}
}
}
}
14 changes: 14 additions & 0 deletions app/components/widgets/feeds/debates_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="feed_debates" class="small-12 column margin-top
<%= "medium-4" if feed_debates_and_proposals_enabled? %>">
<div class="feed-content" data-equalizer-watch>
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
<div class="<%= item.class.to_s.parameterize(separator: "_") %>">
<strong><%= link_to item.title, url_for(item) %></strong>
</div>
<% end %>
</div>

<%= link_to t("welcome.feed.see_all_debates"), debates_path, class: "see-all" %>
</div>
8 changes: 8 additions & 0 deletions app/components/widgets/feeds/debates_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Widgets::Feeds::DebatesComponent < ApplicationComponent
include FeedsHelper
attr_reader :feed

def initialize(feed)
@feed = feed
end
end
11 changes: 11 additions & 0 deletions app/components/widgets/feeds/participation_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="row margin-bottom feeds-list feeds-participation" data-equalizer data-equalize-on="medium">
<% feeds.each do |feed| %>
<% if feed_proposals?(feed) %>
<%= render Widgets::Feeds::ProposalsComponent.new(feed) %>
<% end %>

<% if feed_debates?(feed) %>
<%= render Widgets::Feeds::DebatesComponent.new(feed) %>
<% end %>
<% end %>
</div>
17 changes: 17 additions & 0 deletions app/components/widgets/feeds/participation_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Widgets::Feeds::ParticipationComponent < ApplicationComponent
attr_reader :feeds

def initialize(feeds)
@feeds = feeds
end

private

def feed_debates?(feed)
feed.kind == "debates"
end

def feed_proposals?(feed)
feed.kind == "proposals"
end
end
21 changes: 21 additions & 0 deletions app/components/widgets/feeds/processes_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="card small-12 column margin-bottom">
<div class="feed-content">
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
<%= link_to url_for(item) do %>
<figure class="figure-card <%= item.class.to_s.parameterize(separator: "_") %>">
<%= image_tag("welcome_process.png", alt: "") %>
<figcaption>
<span><%= t("welcome.feed.process_label") %></span><br>
<h3><%= item.title %></h3>
</figcaption>
</figure>
<p class="description small"><%= item.summary %></p>
<p class="small"><%= t("welcome.feed.see_process") %></p>
<% end %>
<% end %>

<%= link_to t("welcome.feed.see_all_processes"), legislation_processes_path, class: "float-right see-all" %>
</div>
</div>
7 changes: 7 additions & 0 deletions app/components/widgets/feeds/processes_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Widgets::Feeds::ProcessesComponent < ApplicationComponent
attr_reader :feed

def initialize(feed)
@feed = feed
end
end
26 changes: 26 additions & 0 deletions app/components/widgets/feeds/proposals_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div id="feed_proposals" class="feed-proposals small-12 column margin-top
<%= "medium-8" if feed_debates_and_proposals_enabled? %>">
<div class="feed-content" data-equalizer-watch>
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
<div class="<%= item.class.to_s.parameterize(separator: "_") %> row">
<div class="feed-description small-12 column
<%= "medium-6 large-9" if item.image.present? %>">
<strong><%= link_to item.title, url_for(item) %></strong><br>
<p><%= item.summary %></p>
</div>
<% if item.image.present? %>
<div class="small-12 medium-6 large-3 column">
<div class="feed-image">
<%= image_tag item.image_url(:thumb),
alt: item.image.title.unicode_normalize %>
</div>
</div>
<% end %>
</div>
<% end %>
</div>

<%= link_to t("welcome.feed.see_all_proposals"), proposals_path, class: "see-all" %>
</div>
8 changes: 8 additions & 0 deletions app/components/widgets/feeds/proposals_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Widgets::Feeds::ProposalsComponent < ApplicationComponent
include FeedsHelper
attr_reader :feed

def initialize(feed)
@feed = feed
end
end
8 changes: 0 additions & 8 deletions app/helpers/feeds_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
module FeedsHelper
def feed_debates?(feed)
feed.kind == "debates"
end

def feed_proposals?(feed)
feed.kind == "proposals"
end

def feed_processes?(feed)
feed.kind == "processes"
end
Expand Down
52 changes: 1 addition & 51 deletions app/views/welcome/_feeds.html.erb
Original file line number Diff line number Diff line change
@@ -1,51 +1 @@
<div class="row margin-bottom feeds-list" data-equalizer data-equalize-on="medium">
<% @feeds.each do |feed| %>

<% if feed_proposals?(feed) %>
<div id="feed_proposals" class="small-12 column margin-top
<%= "medium-8" if feed_debates_and_proposals_enabled? %>">
<div class="feed-content" data-equalizer-watch>
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
<div class="<%= item.class.to_s.parameterize(separator: "_") %> row">
<div class="feed-description small-12 column
<%= "medium-6 large-9" if item.image.present? %>">
<strong><%= link_to item.title, url_for(item) %></strong><br>
<p><%= item.summary %></p>
</div>
<% if item.image.present? %>
<div class="small-12 medium-6 large-3 column">
<div class="feed-image">
<%= image_tag item.image_url(:thumb),
alt: item.image.title.unicode_normalize %>
</div>
</div>
<% end %>
</div>
<% end %>
</div>

<%= link_to t("welcome.feed.see_all_proposals"), proposals_path, class: "see-all" %>
</div>
<% end %>

<% if feed_debates?(feed) %>
<div id="feed_debates" class="small-12 column margin-top
<%= "medium-4" if feed_debates_and_proposals_enabled? %>">
<div class="feed-content" data-equalizer-watch>
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
<div class="<%= item.class.to_s.parameterize(separator: "_") %>">
<strong><%= link_to item.title, url_for(item) %></strong>
</div>
<% end %>
</div>

<%= link_to t("welcome.feed.see_all_debates"), debates_path, class: "see-all" %>
</div>
<% end %>

<% end %>
</div>
<%= render Widgets::Feeds::ParticipationComponent.new(@feeds) %>
24 changes: 1 addition & 23 deletions app/views/welcome/_processes.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
<div class="feeds-list">
<% @feeds.each do |feed| %>

<% if feed_processes?(feed) %>
<div class="card small-12 column margin-bottom">
<div class="feed-content">
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
<%= link_to url_for(item) do %>
<figure class="figure-card <%= item.class.to_s.parameterize(separator: "_") %>">
<%= image_tag("welcome_process.png", alt: "") %>
<figcaption>
<span><%= t("welcome.feed.process_label") %></span><br>
<h3><%= item.title %></h3>
</figcaption>
</figure>
<p class="description small"><%= item.summary %></p>
<p class="small"><%= t("welcome.feed.see_process") %></p>
<% end %>
<% end %>

<%= link_to t("welcome.feed.see_all_processes"), legislation_processes_path, class: "float-right see-all" %>
</div>
</div>
<%= render Widgets::Feeds::ProcessesComponent.new(feed) %>
<% end %>

<% end %>
</div>