Commit 6153aa136007daa4b5c592190b72de389de8b032
1 parent
5e96ee34
Exists in
spb-stable
and in
3 other branches
Use FilteringService for Dashboard, Group pages
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
32 additions
and
21 deletions
Show diff stats
app/controllers/dashboard_controller.rb
... | ... | @@ -3,6 +3,8 @@ class DashboardController < ApplicationController |
3 | 3 | |
4 | 4 | before_filter :load_projects, except: [:projects] |
5 | 5 | before_filter :event_filter, only: :show |
6 | + before_filter :default_filter, only: [:issues, :merge_requests] | |
7 | + | |
6 | 8 | |
7 | 9 | def show |
8 | 10 | # Fetch only 30 projects. |
... | ... | @@ -51,12 +53,12 @@ class DashboardController < ApplicationController |
51 | 53 | end |
52 | 54 | |
53 | 55 | def merge_requests |
54 | - @merge_requests = FilterContext.new(MergeRequest, current_user, params).execute | |
56 | + @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params) | |
55 | 57 | @merge_requests = @merge_requests.recent.page(params[:page]).per(20) |
56 | 58 | end |
57 | 59 | |
58 | 60 | def issues |
59 | - @issues = FilterContext.new(Issue, current_user, params).execute | |
61 | + @issues = FilteringService.new.execute(Issue, current_user, params) | |
60 | 62 | @issues = @issues.recent.page(params[:page]).per(20) |
61 | 63 | @issues = @issues.includes(:author, :project) |
62 | 64 | |
... | ... | @@ -71,4 +73,9 @@ class DashboardController < ApplicationController |
71 | 73 | def load_projects |
72 | 74 | @projects = current_user.authorized_projects.sorted_by_activity.non_archived |
73 | 75 | end |
76 | + | |
77 | + def default_filter | |
78 | + params[:scope] = 'assigned-to-me' if params[:scope].blank? | |
79 | + params[:state] = 'opened' if params[:state].blank? | |
80 | + end | |
74 | 81 | end | ... | ... |
app/controllers/groups_controller.rb
... | ... | @@ -10,6 +10,8 @@ class GroupsController < ApplicationController |
10 | 10 | # Load group projects |
11 | 11 | before_filter :projects, except: [:new, :create] |
12 | 12 | |
13 | + before_filter :default_filter, only: [:issues, :merge_requests] | |
14 | + | |
13 | 15 | layout :determine_layout |
14 | 16 | |
15 | 17 | before_filter :set_title, only: [:new, :create] |
... | ... | @@ -43,18 +45,14 @@ class GroupsController < ApplicationController |
43 | 45 | end |
44 | 46 | end |
45 | 47 | |
46 | - # Get authored or assigned open merge requests | |
47 | 48 | def merge_requests |
48 | - @merge_requests = FilterContext.new(MergeRequest, current_user, params).execute | |
49 | - @merge_requests = @merge_requests.of_group(@group) | |
50 | - @merge_requests = @merge_requests.recent.page(params[:page]).per(20) | |
49 | + @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params) | |
50 | + @merge_requests = @merge_requests.page(params[:page]).per(20) | |
51 | 51 | end |
52 | 52 | |
53 | - # Get only assigned issues | |
54 | 53 | def issues |
55 | - @issues = FilterContext.new(Issue, current_user, params).execute | |
56 | - @issues = @issues.of_group(@group) | |
57 | - @issues = @issues.recent.page(params[:page]).per(20) | |
54 | + @issues = FilteringService.new.execute(Issue, current_user, params) | |
55 | + @issues = @issues.page(params[:page]).per(20) | |
58 | 56 | @issues = @issues.includes(:author, :project) |
59 | 57 | |
60 | 58 | respond_to do |format| |
... | ... | @@ -130,4 +128,10 @@ class GroupsController < ApplicationController |
130 | 128 | 'group' |
131 | 129 | end |
132 | 130 | end |
131 | + | |
132 | + def default_filter | |
133 | + params[:scope] = 'assigned-to-me' if params[:scope].blank? | |
134 | + params[:state] = 'opened' if params[:state].blank? | |
135 | + params[:group_id] = @group.id | |
136 | + end | |
133 | 137 | end | ... | ... |
app/helpers/dashboard_helper.rb
app/views/shared/_filter.html.haml
... | ... | @@ -2,8 +2,8 @@ |
2 | 2 | = form_tag filter_path(entity), method: 'get' do |
3 | 3 | %fieldset.scope-filter |
4 | 4 | %ul.nav.nav-pills.nav-stacked |
5 | - %li{class: ("active" if params[:scope].blank?)} | |
6 | - = link_to filter_path(entity, scope: nil) do | |
5 | + %li{class: ("active" if params[:scope] == 'assigned-to-me')} | |
6 | + = link_to filter_path(entity, scope: 'assigned-to-me') do | |
7 | 7 | Assigned to me |
8 | 8 | %li{class: ("active" if params[:scope] == 'authored')} |
9 | 9 | = link_to filter_path(entity, scope: 'authored') do |
... | ... | @@ -15,14 +15,14 @@ |
15 | 15 | %fieldset.status-filter |
16 | 16 | %legend State |
17 | 17 | %ul.nav.nav-pills |
18 | - %li{class: ("active" if params[:status].blank?)} | |
19 | - = link_to filter_path(entity, status: nil) do | |
18 | + %li{class: ("active" if params[:state] == 'opened')} | |
19 | + = link_to filter_path(entity, state: 'opened') do | |
20 | 20 | Open |
21 | - %li{class: ("active" if params[:status] == 'closed')} | |
22 | - = link_to filter_path(entity, status: 'closed') do | |
21 | + %li{class: ("active" if params[:state] == 'closed')} | |
22 | + = link_to filter_path(entity, state: 'closed') do | |
23 | 23 | Closed |
24 | - %li{class: ("active" if params[:status] == 'all')} | |
25 | - = link_to filter_path(entity, status: 'all') do | |
24 | + %li{class: ("active" if params[:state] == 'all')} | |
25 | + = link_to filter_path(entity, state: 'all') do | |
26 | 26 | All |
27 | 27 | |
28 | 28 | %fieldset |
... | ... | @@ -36,8 +36,8 @@ |
36 | 36 | %small.pull-right= entities_per_project(project, entity) |
37 | 37 | |
38 | 38 | %fieldset |
39 | - - if params[:status].present? || params[:project_id].present? | |
40 | - = link_to filter_path(entity, status: nil, project_id: nil), class: 'pull-right cgray' do | |
39 | + - if params[:state].present? || params[:project_id].present? | |
40 | + = link_to filter_path(entity, state: nil, project_id: nil), class: 'pull-right cgray' do | |
41 | 41 | %i.icon-remove |
42 | 42 | %strong Clear filter |
43 | 43 | ... | ... |