Skip to content
5 changes: 3 additions & 2 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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] || {}
Expand Down
13 changes: 11 additions & 2 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions app/views/collections/_filters.html.erb
Original file line number Diff line number Diff line change
@@ -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| %>
<h3 class="landmark heading"><%= t(".landmark") %></h3>
<%= field_set_tag t(".legend") do %>
<dl>
Expand Down Expand Up @@ -133,7 +139,7 @@
<dd class="submit actions"><%= submit_tag t(".submit.button") %></dd>
</dl>
<p class="footnote">
<%= link_to t(".clear_filters"), collections_path %>
<%= link_to t(".clear_filters"), collections_original_path %>
</p>
<% end %>
<% # On narrow screens, link jumps to top of index when JavaScript is disabled and closes filters when JavaScript is enabled %>
Expand Down
54 changes: 28 additions & 26 deletions app/views/collections/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,48 @@

<h3 class="heading">
<% 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 %>
</h3>
<!--/descriptions-->

<!--Subnavigation, sorting and actions-->
<h3 class="landmark heading"><%= ts("Navigation") %></h3>
<ul class="navigation actions" role="navigation">
<% # Collections and Open Challenges links unless a logged in user viewing own collections page %>
<% unless logged_in? && @user && @user == current_user %>
<li><%= span_if_current ts("Collections"), collections_path %></li>
<li><%= link_to ts("Open Challenges"), list_challenges_collections_path %></li>
<% end %>
<% if logged_in? %>
<% # Logged in user on own collections index gets links for user Collections and Manage Collection Items %>
<% if @user && @user == current_user %>
<li><%= span_if_current ts("Collections"), user_collections_path(@user) %></li>
<li><%= link_to ts("Manage Collection Items"), user_collection_items_path(@user) %></li>
<div class="navigation actions module">
<h3 class="landmark heading"><%= t(".navigation.landmark_heading") %></h3>
<ul class="navigation actions" role="navigation">
<%# Collections and Open Challenges links unless a logged in user viewing own collections page %>
<% unless logged_in? && @user && @user == current_user %>
<li><%= span_if_current t(".navigation.actions.collections"), collections_path %></li>
<li><%= link_to t(".navigation.actions.open_challenges"), list_challenges_collections_path %></li>
<% end %>
<% # Logged in collection maintainer on own collection gets link for New Subcollection and all other logged in users get New Collection link %>
<% if @collection && !@collection.parent && @collection.user_is_maintainer?(current_user) %>
<li><%= link_to ts("New Subcollection"), new_collection_collection_path(@collection) %></li>
<% else %>
<li><%= link_to ts("New Collection"), new_collection_path %></li>
<% if logged_in? %>
<%# Logged in user on own collections index gets links for user Collections and Manage Collection Items %>
<% if @user && @user == current_user %>
<li><%= span_if_current t(".navigation.actions.collections"), user_collections_path(@user) %></li>
<li><%= link_to t(".navigation.actions.manage_items"), user_collection_items_path(@user) %></li>
<% end %>
<%# Logged in collection maintainer on own collection gets link for New Subcollection and all other logged in users get New Collection link %>
<% if @collection && !@collection.parent && @collection.user_is_maintainer?(current_user) %>
<li><%= link_to t(".navigation.actions.new_subcollection"), new_collection_collection_path(@collection) %></li>
<% else %>
<li><%= link_to t(".navigation.actions.new_collection"), new_collection_path %></li>
<% end %>
<% end %>
<% end %>
<% if @sort_and_filter %>
<% # Filters button for narrow screens jumps to filters when JavaScript is disabled and opens filters when JavaScript is enabled %>
<li class="narrow-shown hidden"><a href="#collection-filters" id="go_to_filters"><%= ts("Filters") %></a></li>
<% end %>
</ul>
<% if @sort_and_filter %>
<%# Filters button for narrow screens jumps to filters when JavaScript is disabled and opens filters when JavaScript is enabled %>
<li class="narrow-shown hidden"><a href="#collection-filters" id="go_to_filters"><%= t(".navigation.actions.filters") %></a></li>
<% end %>
</ul>
</div>

<% unless @collections.blank? %>
<!--pagination here-->
<%= will_paginate @collections %>

<!--main content-->
<h3 class="landmark heading"><%= ts("List of Collections") %></h3>
<h3 class="landmark heading"><%= t(".main_content.landmark_heading") %></h3>
<ul class="collection picture index group">
<% @collections.each do |collection| %>
<%= render :partial => "collection_blurb", :locals => {:collection => collection} %>
Expand Down
13 changes: 13 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,23 @@ en:
footnote: Use this if your collection is not fandom-specific.
label: Multifandom
index:
main_content:
landmark_heading: List of Collections
navigation:
actions:
collections: Collections
filters: Filters
manage_items: Manage Collection Items
new_collection: New Collection
new_subcollection: New Subcollection
open_challenges: Open Challenges
landmark_heading: Navigation
page_heading:
challenges_subcollections_in: Challenges/Subcollections in %{collection}
collections_in_the: Collections in the %{archive}
collections_including: Collections including %{work}
no_results: Sorry, there were no collections found.
search_header: Collection
users_collections: "%{user}'s Collections"
sidebar:
bookmarks: Bookmarked Items (%{count})
Expand Down
17 changes: 15 additions & 2 deletions features/search/filters.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@users
Feature: Filters
In order to ensure filtering works on works and bookmarks
In order to ensure filtering works on works, bookmarks and collections
As a humble user
I want to filter on a user's works and bookmarks
I want to filter on a user's works, bookmarks and collections

Background:
Given a canonical fandom "The Hobbit"
Expand Down Expand Up @@ -352,3 +352,16 @@ Feature: Filters
When I fill in "work_search_query" with "bad~query!!!"
And I press "Sort and Filter"
Then I should see "Your search failed because of a syntax error"

@javascript
@collections
Scenario: Filtering on a user collection page should only return collections by that user.
Given a collection "Duplicate Name" with name "collection1" owned by "meatloaf"
And a collection "Duplicate Name" with name "collection2" owned by "recengine"
And a collection "The Hobbits" with name "collectionhobbit" owned by "recengine"
And all indexing jobs have been run
When I go to recengine's user page
And I follow "Collections (2)"
And I fill in "Filter by title" with "Duplicate Name"
And I press "Sort and Filter"
Then I should see "1 Collection"
17 changes: 10 additions & 7 deletions features/step_definitions/collection_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
collection.collection_preference.update_attribute(:closed, true) if closed.present?
end

Given "a collection {string} with name {string} owned by {string}" do |title, name, owner|
user = ensure_user(owner)
FactoryBot.create(:collection, title: title, name: (name.presence || title.gsub(/[^\w]/, "_")), owner: user.default_pseud)
end

Given /^I open the collection with the title "([^\"]*)"$/ do |title|
step %{I am logged in as "moderator"}
visit collection_path(Collection.find_by(title: title))
Expand All @@ -107,7 +112,7 @@
visit collection_path(Collection.find_by(title: title))
click_link("Membership")
step %{I fill in "participants_to_invite" with "#{name}"}
step %{I press "Submit"}
step %{I press "Submit"}

step %{I select "Moderator" from "#{name}_role"}
# TODO: fix the form, it is malformed right now
Expand Down Expand Up @@ -178,21 +183,19 @@

When /^I set up (?:a|the) collection "([^"]*)"(?: with name "([^"]*)")?$/ do |title, name|
visit new_collection_path
fill_in("collection_name", with: (name.blank? ? title.gsub(/[^\w]/, '_') : name))
fill_in("collection_name", with: (name.presence || title.gsub(/[^\w]/, "_")))
fill_in("collection_title", with: title)
end

When /^I create (?:a|the) collection "([^"]*)"(?: with name "([^"]*)")?$/ do |title, name|
name = title.gsub(/[^\w]/, '_') if name.blank?
name = title.gsub(/[^\w]/, "_") if name.blank?
step %{I set up the collection "#{title}" with name "#{name}"}
step %{I submit}
end

When /^I add (?:a|the) subcollection "([^"]*)"(?: with name "([^"]*)")? to (?:a|the) parent collection named "([^"]*)"$/ do |title, name, parent_name|
if Collection.find_by_name(parent_name).nil?
step %{I create the collection "#{parent_name}" with name "#{parent_name}"}
end
name = title.gsub(/[^\w]/, '_') if name.blank?
step %{I create the collection "#{parent_name}" with name "#{parent_name}"} if Collection.find_by_name(parent_name).nil?
name = title.gsub(/[^\w]/, "_") if name.blank?
step %{I set up the collection "#{title}" with name "#{name}"}
fill_in("collection_parent_name", with: parent_name)
step %{I submit}
Expand Down
5 changes: 0 additions & 5 deletions public/stylesheets/site/2.0/17-zone-home.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ user home, collections and challenges home, tag home, admin comms home
float: none;
}

/* (no filters) */

.dashboard.collections-index .index {
width: 100%;
}

.dashboard.works-index h4.landmark, .dashboard.works-index ol.pagination {
float: left;
Expand Down
Loading