Add progress bars to milestones public view

This commit is contained in:
Javi Martín
2019-01-10 21:03:46 +01:00
committed by decabeza
parent ad355d4df6
commit e73f3bd97a
7 changed files with 95 additions and 98 deletions

View File

@@ -1,4 +1,4 @@
.tab-milestones ul {
.tab-milestones .timeline ul {
margin-top: rem-calc(40);
position: relative;
}

View File

@@ -0,0 +1,9 @@
module MilestonesHelper
def progress_tag_for(progress_bar)
content_tag :progress,
number_to_percentage(progress_bar.percentage, precision: 0),
class: progress_bar.primary? ? "primary" : "",
max: ProgressBar::RANGE.max,
value: progress_bar.percentage
end
end

View File

@@ -7,5 +7,13 @@ module Milestoneable
scope :with_milestones, -> { joins(:milestones).distinct }
has_many :progress_bars, as: :progressable
def primary_progress_bar
progress_bars.primary.first
end
def secondary_progress_bars
progress_bars.secondary
end
end
end

View File

@@ -5,6 +5,22 @@
<%= t("milestones.index.no_milestones") %>
</div>
<% end %>
<% if milestoneable.primary_progress_bar %>
<%= progress_tag_for(milestoneable.primary_progress_bar) %>
<% if milestoneable.secondary_progress_bars.any? %>
<ul class="milestone-progress">
<% milestoneable.secondary_progress_bars.each do |progress_bar| %>
<li>
<%= progress_bar.title %>
<%= progress_tag_for(progress_bar) %>
</li>
<% end %>
</ul>
<% end %>
<% end %>
<section class="timeline">
<ul class="no-bullet">
<% milestoneable.milestones.order_by_publication_date.each do |milestone| %>