Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,24 @@ def index
def list_challenges
@page_subtitle = "Open Challenges"
@hide_dashboard = true

@challenge_collections = (CollectionSearchForm.new(challenge_type: "GiftExchange", signup_open: true, sort_column: "signups_close_at", page: 1, per_page: 15).search_results.to_a +
CollectionSearchForm.new(challenge_type: "PromptMeme", signup_open: true, sort_column: "signups_close_at", page: 1, per_page: 15).search_results.to_a)
@sort_and_filter = true
@show_type_filter = true
@search = CollectionSearchForm.new(challenge_filter_params.merge(signup_open: true, sort_column: "signups_close_at", page: params[:page]))
@challenge_collections = @search.search_results
end

def list_ge_challenges
@page_subtitle = "Open Gift Exchange Challenges"
@challenge_collections = CollectionSearchForm.new(challenge_type: "GiftExchange", signup_open: true, sort_column: "signups_close_at", page: 1, per_page: 15).search_results
@sort_and_filter = true
@search = CollectionSearchForm.new(challenge_filter_params.merge(challenge_type: "GiftExchange", signup_open: true, sort_column: "signups_close_at", page: params[:page]))
@challenge_collections = @search.search_results
end

def list_pm_challenges
@page_subtitle = "Open Prompt Meme Challenges"
@challenge_collections = CollectionSearchForm.new(challenge_type: "PromptMeme", signup_open: true, sort_column: "signups_close_at", page: 1, per_page: 15).search_results
@sort_and_filter = true
@search = CollectionSearchForm.new(challenge_filter_params.merge(challenge_type: "PromptMeme", signup_open: true, sort_column: "signups_close_at", page: params[:page]))
@challenge_collections = @search.search_results
end

def show
Expand Down Expand Up @@ -215,4 +220,10 @@ def collection_params
]
)
end

def challenge_filter_params
params.permit(:commit, collection_search: [
:title, :tag, :challenge_type, :moderated, :multifandom, :closed
])[:collection_search] || {}
end
end
6 changes: 5 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ def classes_for_main
class_names
end

COLLECTION_FILTER_ACTIONS = %w[index list_challenges list_ge_challenges list_pm_challenges].freeze

def page_has_filters?
@facets.present? || (controller.action_name == 'index' && controller.controller_name == 'collections') || (controller.action_name == 'unassigned' && controller.controller_name == 'fandoms')
@facets.present? || # rubocop:disable Rails/HelperInstanceVariable
(controller.controller_name == "collections" && COLLECTION_FILTER_ACTIONS.include?(controller.action_name)) ||
(controller.controller_name == "fandoms" && controller.action_name == "unassigned")
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
Expand Down
7 changes: 6 additions & 1 deletion app/models/search/collection_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def signup_open_filter
end

def signup_closes_in_future_filter
{ range: { signups_close_at: { gt: "now" } } } if options[:signup_open].present?
return if options[:signup_open].blank?

{ bool: { should: [
{ range: { signups_close_at: { gt: "now" } } },
{ bool: { must_not: { exists: { field: "signups_close_at" } } } }
] } }
end

def closed_filter
Expand Down
29 changes: 23 additions & 6 deletions app/views/collections/_challenge_collections.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
<% if @challenge_collections.blank? %>
<p class="notes"><%= ts("There are no challenges currently open for sign-ups in the archive.") %></p>
<% else %>
<p class="notes"><%= ts("The following challenges are currently open for sign-ups! Those closing soonest are at the top.") %></p>
<h3 class="heading">
<% if @challenge_collections.blank? %>
<%= t("collections.challenge_collections.no_challenges") %>
<% else %>
<%= search_header @challenge_collections, @query, t("collections.challenge_collections.search_header_label") %>
<% end %>
</h3>

<% unless @challenge_collections.blank? %>
<p class="notes"><%= t("collections.challenge_collections.open_description") %></p>

<%= will_paginate @challenge_collections %>

<h3 class="landmark heading"><%= ts("List of Collections") %></h3>
<h3 class="landmark heading"><%= t("collections.challenge_collections.list_heading") %></h3>
<ul class="collection picture index group">
<% @challenge_collections.each do |collection| %>
<%= render :partial => "collection_blurb", :locals => {:collection => collection} %>
<% end %>
</ul>
<% end %>

<% end %>

<% if @sort_and_filter %>
<%= render "challenge_filters" %>
<% end %>

<% unless @challenge_collections.blank? %>
<%= will_paginate @challenge_collections %>
<% end %>
132 changes: 132 additions & 0 deletions app/views/collections/_challenge_filters.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<%= form_for @search, as: :collection_search, url: request.path, html: { method: :get, class: "narrow-hidden filters", id: "collection-filters" } do |f| %>
<h3 class="landmark heading"><%= t("collections.filters.landmark") %></h3>
<%= field_set_tag t("collections.filters.legend") do %>
<dl>
<dt class="landmark"><%= t("collections.filters.submit.landmark") %></dt>
<dd class="submit actions"><%= submit_tag t("collections.filters.submit.button") %></dd>

<dt class="autocomplete search">
<%= f.label "title", t("collections.filters.title") %>
</dt>
<dd class="autocomplete search">
<%= f.text_field "title", autocomplete_options("collection_title", data: { autocomplete_token_limit: 1 }) %>
</dd>

<dt class="autocomplete search">
<%= f.label "tag", t("collections.filters.tag") %>
</dt>
<dd class="autocomplete search">
<%= f.text_field "tag", autocomplete_options("tag", data: { autocomplete_token_limit: 5 }) %>
</dd>

<dt><%= t("collections.filters.multifandom.label") %></dt>
<dd>
<ul>
<li>
<%= f.label "multifandom", value: true do %>
<%= f.radio_button "multifandom", true %>
<%= label_indicator_and_text(t("collections.filters.multifandom.only")) %>
<% end %>
</li>
<li>
<%= f.label "multifandom", value: false do %>
<%= f.radio_button "multifandom", false %>
<%= label_indicator_and_text(t("collections.filters.multifandom.exclude")) %>
<% end %>
</li>
<li>
<%= f.label "multifandom", value: "" do %>
<%= f.radio_button "multifandom", "" %>
<%= label_indicator_and_text(t("collections.filters.multifandom.include")) %>
<% end %>
</li>
</ul>
</dd>

<dt><%= t("collections.filters.closed.label") %></dt>
<dd>
<ul>
<li>
<%= f.label "closed", value: true do %>
<%= f.radio_button "closed", true %>
<%= label_indicator_and_text(t("collections.filters.closed.only")) %>
<% end %>
</li>
<li>
<%= f.label "closed", value: false do %>
<%= f.radio_button "closed", false %>
<%= label_indicator_and_text(t("collections.filters.closed.exclude")) %>
<% end %>
</li>
<li>
<%= f.label "closed", value: "" do %>
<%= f.radio_button "closed", "" %>
<%= label_indicator_and_text(t("collections.filters.closed.include")) %>
<% end %>
</li>
</ul>
</dd>

<dt><%= t("collections.filters.moderated.label") %></dt>
<dd>
<ul>
<li>
<%= f.label "moderated", value: true do %>
<%= f.radio_button "moderated", true %>
<%= label_indicator_and_text(t("collections.filters.moderated.only")) %>
<% end %>
</li>
<li>
<%= f.label "moderated", value: false do %>
<%= f.radio_button "moderated", false %>
<%= label_indicator_and_text(t("collections.filters.moderated.exclude")) %>
<% end %>
</li>
<li>
<%= f.label "moderated", value: "" do %>
<%= f.radio_button "moderated", "" %>
<%= label_indicator_and_text(t("collections.filters.moderated.include")) %>
<% end %>
</li>
</ul>
</dd>

<% if @show_type_filter %>
<dt><%= t("collections.filters.type.label") %></dt>
<dd>
<ul>
<li>
<%= f.label "challenge_type", value: "GiftExchange" do %>
<%= f.radio_button "challenge_type", "GiftExchange" %>
<%= label_indicator_and_text(t("collections.filters.type.gift_exchange")) %>
<% end %>
</li>
<li>
<%= f.label "challenge_type", value: "PromptMeme" do %>
<%= f.radio_button "challenge_type", "PromptMeme" %>
<%= label_indicator_and_text(t("collections.filters.type.prompt_meme")) %>
<% end %>
</li>
<li>
<%= f.label "challenge_type", value: "" do %>
<%= f.radio_button "challenge_type", "" %>
<%= label_indicator_and_text(t("collections.filters.type.any")) %>
<% end %>
</li>
</ul>
</dd>
<% end %>

<dt class="landmark"><%= t("collections.filters.submit.landmark") %></dt>
<dd class="submit actions"><%= submit_tag t("collections.filters.submit.button") %></dd>
</dl>
<p class="footnote">
<%= link_to t("collections.filters.clear_filters"), request.path %>
</p>
<% end %>
<p class="narrow-shown hidden">
<a href="#main" id="leave_filters" class="close">
<%= t("collections.filters.leave_filters") %>
</a>
</p>
<% end %>
5 changes: 5 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,11 @@ en:
meta:
collection_tags: 'Collection tags:'
collections:
challenge_collections:
list_heading: List of Challenges
no_challenges: There are no challenges currently open for sign-ups in the archive.
open_description: The following challenges are currently open for sign-ups! Those closing soonest are at the top.
search_header_label: Challenge
collection_blurb:
collection_tags: 'Collection Tags:'
filters:
Expand Down
Loading
Loading