diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0ddd743f053..79824116b41 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -240,24 +240,26 @@ class ApplicationController < ActionController::Base end end - def set_filters_defaults + def set_filters_params params[:sort] ||= 'newest' params[:scope] = 'all' if params[:scope].blank? params[:state] = 'opened' if params[:state].blank? - @sort = params[:sort].humanize + @filter_params = params.dup if @project - params[:project_id] = @project.id + @filter_params[:project_id] = @project.id elsif @group - params[:group_id] = @group.id + @filter_params[:group_id] = @group.id else - params[:authorized_only] = true + @filter_params[:authorized_only] = true - unless params[:assignee_id].present? - params[:assignee_id] = current_user.id + unless @filter_params[:assignee_id] + @filter_params[:assignee_id] = current_user.id end end + + @filter_params end def set_filter_values(collection) @@ -265,20 +267,35 @@ class ApplicationController < ActionController::Base author_id = params[:author_id] milestone_id = params[:milestone_id] + @sort = params[:sort].try(:humanize) @assignees = User.where(id: collection.pluck(:assignee_id)) @authors = User.where(id: collection.pluck(:author_id)) @milestones = Milestone.where(id: collection.pluck(:milestone_id)) if assignee_id.present? && !assignee_id.to_i.zero? - @assignee = @assignees.find(assignee_id) + @assignee = @assignees.find_by(id: assignee_id) end if author_id.present? && !author_id.to_i.zero? - @author = @authors.find(author_id) + @author = @authors.find_by(id: author_id) end if milestone_id.present? && !milestone_id.to_i.zero? - @milestone = @milestones.find(milestone_id) + @milestone = @milestones.find_by(id: milestone_id) end end + + def get_issues_collection + set_filters_params + issues = IssuesFinder.new.execute(current_user, @filter_params) + set_filter_values(issues) + issues + end + + def get_merge_requests_collection + set_filters_params + merge_requests = MergeRequestsFinder.new.execute(current_user, @filter_params) + set_filter_values(merge_requests) + merge_requests + end end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index bfd1361f2df..cd876024ba3 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -53,17 +53,13 @@ class DashboardController < ApplicationController end def merge_requests - set_filters_defaults - @merge_requests = MergeRequestsFinder.new.execute(current_user, params) - set_filter_values(@merge_requests) + @merge_requests = get_merge_requests_collection @merge_requests = @merge_requests.page(params[:page]).per(20) @merge_requests = @merge_requests.preload(:author, :target_project) end def issues - set_filters_defaults - @issues = IssuesFinder.new.execute(current_user, params) - set_filter_values(@issues) + @issues = get_issues_collection @issues = @issues.page(params[:page]).per(20) @issues = @issues.preload(:author, :project) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index a28f4cc4072..6cd12c35bf9 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -45,17 +45,13 @@ class GroupsController < ApplicationController end def merge_requests - set_filters_defaults - @merge_requests = MergeRequestsFinder.new.execute(current_user, params) - set_filter_values(@merge_requests) + @merge_requests = get_merge_requests_collection @merge_requests = @merge_requests.page(params[:page]).per(20) @merge_requests = @merge_requests.preload(:author, :target_project) end def issues - set_filters_defaults - @issues = IssuesFinder.new.execute(current_user, params) - set_filter_values(@issues) + @issues = get_issues_collection @issues = @issues.page(params[:page]).per(20) @issues = @issues.preload(:author, :project) diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 0266c51babb..42e207cf376 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -18,9 +18,7 @@ class Projects::IssuesController < Projects::ApplicationController def index terms = params['issue_search'] - set_filters_defaults - @issues = IssuesFinder.new.execute(current_user, params) - set_filter_values(@issues) + @issues = get_issues_collection @issues = @issues.full_search(terms) if terms.present? @issues = @issues.page(params[:page]).per(20) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 20d1222326e..d23461821d7 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -17,9 +17,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController before_filter :authorize_modify_merge_request!, only: [:close, :edit, :update, :sort] def index - set_filters_defaults - @merge_requests = MergeRequestsFinder.new.execute(current_user, params) - set_filter_values(@merge_requests) + @merge_requests = get_merge_requests_collection @merge_requests = @merge_requests.page(params[:page]).per(20) end