diff --git a/app/controllers/concerns/filter_scoped.rb b/app/controllers/concerns/filter_scoped.rb index 8e342afe7..6f2dd87de 100644 --- a/app/controllers/concerns/filter_scoped.rb +++ b/app/controllers/concerns/filter_scoped.rb @@ -13,7 +13,7 @@ module FilterScoped end private - DEFAULT_PARAMS = { indexed_by: "latest" } + DEFAULT_PARAMS = { indexed_by: "all", sorted_by: "latest" } def set_filter if params[:filter_id].present? diff --git a/app/models/card.rb b/app/models/card.rb index 0d0a458af..a429d7ae6 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -20,13 +20,20 @@ class Card < ApplicationRecord scope :indexed_by, ->(index) do case index + when "stalled" then stalled + when "closing_soon" then closing_soon + when "falling_back_soon" then falling_back_soon + when "closed" then closed.recently_closed_first + else all + end + end + + scope :sorted_by, ->(sort) do + case sort when "newest" then reverse_chronologically when "oldest" then chronologically when "latest" then latest - when "stalled" then stalled.chronologically - when "closing_soon" then closing_soon.chronologically - when "falling_back_soon" then falling_back_soon.chronologically - when "closed" then closed.recently_closed_first + else latest end end diff --git a/app/models/filter.rb b/app/models/filter.rb index 56f9c6be7..8b2a78e21 100644 --- a/app/models/filter.rb +++ b/app/models/filter.rb @@ -18,7 +18,7 @@ class Filter < ApplicationRecord def cards @cards ||= begin - result = creator.accessible_cards.indexed_by(indexed_by) + result = creator.accessible_cards.indexed_by(indexed_by).sorted_by(sorted_by) result = result.where(id: card_ids) if card_ids.present? result = result.open unless include_closed_cards? result = result.by_engagement_status(engagement_status) if engagement_status.present? diff --git a/app/models/filter/fields.rb b/app/models/filter/fields.rb index fcdde0346..cf7ce868f 100644 --- a/app/models/filter/fields.rb +++ b/app/models/filter/fields.rb @@ -1,13 +1,14 @@ module Filter::Fields extend ActiveSupport::Concern - INDEXES = %w[ newest oldest latest stalled closing_soon falling_back_soon ] + INDEXES = %w[ all stalled closing_soon falling_back_soon ] + SORTED_BY = %w[ newest oldest latest ] delegate :default_value?, to: :class class_methods do def default_values - { indexed_by: "latest" } + { indexed_by: "all", sorted_by: "latest" } end def default_value?(key, value) @@ -16,7 +17,7 @@ module Filter::Fields end included do - store_accessor :fields, :assignment_status, :indexed_by, :terms, + store_accessor :fields, :assignment_status, :indexed_by, :sorted_by, :terms, :engagement_status, :card_ids, :creation, :closure def assignment_status @@ -27,6 +28,10 @@ module Filter::Fields (super || default_indexed_by).inquiry end + def sorted_by + (super || default_sorted_by).inquiry + end + def engagement_status super&.inquiry end @@ -59,4 +64,12 @@ module Filter::Fields def default_indexed_by? default_value?(:indexed_by, indexed_by) end + + def default_sorted_by + self.class.default_values[:sorted_by] + end + + def default_sorted_by? + default_value?(:sorted_by, sorted_by) + end end diff --git a/app/models/filter/params.rb b/app/models/filter/params.rb index 21b0886bd..e7ee5a32b 100644 --- a/app/models/filter/params.rb +++ b/app/models/filter/params.rb @@ -4,6 +4,7 @@ module Filter::Params PERMITTED_PARAMS = [ :assignment_status, :indexed_by, + :sorted_by, :engagement_status, :creation, :closure, @@ -40,6 +41,7 @@ module Filter::Params def as_params {}.tap do |params| params[:indexed_by] = indexed_by + params[:sorted_by] = sorted_by params[:engagement_status] = engagement_status params[:creation] = creation params[:closure] = closure diff --git a/app/models/filter/summarized.rb b/app/models/filter/summarized.rb index e56a2dd10..22bc6bc5e 100644 --- a/app/models/filter/summarized.rb +++ b/app/models/filter/summarized.rb @@ -1,15 +1,21 @@ module Filter::Summarized def summary - [ index_summary, tag_summary, assignee_summary, creator_summary, stage_summary, terms_summary ].compact.to_sentence + [ index_summary, sort_summary, tag_summary, assignee_summary, creator_summary, stage_summary, terms_summary ].compact.to_sentence end private def index_summary - unless indexed_by.latest? + unless indexed_by.all? indexed_by.humanize end end + def sort_summary + unless sorted_by.latest? + sorted_by.humanize + end + end + def tag_summary if tags.any? "#{tags.map(&:hashtag).to_choice_sentence}" diff --git a/app/models/user/filtering.rb b/app/models/user/filtering.rb index 74c436801..448445c0b 100644 --- a/app/models/user/filtering.rb +++ b/app/models/user/filtering.rb @@ -44,11 +44,15 @@ class User::Filtering def any? filter.tags.any? || filter.assignees.any? || filter.creators.any? || filter.closers.any? || filter.stages.any? || filter.terms.any? || filter.card_ids&.any? || - filter.assignment_status.unassigned? || !filter.indexed_by.latest? + filter.assignment_status.unassigned? || !filter.indexed_by.all? || !filter.sorted_by.latest? end def show_indexed_by? - expanded? || !filter.indexed_by.latest? + expanded? || !filter.indexed_by.all? + end + + def show_sorted_by? + expanded? || !filter.sorted_by.latest? end def show_tags? @@ -67,10 +71,6 @@ class User::Filtering expanded? || filter.closers.any? end - def show_time_window?(name) - expanded? || filter.public_send("#{name}_window").present? - end - def enable_collection_filtering(&block) @collection_filtering_route_resolver = block end diff --git a/app/views/filters/_settings.html.erb b/app/views/filters/_settings.html.erb index 499878493..1ec499420 100644 --- a/app/views/filters/_settings.html.erb +++ b/app/views/filters/_settings.html.erb @@ -2,6 +2,7 @@