Commit b85e4d3c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move issues sort logic to Issuable concern

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent adf6ee09
...@@ -31,23 +31,9 @@ module Issues ...@@ -31,23 +31,9 @@ module Issues
end end
# Sort by :sort param # Sort by :sort param
@issues = sort(@issues, params[:sort]) @issues = @issues.sort(params[:sort])
@issues @issues
end end
private
def sort(issues, condition)
case condition
when 'newest' then issues.except(:order).order('created_at DESC')
when 'oldest' then issues.except(:order).order('created_at ASC')
when 'recently_updated' then issues.except(:order).order('updated_at DESC')
when 'last_updated' then issues.except(:order).order('updated_at ASC')
when 'milestone_due_soon' then issues.except(:order).joins(:milestone).order("milestones.due_date ASC")
when 'milestone_due_later' then issues.except(:order).joins(:milestone).order("milestones.due_date DESC")
else issues
end
end
end end
end end
...@@ -45,6 +45,18 @@ module Issuable ...@@ -45,6 +45,18 @@ module Issuable
def search(query) def search(query)
where("title like :query", query: "%#{query}%") where("title like :query", query: "%#{query}%")
end end
def sort(method)
case method.to_s
when 'newest' then reorder('created_at DESC')
when 'oldest' then reorder('created_at ASC')
when 'recently_updated' then reorder('updated_at DESC')
when 'last_updated' then reorder('updated_at ASC')
when 'milestone_due_soon' then joins(:milestone).reorder("milestones.due_date ASC")
when 'milestone_due_later' then joins(:milestone).reorder("milestones.due_date DESC")
else reorder('created_at DESC')
end
end
end end
def today? def today?
......
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