BathHacked/energy-sparks

View on GitHub
app/views/school_groups/current_scores.html.erb

Summary

Maintainability
Test Coverage
<%= render 'enhanced_header' %>

<div class="row mt-4">
  <div class="col-md-12">

    <p>
      <% if @academic_year == @current_year %>
        <%= t('school_groups.current_scores.introduction') %>
        <%= link_to t('scoreboard.previous_scoreboard'),
                    current_scores_school_group_path(@school_group, previous_year: true) %>.
      <% else %>
        <%= t('scoreboard.previous_scores') %>.
        <strong>
          <%= link_to t('school_groups.current_scores.view_current_scores'),
                      current_scores_school_group_path(@school_group) %>
        </strong>.
      <% end %>
    </p>
    <% if @school_group.default_scoreboard.present? %>
      <p>
        <%= t('school_groups.current_scores.regional_scoreboard_html',
              scoreboard: scoreboard_path(@school_group.default_scoreboard)) %>
      </p>
    <% end %>
  </div>
</div>

<div class='text-right pt-3'>
  <% previous_year = @academic_year == @current_year ? nil : true %>
  <%= link_to t('school_groups.download_as_csv'),
              current_scores_school_group_path(@school_group, previous_year: previous_year, format: :csv),
              class: 'btn btn-sm btn-outline-dark rounded-pill font-weight-bold' %>
</div>

<table width="100%" class="mt-3 table advice-table">
  <thead>
    <tr>
      <th><%= t('scoreboard.position') %></th>
      <th><%= t('common.school') %></th>
      <% if can?(:update_settings, @school_group) %>
        <th><%= t('school_groups.clusters.labels.cluster') %></th>
      <% end %>
      <th><%= t('scoreboard.score') %></th>
    </tr>
  </thead>
  <tbody>
    <% @scored_schools.with_points.schools_with_positions.each do |position, schools| %>
      <% schools.each do |school| %>
        <tr>
          <td>
            <span class="badge badge-primary"><%= '=' if schools.size > 1 %><%= position %></span>
          </td>
          <td><%= link_to school.name, school_path(school) %></td>
          <% if can?(:update_settings, @school_group) %>
            <td><%= school.school_group_cluster_name %></td>
          <% end %>
          <td>
            <%= link_to school.sum_points, school_timeline_path(school, academic_year: @academic_year),
                        class: 'badge badge-success' %>
            &nbsp;
            <% if school.recent_points&.positive? %>
              <i class="fa fa-arrow-up" data-toggle="tooltip" title="<%= t('scoreboard.score_tooltip') %>"></i>
            <% end %>
          </td>
        </tr>
      <% end %>
    <% end %>
    <% @scored_schools.without_points.each do |school| %>
      <tr>
        <td><span class="badge badge-secondary">-</span></td>
        <td><%= link_to school.name, school_path(school) %></td>
        <% if can?(:update_settings, @school_group) %>
          <td><%= school.school_group_cluster_name %></td>
        <% end %>
        <td><span class="badge badge-secondary">0</span></td>
      </tr>
    <% end %>
  </tbody>
</table>