BigW Consortium Gitlab

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

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
  # Returns count of milestones for different states
39
  # Uses explicit hash keys as the 'opened' state URL params differs from the db value
40
  # and we need to add the total
41 42
  def milestone_counts(milestones)
    counts = milestones.reorder(nil).group(:state).count
43

44
    {
45 46 47
      opened: counts['active'] || 0,
      closed: counts['closed'] || 0,
      all: counts.values.sum || 0
48
    }
49 50
  end

51 52 53
  # Show 'active' class if provided GET param matches check
  # `or_blank` allows the function to return 'active' when given an empty param
  # Could be refactored to be simpler but that may make it harder to read
54
  def milestone_class_for_state(param, check, match_blank_param = false)
55 56 57 58 59 60 61
    if match_blank_param
      'active' if param.blank? || param == check
    else
      'active' if param == check
    end
  end

62 63 64
  def milestone_progress_bar(milestone)
    options = {
      class: 'progress-bar progress-bar-success',
65
      style: "width: #{milestone.percent_complete(current_user)}%;"
66 67 68 69 70 71
    }

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

73 74 75 76
  def milestones_filter_dropdown_path
    if @project
      namespace_project_milestones_path(@project.namespace, @project, :json)
    else
77
      dashboard_milestones_path(:json)
78
    end
79
  end
80

81
  def milestone_remaining_days(milestone)
82
    if milestone.expired?
Fatih Acet committed
83
      content_tag(:strong, 'Past due')
84
    elsif milestone.due_date
85 86 87
      days    = milestone.remaining_days
      content = content_tag(:strong, days)
      content << " #{'day'.pluralize(days)} remaining"
88 89
    end
  end
90
end