Commit 016981c0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor issuable list pages

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 47634e39
...@@ -240,24 +240,26 @@ class ApplicationController < ActionController::Base ...@@ -240,24 +240,26 @@ class ApplicationController < ActionController::Base
end end
end end
def set_filters_defaults def set_filters_params
params[:sort] ||= 'newest' params[:sort] ||= 'newest'
params[:scope] = 'all' if params[:scope].blank? params[:scope] = 'all' if params[:scope].blank?
params[:state] = 'opened' if params[:state].blank? params[:state] = 'opened' if params[:state].blank?
@sort = params[:sort].humanize @filter_params = params.dup
if @project if @project
params[:project_id] = @project.id @filter_params[:project_id] = @project.id
elsif @group elsif @group
params[:group_id] = @group.id @filter_params[:group_id] = @group.id
else else
params[:authorized_only] = true @filter_params[:authorized_only] = true
unless params[:assignee_id].present? unless @filter_params[:assignee_id]
params[:assignee_id] = current_user.id @filter_params[:assignee_id] = current_user.id
end end
end end
@filter_params
end end
def set_filter_values(collection) def set_filter_values(collection)
...@@ -265,20 +267,35 @@ class ApplicationController < ActionController::Base ...@@ -265,20 +267,35 @@ class ApplicationController < ActionController::Base
author_id = params[:author_id] author_id = params[:author_id]
milestone_id = params[:milestone_id] milestone_id = params[:milestone_id]
@sort = params[:sort].try(:humanize)
@assignees = User.where(id: collection.pluck(:assignee_id)) @assignees = User.where(id: collection.pluck(:assignee_id))
@authors = User.where(id: collection.pluck(:author_id)) @authors = User.where(id: collection.pluck(:author_id))
@milestones = Milestone.where(id: collection.pluck(:milestone_id)) @milestones = Milestone.where(id: collection.pluck(:milestone_id))
if assignee_id.present? && !assignee_id.to_i.zero? if assignee_id.present? && !assignee_id.to_i.zero?
@assignee = @assignees.find(assignee_id) @assignee = @assignees.find_by(id: assignee_id)
end end
if author_id.present? && !author_id.to_i.zero? if author_id.present? && !author_id.to_i.zero?
@author = @authors.find(author_id) @author = @authors.find_by(id: author_id)
end end
if milestone_id.present? && !milestone_id.to_i.zero? if milestone_id.present? && !milestone_id.to_i.zero?
@milestone = @milestones.find(milestone_id) @milestone = @milestones.find_by(id: milestone_id)
end
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
end end
...@@ -53,17 +53,13 @@ class DashboardController < ApplicationController ...@@ -53,17 +53,13 @@ class DashboardController < ApplicationController
end end
def merge_requests def merge_requests
set_filters_defaults @merge_requests = get_merge_requests_collection
@merge_requests = MergeRequestsFinder.new.execute(current_user, params)
set_filter_values(@merge_requests)
@merge_requests = @merge_requests.page(params[:page]).per(20) @merge_requests = @merge_requests.page(params[:page]).per(20)
@merge_requests = @merge_requests.preload(:author, :target_project) @merge_requests = @merge_requests.preload(:author, :target_project)
end end
def issues def issues
set_filters_defaults @issues = get_issues_collection
@issues = IssuesFinder.new.execute(current_user, params)
set_filter_values(@issues)
@issues = @issues.page(params[:page]).per(20) @issues = @issues.page(params[:page]).per(20)
@issues = @issues.preload(:author, :project) @issues = @issues.preload(:author, :project)
......
...@@ -45,17 +45,13 @@ class GroupsController < ApplicationController ...@@ -45,17 +45,13 @@ class GroupsController < ApplicationController
end end
def merge_requests def merge_requests
set_filters_defaults @merge_requests = get_merge_requests_collection
@merge_requests = MergeRequestsFinder.new.execute(current_user, params)
set_filter_values(@merge_requests)
@merge_requests = @merge_requests.page(params[:page]).per(20) @merge_requests = @merge_requests.page(params[:page]).per(20)
@merge_requests = @merge_requests.preload(:author, :target_project) @merge_requests = @merge_requests.preload(:author, :target_project)
end end
def issues def issues
set_filters_defaults @issues = get_issues_collection
@issues = IssuesFinder.new.execute(current_user, params)
set_filter_values(@issues)
@issues = @issues.page(params[:page]).per(20) @issues = @issues.page(params[:page]).per(20)
@issues = @issues.preload(:author, :project) @issues = @issues.preload(:author, :project)
......
...@@ -18,9 +18,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -18,9 +18,7 @@ class Projects::IssuesController < Projects::ApplicationController
def index def index
terms = params['issue_search'] terms = params['issue_search']
set_filters_defaults @issues = get_issues_collection
@issues = IssuesFinder.new.execute(current_user, params)
set_filter_values(@issues)
@issues = @issues.full_search(terms) if terms.present? @issues = @issues.full_search(terms) if terms.present?
@issues = @issues.page(params[:page]).per(20) @issues = @issues.page(params[:page]).per(20)
......
...@@ -17,9 +17,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -17,9 +17,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_filter :authorize_modify_merge_request!, only: [:close, :edit, :update, :sort] before_filter :authorize_modify_merge_request!, only: [:close, :edit, :update, :sort]
def index def index
set_filters_defaults @merge_requests = get_merge_requests_collection
@merge_requests = MergeRequestsFinder.new.execute(current_user, params)
set_filter_values(@merge_requests)
@merge_requests = @merge_requests.page(params[:page]).per(20) @merge_requests = @merge_requests.page(params[:page]).per(20)
end 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