Commit 300745c6 authored by Mario de la Ossa's avatar Mario de la Ossa Committed by Jose Vargas

Bring back asc/desc sort orders for Issues/MRs

parent 60fb3ff6
...@@ -167,12 +167,6 @@ module IssuableCollections ...@@ -167,12 +167,6 @@ module IssuableCollections
case value case value
when 'id_asc' then sort_value_oldest_created when 'id_asc' then sort_value_oldest_created
when 'id_desc' then sort_value_recently_created when 'id_desc' then sort_value_recently_created
when 'created_asc' then sort_value_created_date
when 'created_desc' then sort_value_created_date
when 'due_date_asc' then sort_value_due_date
when 'due_date_desc' then sort_value_due_date
when 'milestone_due_asc' then sort_value_milestone
when 'milestone_due_desc' then sort_value_milestone
when 'downvotes_asc' then sort_value_popularity when 'downvotes_asc' then sort_value_popularity
when 'downvotes_desc' then sort_value_popularity when 'downvotes_desc' then sort_value_popularity
else value else value
......
...@@ -43,14 +43,19 @@ module Awardable ...@@ -43,14 +43,19 @@ module Awardable
end end
def order_upvotes_desc def order_upvotes_desc
order_votes_desc(AwardEmoji::UPVOTE_NAME) order_votes(AwardEmoji::UPVOTE_NAME, 'DESC')
end
def order_upvotes_asc
order_votes(AwardEmoji::UPVOTE_NAME, 'ASC')
end end
def order_downvotes_desc def order_downvotes_desc
order_votes_desc(AwardEmoji::DOWNVOTE_NAME) order_votes(AwardEmoji::DOWNVOTE_NAME, 'DESC')
end end
def order_votes_desc(emoji_name) # Order votes by emoji, optional sort order param `descending` defaults to true
def order_votes(emoji_name, direction)
awardable_table = self.arel_table awardable_table = self.arel_table
awards_table = AwardEmoji.arel_table awards_table = AwardEmoji.arel_table
...@@ -62,7 +67,7 @@ module Awardable ...@@ -62,7 +67,7 @@ module Awardable
) )
).join_sources ).join_sources
joins(join_clause).group(awardable_table[:id]).reorder("COUNT(award_emoji.id) DESC") joins(join_clause).group(awardable_table[:id]).reorder("COUNT(award_emoji.id) #{direction}")
end end
end end
......
...@@ -145,14 +145,20 @@ module Issuable ...@@ -145,14 +145,20 @@ module Issuable
def sort_by_attribute(method, excluded_labels: []) def sort_by_attribute(method, excluded_labels: [])
sorted = sorted =
case method.to_s case method.to_s
when 'downvotes_desc' then order_downvotes_desc when 'downvotes_desc' then order_downvotes_desc
when 'label_priority' then order_labels_priority(excluded_labels: excluded_labels) when 'label_priority' then order_labels_priority(excluded_labels: excluded_labels)
when 'milestone' then order_milestone_due_asc when 'label_priority_asc' then order_labels_priority(excluded_labels: excluded_labels)
when 'milestone_due_asc' then order_milestone_due_asc when 'label_priority_desc' then order_labels_priority('DESC', excluded_labels: excluded_labels)
when 'milestone_due_desc' then order_milestone_due_desc when 'milestone' then order_milestone_due_asc
when 'popularity' then order_upvotes_desc when 'milestone_due_asc' then order_milestone_due_asc
when 'priority' then order_due_date_and_labels_priority(excluded_labels: excluded_labels) when 'milestone_due_desc' then order_milestone_due_desc
when 'upvotes_desc' then order_upvotes_desc when 'popularity' then order_upvotes_desc
when 'popularity_desc' then order_upvotes_desc
when 'popularity_asc' then order_upvotes_asc
when 'priority' then order_due_date_and_labels_priority(excluded_labels: excluded_labels)
when 'priority_asc' then order_due_date_and_labels_priority(excluded_labels: excluded_labels)
when 'priority_desc' then order_due_date_and_labels_priority('DESC', excluded_labels: excluded_labels)
when 'upvotes_desc' then order_upvotes_desc
else order_by(method) else order_by(method)
end end
...@@ -160,7 +166,7 @@ module Issuable ...@@ -160,7 +166,7 @@ module Issuable
sorted.with_order_id_desc sorted.with_order_id_desc
end end
def order_due_date_and_labels_priority(excluded_labels: []) def order_due_date_and_labels_priority(direction = 'ASC', excluded_labels: [])
# The order_ methods also modify the query in other ways: # The order_ methods also modify the query in other ways:
# #
# - For milestones, we add a JOIN. # - For milestones, we add a JOIN.
...@@ -177,11 +183,11 @@ module Issuable ...@@ -177,11 +183,11 @@ module Issuable
order_milestone_due_asc order_milestone_due_asc
.order_labels_priority(excluded_labels: excluded_labels, extra_select_columns: [milestones_due_date]) .order_labels_priority(excluded_labels: excluded_labels, extra_select_columns: [milestones_due_date])
.reorder(Gitlab::Database.nulls_last_order(milestones_due_date, 'ASC'), .reorder(Gitlab::Database.nulls_last_order(milestones_due_date, direction),
Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) Gitlab::Database.nulls_last_order('highest_priority', direction))
end end
def order_labels_priority(excluded_labels: [], extra_select_columns: []) def order_labels_priority(direction = 'ASC', excluded_labels: [], extra_select_columns: [])
params = { params = {
target_type: name, target_type: name,
target_column: "#{table_name}.id", target_column: "#{table_name}.id",
...@@ -198,7 +204,7 @@ module Issuable ...@@ -198,7 +204,7 @@ module Issuable
select(select_columns.join(', ')) select(select_columns.join(', '))
.group(arel_table[:id]) .group(arel_table[:id])
.reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) .reorder(Gitlab::Database.nulls_last_order('highest_priority', direction))
end end
def with_label(title, sort = nil) def with_label(title, sort = nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment