Skip to content

Commit

Permalink
Filter conferences by colors (#14)
Browse files Browse the repository at this point in the history
* Replace hashtags, Remove menu "triplication"

* Replace hashtags

* show buttons for existing conferences

* refactoring

* add original to deface

* cells override

* use a query string

* add tests

* add controller spec

* add spec checksums

* change default links color

* active links

* styles
  • Loading branch information
antopalidi committed Sep 7, 2023
1 parent 2c25548 commit 0afc191
Show file tree
Hide file tree
Showing 27 changed files with 323 additions and 326 deletions.
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.14.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.14.5-x86_64-linux)
Expand Down Expand Up @@ -871,6 +873,7 @@ GEM
zeitwerk (2.6.11)

PLATFORMS
arm64-darwin-23
x86_64-darwin-22
x86_64-darwin-23
x86_64-linux
Expand Down
15 changes: 15 additions & 0 deletions app/cells/concerns/decidim/conference_cell_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Decidim
module ConferenceCellExtensions
extend ActiveSupport::Concern

def conference_class(model)
custom_conference_types = Rails.application.secrets.custom_conference_types || []
custom_conference_types.each do |item|
return item[:key] if model.hashtag.include?(item[:hashtag])
end
""
end
end
end
22 changes: 22 additions & 0 deletions app/cells/decidim/card_m/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="column" id="<%= dom_id(model) %>">
<div class="card <%= card_classes %> <%= conference_class(model) %>">
<%= render :label if has_label? %>
<%= render :top if render_top? %>
<%= render :image if has_image? %>
<div class="card__content">
<%= render :header if has_header? %>

<div class="card__text">
<div class="card__text--paragraph">
<%= render :badge if has_badge? %>
<%= Decidim::ContentProcessor.render(description, "div") %>
</div>
</div>

<%= render :tags %>
</div>

<%= render :data %>
<%= render :footer %>
</div>
</div>
9 changes: 9 additions & 0 deletions app/cells/decidim/conferences/conference_m/footer.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="card__footer card__footer--spaces">
<div class="card__support <%= conference_class(model) %>">
<%= link_to(
t(model.cta_button_text_key, scope: "layouts.decidim.conferences.conference"),
resource_path,
class: "card__button button conference-button button--sc small"
) %>
</div>
</div>
46 changes: 13 additions & 33 deletions app/controllers/concerns/conferences_controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ module ConferencesControllerOverride
extend ActiveSupport::Concern

included do
def hashtag_for_current_url
@hashtag_for_current_url ||= Rails.application.secrets.custom_conference_types.find do |item|
item[:url] == request.path
end&.dig(:hashtag)
private

def hashtag_for_current_type
@hashtag_for_current_type ||= find_hashtag_for_current_type
end

def find_hashtag_for_current_type
type = params[:type]
Rails.application.secrets.custom_conference_types.find { |item| item[:key] == type }&.dig(:hashtag)
end

def published_conferences
Expand All @@ -18,42 +23,17 @@ def conferences
@conferences ||= conferences_query(Decidim::Conferences::OrganizationPrioritizedConferences)
end

alias_method :collection, :conferences

def promoted_conferences
@promoted_conferences ||= hashtag_for_current_url ? promoted_filtered_by_hashtag(conferences) : promoted_conferences_without_custom_hashtag(Decidim::Conference.promoted)
def collection
conferences
end

private

def custom_hashtags
@custom_hashtags ||= Rails.application.secrets.custom_conference_types.map { |item| item[:hashtag] }
end

def conferences_query(conference_class)
conferences = conference_class.new(current_organization, current_user)
hashtag_for_current_url ? conferences_with_custom_hashtag_filter(conferences) : conferences_without_custom_hashtag(conferences)
end

def conferences_with_custom_hashtag_filter(conferences)
conferences.query.merge(Decidim::Conference.filtered_by_hashtag(hashtag_for_current_url))
end

def conferences_without_custom_hashtag(conferences)
conferences.query.to_a.reject do |conference|
conference_hashtags = conference.hashtag.split
(conference_hashtags & custom_hashtags).any?
end
end

def promoted_filtered_by_hashtag(conferences)
conferences.merge(Decidim::Conference.promoted.filtered_by_hashtag(hashtag_for_current_url))
end

def promoted_conferences_without_custom_hashtag(conferences)
conferences.select do |conference|
conference_hashtags = conference.hashtag.split
(conference_hashtags & custom_hashtags).empty?
conference_class.new(current_organization, current_user).query.tap do |query|
query.merge!(Decidim::Conference.filtered_by_hashtag(hashtag_for_current_type)) if hashtag_for_current_type
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- insert_after "erb[loud]:contains('decidim/conferences/order_by_conferences')" -->

<%= render partial: "capitalitat/conferences_buttons" %>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- original "25277dbf8f6306c2d1703a6fe82abf2be777fc7a" -->
<!-- replace ".main-footer" -->

<div class="main-footer">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- original "039f5044ee0fe68fb0f2fe8a101ae401d579fb27" -->
<!-- replace ".mini-footer" -->

<div class="mini-footer">
Expand Down
2 changes: 2 additions & 0 deletions app/packs/stylesheets/capital_of_democracy.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
@import "partials/fonts";
@import "partials/html_block";
@import "partials/active_processes_card";
@import "partials/conferences";
@import "partials/texts";
4 changes: 2 additions & 2 deletions app/packs/stylesheets/partials/_active_processes_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.section-heading {
position: relative;
margin-left: 1.5rem;
color: $cpb-violet;
color: $capitalitat-violet;
}

.section-heading::after {
Expand All @@ -26,7 +26,7 @@
top: 6px;
width: 10px;
height: 10px;
border: solid $cpb-violet;
border: solid $capitalitat-violet;
border-width: 0 2px 2px 0;
transform: rotate(-45deg);
}
Expand Down
25 changes: 25 additions & 0 deletions app/packs/stylesheets/partials/_conferences.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@each $class, $color in $classes-colors {
.button.#{$class} {
@include button-styles($color);
}

.button.active-btn {
opacity: 1;
}

.button.inactive-btn {
opacity: 0.5;
}

.card.card--conference.#{$class} {
@include card-styles($color);
}

.card__support.#{$class} {
@include card-support-styles($color);

.conference-button {
@include link-styles($color);
}
}
}
2 changes: 1 addition & 1 deletion app/packs/stylesheets/partials/_footer.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.main-footer,
.mini-footer {
background-color: $cpb-violet !important;
background-color: $capitalitat-violet !important;
}

.footer__logo-title {
Expand Down
4 changes: 2 additions & 2 deletions app/packs/stylesheets/partials/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
}

.header .navbar {
background-color: $cpb-violet;
background-color: $capitalitat-violet;
}

.off-canvas,
.navbar {
background-color: $cpb-blue;
background-color: $capitalitat-blue;
}

.usermenu-off-canvas-holder .usermenu-off-canvas {
Expand Down
2 changes: 1 addition & 1 deletion app/packs/stylesheets/partials/_hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
margin-top: 1rem;
padding: 1.2rem 1rem;
background-color: #ffffff;
color: $cpb-violet;
color: $capitalitat-violet;

@include breakpoint(medium) {
margin-top: 1.3rem;
Expand Down
2 changes: 1 addition & 1 deletion app/packs/stylesheets/partials/_html_block.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.democracy-innovation {
background-color: $cpb-violet;
background-color: $capitalitat-violet;
padding: 4rem 0;
}

Expand Down
4 changes: 2 additions & 2 deletions app/packs/stylesheets/partials/_stats.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}

.statistics-cell .statistic__number {
color: $cpb-blue;
color: $capitalitat-blue;
font-weight: 400;
}

Expand All @@ -23,7 +23,7 @@
}

.card--list__icon {
fill: $cpb-rose;
fill: $capitalitat-rose;
height: 50%;
width: auto;
}
Expand Down
11 changes: 11 additions & 0 deletions app/packs/stylesheets/partials/_texts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.card__link {
color: $capitalitat-violet;

&:hover {
color: #403e80;
}

&:focus {
color: #403e80;
}
}
35 changes: 29 additions & 6 deletions app/packs/stylesheets/partials/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
$cpb-violet: #524F9F;
$cpb-rose: #E670A6;
$cpb-blue: #3397D9;
$cpb-brown: #5E3836;
$cpb-red: #E33B29;
$cpb-orange: #EB7329;
$capitalitat-violet: #524F9F;
$capitalitat-rose: #E670A6;
$capitalitat-blue: #3397D9;
$capitalitat-brown: #5E3836;
$capitalitat-red: #E33B29;
$capitalitat-orange: #EB7329;
$black-font: #000;
$grey-color: #EDEDED;
$classes-colors: (
city: $capitalitat-rose,
international: $capitalitat-blue,
activity: $capitalitat-orange
);

@font-face {
font-family: 'Inter';
Expand Down Expand Up @@ -34,3 +39,21 @@ $grey-color: #EDEDED;
font-style: normal;
font-weight: 600;
}

@mixin button-styles($color) {
background-color: $color;
color: white;
}

@mixin card-styles($color) {
border: 1px solid $color;
}

@mixin card-support-styles($color) {
background-color: $color;
}

@mixin link-styles($color) {
background-color: white;
color: $capitalitat-violet;
}
16 changes: 16 additions & 0 deletions app/views/capitalitat/_conferences_buttons.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="flex flex--sc mb-s">
<% custom_conference_types = Rails.application.secrets.custom_conference_types || [] %>
<% current_type = params[:type] %>
<% all_active = current_type.blank? %>
<% custom_conference_types.each do |item| %>
<% hashtag = item[:hashtag] %>
<% if Decidim::Conference.exists?(Decidim::Conference.filtered_by_hashtag(hashtag)) %>
<% is_active = all_active || current_type == item[:key] %>
<%= link_to I18n.t(item[:key], scope: "decidim.conferences.custom_conference_types"),
conferences_path(type: item[:key]),
class: "button button--sc #{item[:key]} conference-button #{is_active ? 'active-btn' : 'inactive-btn'}" %>
<% end %>
<% end %>
</div>
16 changes: 2 additions & 14 deletions config/initializers/conferences_hacks.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
# frozen_string_literal: true

# extra menus defined in secrets.yml
Decidim.menu :menu do |menu|
custom_conference_types = Rails.application.secrets.custom_conference_types || []
custom_conference_types.each do |item|
hashtag = item[:hashtag]
options = {}
options[:position] = item[:position].to_i if item[:position]
options[:active] = item[:active].to_sym if item[:active]
options[:icon_name] = item[:icon_name].to_s if item[:icon_name]
options[:if] = Decidim::Conference.exists?(Decidim::Conference.filtered_by_hashtag(hashtag))
menu.add_item item[:key], I18n.t(item[:key], scope: "decidim.conferences.custom_conference_types"), item[:url], options
end
end

Rails.application.config.to_prepare do
Decidim::StatisticCell.include(Decidim::StatisticCellOverride)
Decidim::CardMCell.include(Decidim::ConferenceCellExtensions)
Decidim::Conferences::ConferenceMCell.include(Decidim::ConferenceCellExtensions)
Decidim::Conference.include(ConferenceOverride)
end

Expand Down
5 changes: 3 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ en:
decidim:
conferences:
custom_conference_types:
city: City conferences
parallel: Parallel conferences
activity: Parallel activities
city: City acts
international: International acts
content_blocks:
active_processes:
name: Active processes
Expand Down
6 changes: 0 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,5 @@
resources :iframe, only: [:index]
end

scope module: "decidim/conferences" do
Rails.application.secrets.custom_conference_types.each do |item|
get item[:url], to: "conferences#index"
end
end

mount Decidim::Core::Engine => "/"
end
12 changes: 5 additions & 7 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ storage_default: &storage_default

default: &default
custom_conference_types:
- key: parallel # used to find the I18n key and route path
url: /conferences/parallel
position: 6
hashtag: actesparalels
- key: activity # used to find the I18n key and route path
hashtag: activitat
- key: city # used to find the I18n key and route path
url: /conferences/city
position: 6
hashtag: actesciutat
hashtag: ciutat
- key: international # used to find the I18n key and route path
hashtag: internacional
decidim:
<<: *decidim_default
omniauth:
Expand Down
Loading

0 comments on commit 0afc191

Please sign in to comment.