diff options
author | Alex Clifford <alex@silverstripe.com.au> | 2017-01-25 14:56:43 +0100 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2017-01-25 15:56:56 +0100 |
commit | 32944bbaa506eaa523f331610ebe4f4dab56aadc (patch) | |
tree | ef777a891fa089d7af5eb06322706f41e7888c31 | |
parent | 1e64882da165bc872f5ce487775addf7347779f2 (diff) | |
download | gitlab-ce-adam-sort-by-comments.tar.gz |
Allow sorting by most or least comments on Issues and Merge Requestsadam-sort-by-comments
-rw-r--r-- | app/helpers/sorting_helper.rb | 20 | ||||
-rw-r--r-- | app/models/concerns/issuable.rb | 25 | ||||
-rw-r--r-- | app/views/shared/_sort_dropdown.html.haml | 4 | ||||
-rw-r--r-- | changelogs/unreleased/adam-sort-by-comments.yml | 4 |
4 files changed, 52 insertions, 1 deletions
diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index ff787fb4131..3239d0552b7 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -16,7 +16,9 @@ module SortingHelper sort_value_oldest_signin => sort_title_oldest_signin, sort_value_downvotes => sort_title_downvotes, sort_value_upvotes => sort_title_upvotes, - sort_value_priority => sort_title_priority + sort_value_priority => sort_title_priority, + sort_value_most_comments => sort_title_most_comments, + sort_value_least_comments => sort_title_least_comments } end @@ -137,6 +139,14 @@ module SortingHelper 'Name, descending' end + def sort_title_most_comments + 'Most comments' + end + + def sort_title_least_comments + 'Least comments' + end + def sort_value_last_joined 'last_joined' end @@ -220,4 +230,12 @@ module SortingHelper def sort_value_upvotes 'upvotes_desc' end + + def sort_value_most_comments + 'comments_desc' + end + + def sort_value_least_comments + 'comments_asc' + end end diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 3517969eabc..94f05e7285f 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -139,6 +139,8 @@ module Issuable when 'downvotes_desc' then order_downvotes_desc when 'upvotes_desc' then order_upvotes_desc when 'priority' then order_labels_priority(excluded_labels: excluded_labels) + when 'comments_desc' then order_most_comments + when 'comments_asc' then order_least_comments else order_by(method) end @@ -189,6 +191,29 @@ module Issuable def to_ability_name model_name.singular end + + def order_most_comments + order_comments('DESC') + end + + def order_least_comments + order_comments('ASC') + end + + def order_comments(comments_order) + issuable_table = self.arel_table + note_table = Note.arel_table + + join_clause = issuable_table.join(note_table, Arel::Nodes::OuterJoin).on( + note_table[:noteable_id].eq(issuable_table[:id]).and( + note_table[:noteable_type].eq(self.name).and( + note_table[:system].eq(false) + ) + ) + ).join_sources + + joins(join_clause).group(issuable_table[:id]).reorder("COUNT(notes.id) " + comments_order) + end end def today? diff --git a/app/views/shared/_sort_dropdown.html.haml b/app/views/shared/_sort_dropdown.html.haml index 0ce0d759e86..c00ddf2db41 100644 --- a/app/views/shared/_sort_dropdown.html.haml +++ b/app/views/shared/_sort_dropdown.html.haml @@ -31,3 +31,7 @@ = sort_title_upvotes = link_to page_filter_path(sort: sort_value_downvotes, label: true) do = sort_title_downvotes + = link_to page_filter_path(sort: sort_value_most_comments, label: true) do + = sort_title_most_comments + = link_to page_filter_path(sort: sort_value_least_comments, label: true) do + = sort_title_least_comments diff --git a/changelogs/unreleased/adam-sort-by-comments.yml b/changelogs/unreleased/adam-sort-by-comments.yml new file mode 100644 index 00000000000..61b3fcdcf87 --- /dev/null +++ b/changelogs/unreleased/adam-sort-by-comments.yml @@ -0,0 +1,4 @@ +--- +title: Allow sorting by most or least comments on Issues +merge_request: 8783 +author: Alex Clifford |