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