Commit a72f4630 authored by Felipe Artur's avatar Felipe Artur

Add sort by weight in issuable filter

parent ee858d71
......@@ -14,7 +14,9 @@ module SortingHelper
sort_value_recently_signin => sort_title_recently_signin,
sort_value_oldest_signin => sort_title_oldest_signin,
sort_value_downvotes => sort_title_downvotes,
sort_value_upvotes => sort_title_upvotes
sort_value_upvotes => sort_title_upvotes,
sort_value_more_weight => sort_title_more_weight,
sort_value_less_weight => sort_title_less_weight
}
end
......@@ -84,6 +86,14 @@ module SortingHelper
'Most popular'
end
def sort_title_more_weight
'More weight'
end
def sort_title_less_weight
'Less weight'
end
def sort_value_oldest_updated
'updated_asc'
end
......@@ -139,4 +149,12 @@ module SortingHelper
def sort_value_upvotes
'upvotes_desc'
end
def sort_value_more_weight
'weight_desc'
end
def sort_value_less_weight
'weight_asc'
end
end
......@@ -38,6 +38,8 @@ module Issuable
scope :order_milestone_due_desc, -> { joins(:milestone).reorder('milestones.due_date DESC, milestones.id DESC') }
scope :order_milestone_due_asc, -> { joins(:milestone).reorder('milestones.due_date ASC, milestones.id ASC') }
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
scope :order_weight_desc, -> { reorder('CASE WHEN weight IS NULL then 0 ELSE 1 END DESC, weight DESC') }
scope :order_weight_asc, -> { reorder('weight ASC') }
scope :join_project, -> { joins(:project) }
scope :references_project, -> { references(:project) }
......@@ -94,6 +96,8 @@ module Issuable
when 'milestone_due_desc' then order_milestone_due_desc
when 'downvotes_desc' then order_downvotes_desc
when 'upvotes_desc' then order_upvotes_desc
when 'weight_desc' then order_weight_desc
when 'weight_asc' then order_weight_asc
else
order_by(method)
end
......
......@@ -16,6 +16,10 @@
= sort_title_recently_updated
= link_to page_filter_path(sort: sort_value_oldest_updated) do
= sort_title_oldest_updated
= link_to page_filter_path(sort: sort_value_more_weight) do
= sort_title_more_weight
= link_to page_filter_path(sort: sort_value_less_weight) do
= sort_title_less_weight
= link_to page_filter_path(sort: sort_value_milestone_soon) do
= sort_title_milestone_soon
= link_to page_filter_path(sort: sort_value_milestone_later) do
......
......@@ -114,6 +114,25 @@ describe Issue, "Issuable" do
end
end
describe "#sort" do
let!(:issue) { create(:issue) }
let(:project) { issue.project }
let!(:issue2) { create(:issue, weight: 1, project: project) }
let!(:issue3) { create(:issue, weight: 2, project: project) }
let!(:issue4) { create(:issue, weight: 3, project: project) }
it "sorts by weight desc" do
issues = Issue.where(project_id: project.id).sort('weight_desc')
expect(issues).to match_array([issue4, issue3, issue2, issue])
end
it "sorts by weight asc" do
issues = Issue.where(project_id: project.id).sort('weight_asc')
expect(issues).to match_array([issue2, issue3, issue4, issue])
end
end
describe '#subscribed?' do
context 'user is not a participant in the issue' do
before { allow(issue).to receive(:participants).with(user).and_return([]) }
......
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