gitlabhq/app/contexts/merge_requests_load_context.rb
Sergio Visinoni a7d0816933 Add Milestone information in Merge Requests
Step 1:
* Add milestone_id in the model for merge_requests
* Make it possible to create or update a Merge Request with an attached
  Milestone detail
* Add the possibility to filter by Milestone and / or Assignee in the
  Merge Requests listing page
2012-10-26 16:12:40 +02:00

30 lines
1 KiB
Ruby

class MergeRequestsLoadContext < BaseContext
def execute
type = params[:f]
merge_requests = @project.merge_requests
merge_requests = case type
when 'all' then merge_requests
when 'closed' then merge_requests.closed
when 'assigned-to-me' then merge_requests.opened.assigned(current_user)
else merge_requests.opened
end.page(params[:page]).per(20)
merge_requests.includes(:author, :project).order("closed, created_at desc")
@merge_requests = merge_requests
# Filter by specific assignee_id (or lack thereof)?
if params[:assignee_id].present?
@merge_requests = merge_requests.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
end
# Filter by specific milestone_id (or lack thereof)?
if params[:milestone_id].present?
@merge_requests = merge_requests.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
end
@merge_requests
end
end