BathHacked/energy-sparks

View on GitHub
app/components/podium_component/podium_component.html.erb

Summary

Maintainability
Test Coverage
<div<%= " id=#{id}" if id %> class="podium-component<%= classes %>">
  <% if podium.includes_school? && podium.school_has_points? %>
    <h4 class="text-center">
      <%= t('components.podium.full_position_html',
            position_ordinal: podium.school_position.ordinal,
            scoreboard: podium.scoreboard.name,
            scoreboard_path: scoreboard_path(podium.scoreboard),
            national_position_ordinal: national_podium.school_position.ordinal,
            national_scoreboard_path: scoreboard_path(national_podium.scoreboard)) %>.
      </h4>
  <% else %>
    <h4 class="text-center"><%= t('components.podium.no_points_this_year') %></h4>
    <p class="text-center"><%= t('components.podium.complete_an_activity_html',
                                 recommendations_path: school_recommendations_path(school)) %>.
      <%= if podium.points_to_overtake
            t('components.podium.points_needed_to_overtake', points: podium.points_to_overtake)
          end %>
    </p>
  <% end %>
  <% if podium.school_has_points? || podium.positions.count > 1 %>
    <div class="row align-items-end border-bottom grey">
      <% podium.low_to_high.each do |position| %>
        <div class="col-4 text-center">
          <h5>
            <% if podium.current_school?(position) %>
              <% if podium.school_has_points? %>
                <%= fa_icon('crown fa-2x') %>
                <p class='h2'><%= position.ordinal %></p>
              <% end %>
            <% else %>
              <p><%= position.ordinal %></p>
              <% if (position.normalised_points * 149).to_i < 70 %>
                <p class="mb-1"><strong><%= position.points %></strong></p>
                <p class="text-uppercase"><%= t('components.podium.points') %></p>
              <% end %>
            <% end %>
          </h5>

          <div class="bar <%= 'bar-current' if podium.current_school?(position) %>">
            <div class="bar-arrow"></div>
            <div class="bar-body" style="height:<%= (position.normalised_points * 149).to_i + 1 %>px">
              <% if (position.normalised_points * 149).to_i > 70 %>
                <p class="pt-2 mb-0"><strong><%= position.points %></strong></p>
                <p class="text-uppercase"><%= t('components.podium.points') %></p>
              <% end %>
            </div>
          </div>
        </div>
      <% end %>
    </div>
    <div class="row border-top grey">
      <% podium.low_to_high.each do |position| %>
        <div class="col-4 text-center">
          <h6>
            <% if podium.current_school?(position) %>
              <%= position.school.name %>
            <% else %>
              <%= link_to position.school.name, pupils_school_path(position.school) %>
            <% end %>
          </h6>
        </div>
      <% end %>
    </div>
  <% end %>
</div>