milestones_helper.rb 2.1 KB
Newer Older
1 2 3
module MilestonesHelper
  def milestones_filter_path(opts = {})
    if @project
V
Vinnie Okada 已提交
4
      namespace_project_milestones_path(@project.namespace, @project, opts)
5 6
    elsif @group
      group_milestones_path(@group, opts)
D
Douwe Maan 已提交
7 8
    else
      dashboard_milestones_path(opts)
9 10
    end
  end
11

R
Rubén Dávila 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  def milestones_label_path(opts = {})
    if @project
      namespace_project_issues_path(@project.namespace, @project, opts)
    elsif @group
      issues_group_path(@group, opts)
    else
      issues_dashboard_path(opts)
    end
  end

  def milestones_browse_issuables_path(milestone, type:)
    opts = { milestone_title: milestone.title }

    if @project
      polymorphic_path([@project.namespace.becomes(Namespace), @project, type], opts)
    elsif @group
      polymorphic_url([type, @group], opts)
    else
      polymorphic_url([type, :dashboard], opts)
    end
  end

  def milestone_issues_by_label_count(milestone, label, state:)
    milestone.issues.with_label(label.title).send(state).size
  end

38 39 40
  def milestone_progress_bar(milestone)
    options = {
      class: 'progress-bar progress-bar-success',
41
      style: "width: #{milestone.percent_complete(current_user)}%;"
42 43 44 45 46 47
    }

    content_tag :div, class: 'progress' do
      content_tag :div, nil, options
    end
  end
48

P
Phil Hughes 已提交
49
  def milestones_filter_dropdown_path
50
    project = @target_project || @project
P
Phil Hughes 已提交
51
    if @project
52
      namespace_project_milestones_path(project.namespace, project, :json)
P
Phil Hughes 已提交
53
    else
54
      dashboard_milestones_path(:json)
P
Phil Hughes 已提交
55
    end
56
  end
57

58
  def milestone_dropdown_selected_text(selected)
P
Phil Hughes 已提交
59 60
    project = @target_project || @project || @projects

61 62 63 64 65
    if selected.is_a? Integer
      Milestone.of_projects(project).where(id: selected).first.try(:title)
    else
      Milestone.of_projects(project).where(title: selected).first.try(:title)
    end
P
Phil Hughes 已提交
66 67
  end

68
  def milestone_remaining_days(milestone)
69
    if milestone.expired?
F
Fatih Acet 已提交
70
      content_tag(:strong, 'Past due')
71
    elsif milestone.due_date
72 73 74
      days    = milestone.remaining_days
      content = content_tag(:strong, days)
      content << " #{'day'.pluralize(days)} remaining"
75 76
    end
  end
77
end