From 763d924b64cd7ea84b666ffc8f2ecc48a12e2753 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Wed, 20 Aug 2025 12:49:12 +0200 Subject: [PATCH] Tidy up code related to show the selected collections' title in a filter --- app/helpers/filters_helper.rb | 29 ------------------- app/models/user/filtering.rb | 10 +++++++ app/views/cards/index.html.erb | 15 ++++------ app/views/events/index.html.erb | 13 ++------- .../filters/menu/_add_card_button.html.erb | 8 +++++ app/views/filters/menu/_custom.html.erb | 2 +- .../filters/menu/custom/_filter.html.erb | 2 +- 7 files changed, 27 insertions(+), 52 deletions(-) create mode 100644 app/views/filters/menu/_add_card_button.html.erb diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 9fb4bf7ac..98f83d275 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -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 { "#{it.name}" }.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 { "#{it.name}" }.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? || diff --git a/app/models/user/filtering.rb b/app/models/user/filtering.rb index e52cea178..f3ac4f2fd 100644 --- a/app/models/user/filtering.rb +++ b/app/models/user/filtering.rb @@ -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 diff --git a/app/views/cards/index.html.erb b/app/views/cards/index.html.erb index 1b5f95849..db952c9f6 100644 --- a/app/views/cards/index.html.erb +++ b/app/views/cards/index.html.erb @@ -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 %>
-
- <% 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" %> - Add a card - <% end %> - <% end %> -
+ <%= render "filters/menu/add_card_button", user_filtering: @user_filtering %> +

- <%= filter_title @filter %> + <%= @user_filtering.collections_title %>

+
<% if collection = @filter.single_collection %> <%= access_involvement_advance_button collection, Current.user %> diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index 3c35bbcd0..c13e8f810 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -10,20 +10,11 @@ <% end %>
-
- <% 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" %> - Add a card - <% end %> - <% end %> -
+ <%= render "filters/menu/add_card_button", user_filtering: @user_filtering %>

- <% if @filter.collections.any? %> - <%= filter_selected_collections_label(@filter) %> - <% end %> + Activity in <%= @user_filtering.collections_title %>

diff --git a/app/views/filters/menu/_add_card_button.html.erb b/app/views/filters/menu/_add_card_button.html.erb new file mode 100644 index 000000000..0341b08c3 --- /dev/null +++ b/app/views/filters/menu/_add_card_button.html.erb @@ -0,0 +1,8 @@ +
+ <% 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" %> + Add a card + <% end %> + <% end %> +
diff --git a/app/views/filters/menu/_custom.html.erb b/app/views/filters/menu/_custom.html.erb index 52d5a7a23..ebc5ce1e9 100644 --- a/app/views/filters/menu/_custom.html.erb +++ b/app/views/filters/menu/_custom.html.erb @@ -2,5 +2,5 @@ <%= 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 } %> diff --git a/app/views/filters/menu/custom/_filter.html.erb b/app/views/filters/menu/custom/_filter.html.erb index bd4f26e7c..c1d96d2a3 100644 --- a/app/views/filters/menu/custom/_filter.html.erb +++ b/app/views/filters/menu/custom/_filter.html.erb @@ -2,7 +2,7 @@ <%= link_to url_for(filter_id: filter.id), class: "btn popup__new popup__item" do %> <%= icon_tag "bookmark" %>
- <%= filter_selected_collections_sentence(filter).html_safe %> + <%= user_filtering.collections_title %> <%= filter.summary %>