Tidy up code related to show the selected collections' title in a filter

This commit is contained in:
Jorge Manrubia
2025-08-20 12:49:12 +02:00
parent 4cc3323581
commit 763d924b64
7 changed files with 27 additions and 52 deletions
-29
View File
@@ -1,14 +1,4 @@
module FiltersHelper
def filter_title(filter)
if filter.collections.none?
Current.user.collections.one? ? Current.user.collections.first.name : "All collections"
elsif filter.collections.one?
filter.collections.first.name
else
filter.collections.map(&:name).to_sentence
end
end
def filter_chip_tag(text, params)
link_to cards_path(params), class: "btn txt-x-small btn--remove fill-selected flex-inline" do
concat tag.span(text)
@@ -21,25 +11,6 @@ module FiltersHelper
hidden_field_tag name, value, id: nil
end
# TODO: REMOVE
def filter_selected_collections_sentence(filter)
if filter.collections.any?
filter.collections.collect { "<strong>#{it.name}</strong>" }.uniq.sort.to_sentence
else
tag.strong "All collections"
end
end
def filter_selected_collections_label(filter)
selected_collections = if filter.collections.any?
filter.collections.collect { "<strong>#{it.name}</strong>" }.uniq.sort.to_sentence
else
"all collections"
end
"Activity in #{selected_collections}".html_safe
end
def any_filters?(filter)
filter.tags.any? || filter.assignees.any? || filter.creators.any? || filter.closers.any? ||
filter.stages.any? || filter.terms.any? || filter.card_ids&.any? ||
+10
View File
@@ -22,4 +22,14 @@ class User::Filtering
def filters
@filters ||= Current.user.filters.all
end
def collections_title
if filter.collections.none?
collections.one? ? collections.first.name : "All collections"
elsif filter.collections.one?
filter.collections.first.name
else
filter.collections.map(&:name).to_sentence
end
end
end
+5 -10
View File
@@ -1,4 +1,4 @@
<% @page_title = filter_title @filter %>
<% @page_title = @user_filtering.collections_title %>
<%= render "filters/broadcasts", filter: @filter %>
@@ -13,17 +13,12 @@
<% end %>
<header class="header" style="--header-actions-width: 7rem;">
<div class="header__actions header__actions--start">
<% if collection = @filter.single_collection || Current.user.collections.first %>
<%= button_to collection_cards_path(collection), method: :post, class: "btn btn--link btn--circle-mobile" do %>
<%= icon_tag "add" %>
<span>Add a card</span>
<% end %>
<% end %>
</div>
<%= render "filters/menu/add_card_button", user_filtering: @user_filtering %>
<h1 class="header__title overflow-ellipsis" style="view-transistion-name: card-collection-title">
<%= filter_title @filter %>
<%= @user_filtering.collections_title %>
</h1>
<div class="header__actions header__actions--end">
<% if collection = @filter.single_collection %>
<%= access_involvement_advance_button collection, Current.user %>
+2 -11
View File
@@ -10,20 +10,11 @@
<% end %>
<header class="events-header header margin-block-end">
<div class="header__actions header__actions--start">
<% if collection = @filter.single_collection || Current.user.collections.ordered_by_recently_accessed.first %>
<%= button_to collection_cards_path(collection), method: :post, class: "btn btn--link btn--circle-mobile" do %>
<%= icon_tag "add" %>
<span>Add a card</span>
<% end %>
<% end %>
</div>
<%= render "filters/menu/add_card_button", user_filtering: @user_filtering %>
<h1 class="header__title overflow-ellipsis">
<div class="overflow-ellipsis">
<% if @filter.collections.any? %>
<%= filter_selected_collections_label(@filter) %>
<% end %>
Activity in <%= @user_filtering.collections_title %>
</div>
</h1>
@@ -0,0 +1,8 @@
<div class="header__actions header__actions--start">
<% if collection = user_filtering.collections.first %>
<%= button_to collection_cards_path(collection), method: :post, class: "btn btn--link btn--circle-mobile" do %>
<%= icon_tag "add" %>
<span>Add a card</span>
<% end %>
<% end %>
</div>
+1 -1
View File
@@ -2,5 +2,5 @@
<li class="popup__group-title">Saved filters</li>
<%= render "filters/menu/custom/create" %>
<%= render partial: "filters/menu/custom/filter", collection: user_filtering.filters, as: :filter %>
<%= render partial: "filters/menu/custom/filter", collection: user_filtering.filters, as: :filter, locals: { user_filtering: user_filtering } %>
</ul>
@@ -2,7 +2,7 @@
<%= link_to url_for(filter_id: filter.id), class: "btn popup__new popup__item" do %>
<%= icon_tag "bookmark" %>
<div class="flex flex-column txt-tight-lines min-width txt-small">
<span class="overflow-ellipsis"><%= filter_selected_collections_sentence(filter).html_safe %></span>
<span class="overflow-ellipsis"><%= user_filtering.collections_title %></span>
<span class="overflow-ellipsis"><%= filter.summary %></span>
</div>
<span class="translucent flex-item-no-shrink flex-item-justify-end"> </span>