Move issues sort logic to Issuable concern
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
adf6ee09b0
commit
b85e4d3cbd
2 changed files with 13 additions and 15 deletions
|
@ -31,23 +31,9 @@ module Issues
|
|||
end
|
||||
|
||||
# Sort by :sort param
|
||||
@issues = sort(@issues, params[:sort])
|
||||
@issues = @issues.sort(params[:sort])
|
||||
|
||||
@issues
|
||||
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
|
||||
|
|
|
@ -45,6 +45,18 @@ module Issuable
|
|||
def search(query)
|
||||
where("title like :query", query: "%#{query}%")
|
||||
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
|
||||
|
||||
def today?
|
||||
|
|
Loading…
Reference in a new issue