milestone_actions.rb 1.9 KB
Newer Older
1 2
# frozen_string_literal: true

P
Phil Hughes 已提交
3 4 5 6 7
module MilestoneActions
  extend ActiveSupport::Concern

  def merge_requests
    respond_to do |format|
P
Phil Hughes 已提交
8
      format.html { redirect_to milestone_redirect_path }
P
Phil Hughes 已提交
9 10
      format.json do
        render json: tabs_json("shared/milestones/_merge_requests_tab", {
11
          merge_requests: @milestone.sorted_merge_requests(current_user), # rubocop:disable Gitlab/ModuleWithInstanceVariables
P
Phil Hughes 已提交
12 13 14 15 16 17 18 19
          show_project_name: true
        })
      end
    end
  end

  def participants
    respond_to do |format|
P
Phil Hughes 已提交
20
      format.html { redirect_to milestone_redirect_path }
P
Phil Hughes 已提交
21 22
      format.json do
        render json: tabs_json("shared/milestones/_participants_tab", {
23
          users: @milestone.issue_participants_visible_by_user(current_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables
P
Phil Hughes 已提交
24 25 26 27 28
        })
      end
    end
  end

29
  # rubocop:disable Gitlab/ModuleWithInstanceVariables
P
Phil Hughes 已提交
30 31
  def labels
    respond_to do |format|
P
Phil Hughes 已提交
32
      format.html { redirect_to milestone_redirect_path }
P
Phil Hughes 已提交
33
      format.json do
34 35
        milestone_labels = @milestone.issue_labels_visible_by_user(current_user)

P
Phil Hughes 已提交
36
        render json: tabs_json("shared/milestones/_labels_tab", {
37 38 39
          labels: milestone_labels.map do |label|
            label.present(issuable_subject: @milestone.parent)
          end
P
Phil Hughes 已提交
40 41 42 43
        })
      end
    end
  end
44
  # rubocop:enable Gitlab/ModuleWithInstanceVariables
P
Phil Hughes 已提交
45 46 47 48 49 50 51 52

  private

  def tabs_json(partial, data = {})
    {
      html: view_to_html_string(partial, data)
    }
  end
P
Phil Hughes 已提交
53

54
  # rubocop:disable Gitlab/ModuleWithInstanceVariables
P
Phil Hughes 已提交
55
  def milestone_redirect_path
P
Phil Hughes 已提交
56
    if @project
57
      project_milestone_path(@project, @milestone)
58
    elsif @group
P
Phil Hughes 已提交
59
      group_milestone_path(@group, @milestone.safe_title, title: @milestone.title)
60 61
    else
      dashboard_milestone_path(@milestone.safe_title, title: @milestone.title)
P
Phil Hughes 已提交
62 63
    end
  end
64
  # rubocop:enable Gitlab/ModuleWithInstanceVariables
P
Phil Hughes 已提交
65
end