Show days remaining instead of elapsed time for Milestone.

This commit is contained in:
Rubén Dávila 2016-02-25 15:23:34 -05:00
parent 6aa50165b0
commit 7773180219
4 changed files with 17 additions and 14 deletions

View file

@ -39,7 +39,7 @@ li.milestone {
margin-right: 10px;
}
.time-elapsed {
.remaining-days {
color: $orange-light;
}
}

View file

@ -36,4 +36,15 @@ module MilestonesHelper
options_from_collection_for_select(grouped_milestones, 'name', 'title', params[:milestone_title])
end
def milestone_remaining_days(milestone)
days = milestone.remaining_days
if days == 0
content_tag(:strong, 'expired')
elsif days.to_i > 0
content = content_tag(:strong, days)
content << " #{'day'.pluralize(days)} remaining"
end
end
end

View file

@ -110,17 +110,11 @@ class Milestone < ActiveRecord::Base
0
end
# Returns the elapsed time (in percent) since the Milestone creation date until today.
# If the Milestone doesn't have a due_date then returns 0 since we can't calculate the elapsed time.
# If the Milestone is overdue then it returns 100%.
def percent_time_used
return 0 unless due_date
return 100 if expired?
def remaining_days
return nil if due_date.nil?
return 0 if due_date < Date.today
duration = ((created_at - due_date.to_datetime) / 1.day)
days_elapsed = ((created_at - Time.now) / 1.day)
((days_elapsed.to_f / duration) * 100).floor
(due_date - Date.today).to_i
end
def expires_at

View file

@ -60,9 +60,7 @@
%strong== #{@milestone.percent_complete}%
complete
%span.milestone-stat
%span.time-elapsed
%strong== #{@milestone.percent_time_used}%
time elapsed
%span.remaining-days= milestone_remaining_days(@milestone)
%span.pull-right.tab-issues-buttons
- if can?(current_user, :create_issue, @project)
= link_to new_namespace_project_issue_path(@project.namespace, @project, issue: { milestone_id: @milestone.id }), class: "btn btn-grouped", title: "New Issue" do