diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 0877f89f6cf..3cc5a96f431 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -43,8 +43,9 @@ def index flash_search_warnings(@collections) @page_subtitle = t(".subcollections_page_title", collection_title: @collection.title) elsif params[:user_id] + @sort_and_filter = true @user = User.find_by!(login: params[:user_id]) - @search = CollectionSearchForm.new({ maintainer_id: @user.id, sort_column: "title.keyword" }.merge(page: params[:page])) + @search = CollectionSearchForm.new(collection_filter_params.merge({ maintainer_id: @user.id, sort_column: "title.keyword" }.merge(page: params[:page]))) @collections = @search.search_results.scope(:for_search) flash_search_warnings(@collections) @page_subtitle = ts("%{username} - Collections", username: @user.login) @@ -194,7 +195,7 @@ def destroy private def collection_filter_params - params.permit(:commit, collection_search: [ + params.permit(:commit, :user_id, collection_search: [ :title, :challenge_type, :moderated, :multifandom, :closed, :tag, :sort_column, :sort_direction ])[:collection_search] || {} diff --git a/app/decorators/pseud_decorator.rb b/app/decorators/pseud_decorator.rb index c8df6bf3afc..2a1147c227f 100644 --- a/app/decorators/pseud_decorator.rb +++ b/app/decorators/pseud_decorator.rb @@ -1,5 +1,4 @@ class PseudDecorator < SimpleDelegator - attr_reader :data # Pseuds need to be decorated with various stats from the "_source" when @@ -14,7 +13,7 @@ def self.load_from_elasticsearch(hits, **options) def self.decorate_from_search(results, search_hits) search_data = search_hits.group_by { |doc| doc["_id"] } results.map do |result| - data = search_data[result.id.to_s].first&.dig('_source') || {} + data = search_data[result.id.to_s].first&.dig("_source") || {} new_with_data(result, data) end end @@ -76,28 +75,41 @@ def works_path def works_link return unless works_count > 0 + text = ActionController::Base.helpers.pluralize(works_count, "works") "#{text}" end + def collections_path + "#{pseud_path}/collections" + end + + def collections_link + text = ActionController::Base.helpers.pluralize(collections_count, "collections") + "#{text}" + end + def bookmarks_path "#{pseud_path}/bookmarks" end def bookmarks_link return unless bookmarks_count > 0 + text = ActionController::Base.helpers.pluralize(bookmarks_count, "bookmarks") "#{text}" end def fandom_path(id) return unless id + "#{works_path}?fandom_id=#{id}" end def fandom_link(fandom_id) fandom = fandom_stats(fandom_id) return unless fandom.present? + text = ActionController::Base.helpers.pluralize(fandom[:count], "work") + " in #{fandom[:name]}" "#{text}" end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index dcb9be97318..a98848c890c 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -1,7 +1,6 @@ module SearchHelper - # modified from mislav-will_paginate-2.3.2/lib/will_paginate/view_helpers.rb - def search_header(collection, search, item_name, parent=nil) + def search_header(collection, search, item_name, parent = nil) header = [] if !collection.respond_to?(:total_pages) header << ts("Recent #{item_name.pluralize}") @@ -53,6 +52,16 @@ def works_original_path ) end + def collections_original_path + url_for( + controller: :collections, + action: :index, + only_path: true, + **params.slice(:title, :challenge_type, :moderated, :multifandom, :closed, :tag, + :sort_column, :sort_direction).permit! + ) + end + def bookmarks_original_path url_for( controller: :bookmarks, diff --git a/app/views/collections/_filters.html.erb b/app/views/collections/_filters.html.erb index 03e2b280107..b6994f397e8 100644 --- a/app/views/collections/_filters.html.erb +++ b/app/views/collections/_filters.html.erb @@ -1,4 +1,10 @@ -<%= form_for @search, as: :collection_search, url: collections_path, html: { method: :get, class: "narrow-hidden filters", id: "collection-filters" } do |f| %> +<%= form_for @search, as: :collection_search, + url: (@user ? user_collections_path(@user) : collections_path), + html: { + method: :get, + class: "narrow-hidden filters", + id: "collection-filters" + } do |f| %>

<%= t(".landmark") %>

<%= field_set_tag t(".legend") do %>
@@ -133,7 +139,7 @@
<%= submit_tag t(".submit.button") %>

- <%= link_to t(".clear_filters"), collections_path %> + <%= link_to t(".clear_filters"), collections_original_path %>

<% end %> <% # On narrow screens, link jumps to top of index when JavaScript is disabled and closes filters when JavaScript is enabled %> diff --git a/app/views/collections/index.html.erb b/app/views/collections/index.html.erb index f3329008b9a..040b079f42b 100755 --- a/app/views/collections/index.html.erb +++ b/app/views/collections/index.html.erb @@ -13,46 +13,48 @@

<% if @collections.empty? %> - <%= ts("Sorry, there were no collections found.") %> + <%= t(".page_heading.no_results") %> <% else %> - <%= search_header @collections, @query, ts("Collection") %> + <%= search_header @collections, @query, t(".page_heading.search_header") %> <% end %>

-

<%= ts("Navigation") %>

- + <% unless @collections.blank? %> <%= will_paginate @collections %> -

<%= ts("List of Collections") %>

+

<%= t(".main_content.landmark_heading") %>