Commit b85e4d3cbdab72ce1b52b409a28081b776f37659
1 parent
adf6ee09
Exists in
spb-stable
and in
3 other branches
Move issues sort logic to Issuable concern
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
13 additions
and
15 deletions
Show diff stats
app/contexts/issues/list_context.rb
... | ... | @@ -31,23 +31,9 @@ module Issues |
31 | 31 | end |
32 | 32 | |
33 | 33 | # Sort by :sort param |
34 | - @issues = sort(@issues, params[:sort]) | |
34 | + @issues = @issues.sort(params[:sort]) | |
35 | 35 | |
36 | 36 | @issues |
37 | 37 | end |
38 | - | |
39 | - private | |
40 | - | |
41 | - def sort(issues, condition) | |
42 | - case condition | |
43 | - when 'newest' then issues.except(:order).order('created_at DESC') | |
44 | - when 'oldest' then issues.except(:order).order('created_at ASC') | |
45 | - when 'recently_updated' then issues.except(:order).order('updated_at DESC') | |
46 | - when 'last_updated' then issues.except(:order).order('updated_at ASC') | |
47 | - when 'milestone_due_soon' then issues.except(:order).joins(:milestone).order("milestones.due_date ASC") | |
48 | - when 'milestone_due_later' then issues.except(:order).joins(:milestone).order("milestones.due_date DESC") | |
49 | - else issues | |
50 | - end | |
51 | - end | |
52 | 38 | end |
53 | 39 | end | ... | ... |
app/models/concerns/issuable.rb
... | ... | @@ -45,6 +45,18 @@ module Issuable |
45 | 45 | def search(query) |
46 | 46 | where("title like :query", query: "%#{query}%") |
47 | 47 | end |
48 | + | |
49 | + def sort(method) | |
50 | + case method.to_s | |
51 | + when 'newest' then reorder('created_at DESC') | |
52 | + when 'oldest' then reorder('created_at ASC') | |
53 | + when 'recently_updated' then reorder('updated_at DESC') | |
54 | + when 'last_updated' then reorder('updated_at ASC') | |
55 | + when 'milestone_due_soon' then joins(:milestone).reorder("milestones.due_date ASC") | |
56 | + when 'milestone_due_later' then joins(:milestone).reorder("milestones.due_date DESC") | |
57 | + else reorder('created_at DESC') | |
58 | + end | |
59 | + end | |
48 | 60 | end |
49 | 61 | |
50 | 62 | def today? | ... | ... |