2015-04-26 12:48:37 +05:30
|
|
|
|
module MilestonesHelper
|
|
|
|
|
def milestones_filter_path(opts = {})
|
|
|
|
|
if @project
|
2017-09-10 17:25:29 +05:30
|
|
|
|
project_milestones_path(@project, opts)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
elsif @group
|
|
|
|
|
group_milestones_path(@group, opts)
|
|
|
|
|
else
|
|
|
|
|
dashboard_milestones_path(opts)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
|
def milestones_label_path(opts = {})
|
|
|
|
|
if @project
|
2017-09-10 17:25:29 +05:30
|
|
|
|
project_issues_path(@project, opts)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
elsif @group
|
|
|
|
|
issues_group_path(@group, opts)
|
|
|
|
|
else
|
|
|
|
|
issues_dashboard_path(opts)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
def milestones_browse_issuables_path(milestone, state: nil, type:)
|
|
|
|
|
opts = { milestone_title: milestone.title, state: state }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
|
|
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:)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
issues = milestone.issues.with_label(label.title)
|
|
|
|
|
issues =
|
|
|
|
|
case state
|
|
|
|
|
when :opened
|
|
|
|
|
issues.opened
|
|
|
|
|
when :closed
|
|
|
|
|
issues.closed
|
|
|
|
|
else
|
|
|
|
|
raise ArgumentError, "invalid milestone state `#{state}`"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
issues.size
|
2016-06-02 11:05:42 +05:30
|
|
|
|
end
|
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
|
# Returns count of milestones for different states
|
|
|
|
|
# Uses explicit hash keys as the 'opened' state URL params differs from the db value
|
|
|
|
|
# and we need to add the total
|
|
|
|
|
def milestone_counts(milestones)
|
|
|
|
|
counts = milestones.reorder(nil).group(:state).count
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
opened: counts['active'] || 0,
|
|
|
|
|
closed: counts['closed'] || 0,
|
|
|
|
|
all: counts.values.sum || 0
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
def milestone_class_for_state(param, check, match_blank_param = false)
|
|
|
|
|
if match_blank_param
|
|
|
|
|
'active' if param.blank? || param == check
|
2017-09-10 17:25:29 +05:30
|
|
|
|
elsif param == check
|
|
|
|
|
'active'
|
2016-11-03 12:29:30 +05:30
|
|
|
|
else
|
2017-09-10 17:25:29 +05:30
|
|
|
|
check
|
2016-11-03 12:29:30 +05:30
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
|
def milestone_progress_bar(milestone)
|
|
|
|
|
options = {
|
|
|
|
|
class: 'progress-bar progress-bar-success',
|
2016-06-02 11:05:42 +05:30
|
|
|
|
style: "width: #{milestone.percent_complete(current_user)}%;"
|
2015-04-26 12:48:37 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content_tag :div, class: 'progress' do
|
|
|
|
|
content_tag :div, nil, options
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
|
def milestones_filter_dropdown_path
|
2016-11-03 12:29:30 +05:30
|
|
|
|
project = @target_project || @project
|
|
|
|
|
if project
|
2017-09-10 17:25:29 +05:30
|
|
|
|
project_milestones_path(project, :json)
|
|
|
|
|
elsif @group
|
|
|
|
|
group_milestones_path(@group, :json)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
else
|
|
|
|
|
dashboard_milestones_path(:json)
|
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
|
def milestone_tooltip_title(milestone)
|
|
|
|
|
if milestone.due_date
|
|
|
|
|
[milestone.due_date.to_s(:medium), "(#{milestone_remaining_days(milestone)})"].join(' ')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
|
def milestone_remaining_days(milestone)
|
|
|
|
|
if milestone.expired?
|
2016-06-16 23:09:34 +05:30
|
|
|
|
content_tag(:strong, 'Past due')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
elsif milestone.upcoming?
|
|
|
|
|
content_tag(:strong, 'Upcoming')
|
2016-04-02 18:10:28 +05:30
|
|
|
|
elsif milestone.due_date
|
2017-08-17 22:00:37 +05:30
|
|
|
|
time_ago = time_ago_in_words(milestone.due_date)
|
|
|
|
|
content = time_ago.gsub(/\d+/) { |match| "<strong>#{match}</strong>" }
|
|
|
|
|
content.slice!("about ")
|
|
|
|
|
content << " remaining"
|
|
|
|
|
content.html_safe
|
|
|
|
|
elsif milestone.start_date && milestone.start_date.past?
|
|
|
|
|
days = milestone.elapsed_days
|
2016-04-02 18:10:28 +05:30
|
|
|
|
content = content_tag(:strong, days)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
content << " #{'day'.pluralize(days)} elapsed"
|
|
|
|
|
content.html_safe
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def milestone_date_range(milestone)
|
|
|
|
|
if milestone.start_date && milestone.due_date
|
|
|
|
|
"#{milestone.start_date.to_s(:medium)}–#{milestone.due_date.to_s(:medium)}"
|
|
|
|
|
elsif milestone.due_date
|
|
|
|
|
if milestone.due_date.past?
|
|
|
|
|
"expired on #{milestone.due_date.to_s(:medium)}"
|
|
|
|
|
else
|
|
|
|
|
"expires on #{milestone.due_date.to_s(:medium)}"
|
|
|
|
|
end
|
|
|
|
|
elsif milestone.start_date
|
|
|
|
|
if milestone.start_date.past?
|
|
|
|
|
"started on #{milestone.start_date.to_s(:medium)}"
|
|
|
|
|
else
|
|
|
|
|
"starts on #{milestone.start_date.to_s(:medium)}"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def milestone_merge_request_tab_path(milestone)
|
|
|
|
|
if @project
|
2017-09-10 17:25:29 +05:30
|
|
|
|
merge_requests_project_milestone_path(@project, milestone, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
elsif @group
|
|
|
|
|
merge_requests_group_milestone_path(@group, milestone.safe_title, title: milestone.title, format: :json)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
else
|
|
|
|
|
merge_requests_dashboard_milestone_path(milestone, title: milestone.title, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def milestone_participants_tab_path(milestone)
|
|
|
|
|
if @project
|
2017-09-10 17:25:29 +05:30
|
|
|
|
participants_project_milestone_path(@project, milestone, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
elsif @group
|
|
|
|
|
participants_group_milestone_path(@group, milestone.safe_title, title: milestone.title, format: :json)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
else
|
|
|
|
|
participants_dashboard_milestone_path(milestone, title: milestone.title, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def milestone_labels_tab_path(milestone)
|
|
|
|
|
if @project
|
2017-09-10 17:25:29 +05:30
|
|
|
|
labels_project_milestone_path(@project, milestone, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
elsif @group
|
|
|
|
|
labels_group_milestone_path(@group, milestone.safe_title, title: milestone.title, format: :json)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
else
|
|
|
|
|
labels_dashboard_milestone_path(milestone, title: milestone.title, format: :json)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def group_milestone_route(milestone, params = {})
|
|
|
|
|
params = nil if params.empty?
|
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
|
if milestone.legacy_group_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
|
group_milestone_path(@group, milestone.safe_title, title: milestone.title, milestone: params)
|
|
|
|
|
else
|
|
|
|
|
group_milestone_path(@group, milestone.iid, milestone: params)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
end
|
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
end
|