2015-01-06 20:32:04 +00:00
|
|
|
|
module MilestonesHelper
|
|
|
|
|
def milestones_filter_path(opts = {})
|
|
|
|
|
if @project
|
2015-01-24 18:02:58 +00:00
|
|
|
|
namespace_project_milestones_path(@project.namespace, @project, opts)
|
2015-01-06 20:32:04 +00:00
|
|
|
|
elsif @group
|
|
|
|
|
group_milestones_path(@group, opts)
|
2015-03-03 15:19:37 +00:00
|
|
|
|
else
|
|
|
|
|
dashboard_milestones_path(opts)
|
2015-01-06 20:32:04 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-03-09 22:20:32 +00:00
|
|
|
|
|
2016-03-07 04:07:19 +00:00
|
|
|
|
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
|
|
|
|
|
|
2016-07-22 20:11:07 +00:00
|
|
|
|
# Returns count of milestones for different states
|
2016-08-24 17:29:27 +00:00
|
|
|
|
# Uses explicit hash keys as the 'opened' state URL params differs from the db value
|
2016-07-22 20:11:07 +00:00
|
|
|
|
# and we need to add the total
|
2016-07-25 21:23:27 +00:00
|
|
|
|
def milestone_counts(milestones)
|
|
|
|
|
counts = milestones.reorder(nil).group(:state).count
|
2016-08-24 17:29:27 +00:00
|
|
|
|
|
2016-07-22 20:11:07 +00:00
|
|
|
|
{
|
2016-08-24 17:29:27 +00:00
|
|
|
|
opened: counts['active'] || 0,
|
|
|
|
|
closed: counts['closed'] || 0,
|
|
|
|
|
all: counts.values.sum || 0
|
2016-07-22 20:11:07 +00:00
|
|
|
|
}
|
2016-07-22 09:18:38 +00:00
|
|
|
|
end
|
|
|
|
|
|
2016-07-26 13:30:14 +00:00
|
|
|
|
# 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
|
2016-08-22 22:58:28 +00:00
|
|
|
|
def milestone_class_for_state(param, check, match_blank_param = false)
|
2016-07-26 13:30:14 +00:00
|
|
|
|
if match_blank_param
|
|
|
|
|
'active' if param.blank? || param == check
|
|
|
|
|
else
|
|
|
|
|
'active' if param == check
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-03-09 22:20:32 +00:00
|
|
|
|
def milestone_progress_bar(milestone)
|
|
|
|
|
options = {
|
|
|
|
|
class: 'progress-bar progress-bar-success',
|
2016-03-17 20:59:30 +00:00
|
|
|
|
style: "width: #{milestone.percent_complete(current_user)}%;"
|
2015-03-09 22:20:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content_tag :div, class: 'progress' do
|
|
|
|
|
content_tag :div, nil, options
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-03-27 02:13:49 +00:00
|
|
|
|
|
2016-03-16 19:14:31 +00:00
|
|
|
|
def milestones_filter_dropdown_path
|
2016-07-16 08:41:55 +00:00
|
|
|
|
project = @target_project || @project
|
2016-07-18 16:43:00 +00:00
|
|
|
|
if project
|
2016-07-16 08:41:55 +00:00
|
|
|
|
namespace_project_milestones_path(project.namespace, project, :json)
|
2016-03-16 19:14:31 +00:00
|
|
|
|
else
|
2016-03-22 18:19:53 +00:00
|
|
|
|
dashboard_milestones_path(:json)
|
2016-03-16 19:14:31 +00:00
|
|
|
|
end
|
2015-03-27 02:13:49 +00:00
|
|
|
|
end
|
2016-02-25 20:23:34 +00:00
|
|
|
|
|
2016-06-08 15:19:04 +00:00
|
|
|
|
def milestone_remaining_days(milestone)
|
2016-03-02 00:39:58 +00:00
|
|
|
|
if milestone.expired?
|
2016-06-08 16:40:32 +00:00
|
|
|
|
content_tag(:strong, 'Past due')
|
2016-03-02 00:39:58 +00:00
|
|
|
|
elsif milestone.due_date
|
2016-06-08 15:19:04 +00:00
|
|
|
|
days = milestone.remaining_days
|
|
|
|
|
content = content_tag(:strong, days)
|
|
|
|
|
content << " #{'day'.pluralize(days)} remaining"
|
2016-11-15 17:48:30 +00:00
|
|
|
|
elsif milestone.upcoming?
|
|
|
|
|
content_tag(:strong, 'Upcoming')
|
|
|
|
|
elsif milestone.start_date && milestone.start_date.past?
|
|
|
|
|
days = milestone.elapsed_days
|
|
|
|
|
content = content_tag(:strong, days)
|
|
|
|
|
content << " #{'day'.pluralize(days)} elapsed"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def milestone_date_range(milestone)
|
|
|
|
|
if milestone.start_date && milestone.due_date
|
2017-01-26 17:54:50 +00:00
|
|
|
|
"#{milestone.start_date.to_s(:medium)}–#{milestone.due_date.to_s(:medium)}"
|
2016-11-15 17:48:30 +00:00
|
|
|
|
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
|
2016-02-25 20:23:34 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-01-06 20:32:04 +00:00
|
|
|
|
end
|