diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 0877f89f6cf..62a2eab26f4 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, default_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/helpers/application_helper.rb b/app/helpers/application_helper.rb index 34d7ec9f3c2..9282b7dd811 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -19,10 +19,11 @@ def link_to_function(name, *args, &block) def classes_for_main class_names = controller.controller_name + '-' + controller.action_name - show_sidebar = (!@hide_dashboard && (@user || @admin_posts || @collection || show_wrangling_dashboard)) - class_names += " dashboard" if show_sidebar - - class_names += " filtered" if page_has_filters? + # Rails/HelperInstanceVariable is disabled for the two following lines given this warning is raised for reusing helpers. This function is only used once in application.html.erb + # Whether or not the sidebar should be shown + class_names += " dashboard" if !@hide_dashboard && (@user || @admin_posts || @collection || show_wrangling_dashboard) # rubocop:disable Rails/HelperInstanceVariable + # Whether or not the page will have filters + class_names += " filtered" if @facets.present? || (controller.controller_name == "collections" && @sort_and_filter) || (controller.action_name == "unassigned" && controller.controller_name == "fandoms") # rubocop:disable Rails/HelperInstanceVariable case controller.controller_name when "abuse_reports", "feedbacks", "known_issues" @@ -57,10 +58,6 @@ def classes_for_main class_names end - def page_has_filters? - @facets.present? || (controller.action_name == 'index' && controller.controller_name == 'collections') || (controller.action_name == 'unassigned' && controller.controller_name == 'fandoms') - end - # This is used to make the current page we're on (determined by the path or by the specified condition) a span with class "current" and it allows us to add a title attribute to the link or the span def span_if_current(link_to_default_text, path, condition=nil, title_attribute_default_text=nil) is_current = condition.nil? ? current_page?(path) : condition 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/models/search/collection_search_form.rb b/app/models/search/collection_search_form.rb index 13976949d9e..097a621d63c 100644 --- a/app/models/search/collection_search_form.rb +++ b/app/models/search/collection_search_form.rb @@ -71,7 +71,7 @@ def sort_options end def default_sort_column - "created_at" + options[:default_sort_column] ||= "created_at" end def default_sort_direction 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..bdd96e0f245 100755 --- a/app/views/collections/index.html.erb +++ b/app/views/collections/index.html.erb @@ -13,37 +13,37 @@

<% 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") %>

-