Refactor issuable list pages

Signed-off-by: 's avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 47634e39
......@@ -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
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment