BathHacked/energy-sparks

View on GitHub
app/views/schools/temperature_observations/index.html.erb

Summary

Maintainability
Test Coverage
<h1><%= t('schools.temperature_observations.index.page_title') %></h1>
<h2><%= @school.name %></h2>

<p>
  <%= link_to t('schools.temperature_observations.index.add_new_temperature_recordings'), new_school_temperature_observation_path(@school, introduction: true), class: 'btn' %>
  <%= link_to t('schools.temperature_observations.index.change_room_names'), school_locations_path(@school), class: 'btn' %>
</p>

<% if @observations.any? %>
  <table class="table table-bordered temperatures table-large">
    <thead>
      <tr>
        <th class='fixed-width-date'><%= t('schools.temperature_observations.index.date') %></th>
        <th><%= t('schools.temperature_observations.index.time') %></th>
        <% @locations.each do |location| %>
          <th><%= location.name %></th>
        <% end %>
        <% if can? :delete, Observation %>
          <th><%= t('schools.temperature_observations.index.actions') %></th>
        <% end %>
      </tr>
    </thead>
    <tbody>
      <% @observations.order(at: :desc).each do |observation| %>
        <tr scope="row">
          <td><%= nice_dates observation.at %></td>
          <td><%= nice_times_only observation.at %></td>
          <% @locations.each do |location| %>
            <%  if observation.temperature_recordings.find_by(location: location) %>
              <td class='<%= temperature_cell_colour(observation.temperature_recordings.find_by(location: location).centigrade) %> align-middle text-center f5'><%= observation.temperature_recordings.find_by(location: location).centigrade  %></td>
            <% else %>
              <td></td>
            <% end %>

          <% end %>
          <% if can? :delete, observation %>
            <td><%= link_to t('schools.temperature_observations.index.delete'), school_temperature_observation_path(@school, observation), method: :delete, data: { confirm: t('schools.temperature_observations.index.are_you_sure') }, class: 'btn btn-sm' %></td>
          <% end %>
        </tr>
      <% end %>
    </tbody>
  </table>

  <hr/>

  <div class='calendar-legend row'>
    <div class='legend-scale vertical'>
      <ul class='legend-labels'>
        <li>
          <span class="<%= temperature_cell_colour(16) %>"></span>
          <div class="description">
            <%= t('schools.temperature_observations.index.roof_and_wall_insulation_message') %>
          </div>
        </li>
        <li>
          <span class="<%= temperature_cell_colour(18) %>"></span>
          <div class="description">
            <%= t('schools.temperature_observations.index.good_temperature_message') %>
          </div>
        </li>
        <li>
          <span class="<%= temperature_cell_colour(19) %>"></span>
          <div class="description">
            <%= t('schools.temperature_observations.index.try_turning_down_your_heating_message') %>
          </div>
        </li>
      </ul>
    </div>
  </div>

  <%= t('schools.temperature_observations.index.what_to_do_next_message_html') %>
<% else %>
  <p><%= t('schools.temperature_observations.index.no_observations_message') %></p>
<% end %>