2012-10-29 16:40:00 -04:00
|
|
|
# Build collection of Merge Requests
|
|
|
|
# based on filtering passed via params for @project
|
2012-10-09 15:09:46 -04:00
|
|
|
class MergeRequestsLoadContext < BaseContext
|
2012-07-20 01:39:34 -04:00
|
|
|
def execute
|
2013-08-10 13:25:53 -04:00
|
|
|
merge_requests = @project.merge_requests
|
2012-07-20 01:39:34 -04:00
|
|
|
|
2013-08-10 13:25:53 -04:00
|
|
|
merge_requests = case params[:state]
|
2012-08-30 15:15:34 -04:00
|
|
|
when 'all' then merge_requests
|
|
|
|
when 'closed' then merge_requests.closed
|
2012-07-20 01:39:34 -04:00
|
|
|
else merge_requests.opened
|
2012-10-29 16:40:00 -04:00
|
|
|
end
|
2012-07-20 01:39:34 -04:00
|
|
|
|
2013-08-10 13:25:53 -04:00
|
|
|
merge_requests = case params[:scope]
|
|
|
|
when 'assigned-to-me' then merge_requests.assigned_to(current_user)
|
|
|
|
when 'created-by-me' then merge_requests.authored(current_user)
|
|
|
|
else merge_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-10-29 16:40:00 -04:00
|
|
|
merge_requests = merge_requests.page(params[:page]).per(20)
|
2013-04-25 10:15:33 -04:00
|
|
|
merge_requests = merge_requests.includes(:author, :source_project, :target_project).order("created_at desc")
|
2012-10-26 08:52:10 -04:00
|
|
|
|
|
|
|
# Filter by specific assignee_id (or lack thereof)?
|
|
|
|
if params[:assignee_id].present?
|
2012-10-29 16:40:00 -04:00
|
|
|
merge_requests = merge_requests.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
|
2012-10-26 08:52:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Filter by specific milestone_id (or lack thereof)?
|
|
|
|
if params[:milestone_id].present?
|
2012-10-29 16:40:00 -04:00
|
|
|
merge_requests = merge_requests.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
|
2012-10-26 08:52:10 -04:00
|
|
|
end
|
2012-10-29 16:40:00 -04:00
|
|
|
|
|
|
|
merge_requests
|
2012-07-20 01:39:34 -04:00
|
|
|
end
|
|
|
|
end
|