merge_requests_load_context.rb 1.15 KB
Newer Older
1 2
# Build collection of Merge Requests
# based on filtering passed via params for @project
3
class MergeRequestsLoadContext < BaseContext
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
  def execute
5
    type = params[:f]
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
6

7
    merge_requests = project.merge_requests
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8 9

    merge_requests = case type
10 11
                     when 'all' then merge_requests
                     when 'closed' then merge_requests.closed
12
                     when 'assigned-to-me' then merge_requests.opened.assigned_to(current_user)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
13
                     else merge_requests.opened
14
                     end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15

16
    merge_requests = merge_requests.page(params[:page]).per(20)
17
    merge_requests = merge_requests.includes(:author, :source_project, :target_project).order("created_at desc")
18 19 20

    # Filter by specific assignee_id (or lack thereof)?
    if params[:assignee_id].present?
21
      merge_requests = merge_requests.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
22 23 24 25
    end

    # Filter by specific milestone_id (or lack thereof)?
    if params[:milestone_id].present?
26
      merge_requests = merge_requests.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
27
    end
28 29

    merge_requests
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
30 31
  end
end