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,6 +3,8 @@ class DashboardController < ApplicationController | ||
3 | 3 | ||
4 | before_filter :load_projects, except: [:projects] | 4 | before_filter :load_projects, except: [:projects] |
5 | before_filter :event_filter, only: :show | 5 | before_filter :event_filter, only: :show |
6 | + before_filter :default_filter, only: [:issues, :merge_requests] | ||
7 | + | ||
6 | 8 | ||
7 | def show | 9 | def show |
8 | # Fetch only 30 projects. | 10 | # Fetch only 30 projects. |
@@ -51,12 +53,12 @@ class DashboardController < ApplicationController | @@ -51,12 +53,12 @@ class DashboardController < ApplicationController | ||
51 | end | 53 | end |
52 | 54 | ||
53 | def merge_requests | 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 | @merge_requests = @merge_requests.recent.page(params[:page]).per(20) | 57 | @merge_requests = @merge_requests.recent.page(params[:page]).per(20) |
56 | end | 58 | end |
57 | 59 | ||
58 | def issues | 60 | def issues |
59 | - @issues = FilterContext.new(Issue, current_user, params).execute | 61 | + @issues = FilteringService.new.execute(Issue, current_user, params) |
60 | @issues = @issues.recent.page(params[:page]).per(20) | 62 | @issues = @issues.recent.page(params[:page]).per(20) |
61 | @issues = @issues.includes(:author, :project) | 63 | @issues = @issues.includes(:author, :project) |
62 | 64 | ||
@@ -71,4 +73,9 @@ class DashboardController < ApplicationController | @@ -71,4 +73,9 @@ class DashboardController < ApplicationController | ||
71 | def load_projects | 73 | def load_projects |
72 | @projects = current_user.authorized_projects.sorted_by_activity.non_archived | 74 | @projects = current_user.authorized_projects.sorted_by_activity.non_archived |
73 | end | 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 | end | 81 | end |
app/controllers/groups_controller.rb
@@ -10,6 +10,8 @@ class GroupsController < ApplicationController | @@ -10,6 +10,8 @@ class GroupsController < ApplicationController | ||
10 | # Load group projects | 10 | # Load group projects |
11 | before_filter :projects, except: [:new, :create] | 11 | before_filter :projects, except: [:new, :create] |
12 | 12 | ||
13 | + before_filter :default_filter, only: [:issues, :merge_requests] | ||
14 | + | ||
13 | layout :determine_layout | 15 | layout :determine_layout |
14 | 16 | ||
15 | before_filter :set_title, only: [:new, :create] | 17 | before_filter :set_title, only: [:new, :create] |
@@ -43,18 +45,14 @@ class GroupsController < ApplicationController | @@ -43,18 +45,14 @@ class GroupsController < ApplicationController | ||
43 | end | 45 | end |
44 | end | 46 | end |
45 | 47 | ||
46 | - # Get authored or assigned open merge requests | ||
47 | def merge_requests | 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 | end | 51 | end |
52 | 52 | ||
53 | - # Get only assigned issues | ||
54 | def issues | 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 | @issues = @issues.includes(:author, :project) | 56 | @issues = @issues.includes(:author, :project) |
59 | 57 | ||
60 | respond_to do |format| | 58 | respond_to do |format| |
@@ -130,4 +128,10 @@ class GroupsController < ApplicationController | @@ -130,4 +128,10 @@ class GroupsController < ApplicationController | ||
130 | 'group' | 128 | 'group' |
131 | end | 129 | end |
132 | end | 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 | end | 137 | end |
app/helpers/dashboard_helper.rb
1 | module DashboardHelper | 1 | module DashboardHelper |
2 | def filter_path(entity, options={}) | 2 | def filter_path(entity, options={}) |
3 | exist_opts = { | 3 | exist_opts = { |
4 | - status: params[:status], | 4 | + state: params[:state], |
5 | scope: params[:scope], | 5 | scope: params[:scope], |
6 | project_id: params[:project_id], | 6 | project_id: params[:project_id], |
7 | } | 7 | } |
app/views/shared/_filter.html.haml
@@ -2,8 +2,8 @@ | @@ -2,8 +2,8 @@ | ||
2 | = form_tag filter_path(entity), method: 'get' do | 2 | = form_tag filter_path(entity), method: 'get' do |
3 | %fieldset.scope-filter | 3 | %fieldset.scope-filter |
4 | %ul.nav.nav-pills.nav-stacked | 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 | Assigned to me | 7 | Assigned to me |
8 | %li{class: ("active" if params[:scope] == 'authored')} | 8 | %li{class: ("active" if params[:scope] == 'authored')} |
9 | = link_to filter_path(entity, scope: 'authored') do | 9 | = link_to filter_path(entity, scope: 'authored') do |
@@ -15,14 +15,14 @@ | @@ -15,14 +15,14 @@ | ||
15 | %fieldset.status-filter | 15 | %fieldset.status-filter |
16 | %legend State | 16 | %legend State |
17 | %ul.nav.nav-pills | 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 | Open | 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 | Closed | 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 | All | 26 | All |
27 | 27 | ||
28 | %fieldset | 28 | %fieldset |
@@ -36,8 +36,8 @@ | @@ -36,8 +36,8 @@ | ||
36 | %small.pull-right= entities_per_project(project, entity) | 36 | %small.pull-right= entities_per_project(project, entity) |
37 | 37 | ||
38 | %fieldset | 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 | %i.icon-remove | 41 | %i.icon-remove |
42 | %strong Clear filter | 42 | %strong Clear filter |
43 | 43 |