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
|
2012-08-30 15:15:34 -04:00
|
|
|
type = params[:f]
|
2012-07-20 01:39:34 -04:00
|
|
|
|
2012-10-29 16:40:00 -04:00
|
|
|
merge_requests = project.merge_requests
|
2012-07-20 01:39:34 -04:00
|
|
|
|
|
|
|
merge_requests = case type
|
2012-08-30 15:15:34 -04: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 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
|
|
|
|
2012-10-29 16:40:00 -04:00
|
|
|
merge_requests = merge_requests.page(params[:page]).per(20)
|
2013-02-21 09:26:09 -05:00
|
|
|
merge_requests = merge_requests.includes(:author, :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
|