BathHacked/energy-sparks

View on GitHub
app/views/schools/school_targets/progress/expired.html.erb

Summary

Maintainability
Test Coverage
<div class="d-flex justify-content-between align-items-center">
  <h1>
    <%= t('schools.school_targets.progress.expired.results_of_reducing_your_usage',
          fuel_type: @fuel_type.to_s.humanize(capitalize: false),
          target_date: I18n.l(@school_target.target_date, format: '%b %Y')) %>
  </h1>
  <div>
    <%= link_to t('schools.school_targets.progress.expired.review_targets'),
                school_school_target_path(@school, @school_target),
                class: 'btn btn-outline-dark rounded-pill font-weight-bold' %>
    <%= link_to_help_for_feature :school_targets, css: 'btn btn-outline-dark rounded-pill font-weight-bold' %>
  </div>
</div>

<p>
  <%= t('schools.school_targets.progress.expired.your_school_set_a_target_to_reduce_its_usage_html',
        fuel_type: @fuel_type.to_s.humanize(capitalize: false),
        school_target_attributes: @school_target.attributes[@fuel_type.to_s],
        start_date: nice_dates(@school_target.start_date),
        target_date: nice_dates(@school_target.target_date)) %>.
</p>

<% if @latest_progress %>
  <% if @latest_progress >= 0.0 %>
    <p>
      <%= t('schools.school_targets.progress.expired.you_didnt_achieve_your_goal_to_reduce',
            fuel_type: human_fuel_type(@fuel_type)) %>
    </p>
  <% else %>
    <p>
      <%= t('schools.school_targets.progress.expired.you_managed_to_reduce_your_usage',
            fuel_type: human_fuel_type(@fuel_type),
            relative_percent: format_target(@latest_progress,
                                            :relative_percent)).html_safe %>.
    </p>
  <% end %>
<% end %>

<% if @progress %>
  <h3><%= t('schools.school_targets.progress.expired.month_by_month_progress') %></h3>

  <table class="table table-bordered table-hover table-sm">
    <thead class="thead-dark">
    <tr>
      <th>
        <%= t('schools.school_targets.progress.expired.month') %>
      </th>
      <% @reporting_months.each do |month| %>
        <th class="text-right">
          <%= month.strftime('%b') %>
        </th>
      <% end %>
    </tr>
    </thead>
    <tbody>
    <%= render 'row', title: t('schools.school_targets.progress.expired.target_consumption_kwh'),
                      progress: @progress,
                      data: @progress.monthly_targets_kwh, keys: @reporting_months,
                      partial_months: {}, percentage_synthetic: @progress.percentage_synthetic,
                      units: :kwh, final_row: false %>
    <%= render 'row', title: t('schools.school_targets.progress.expired.actual_consumption_kwh'),
                      progress: @progress,
                      data: @progress.monthly_usage_kwh, keys: @reporting_months,
                      partial_months: @progress.partial_months, percentage_synthetic: {},
                      units: :kwh, final_row: false %>
    <%= render 'row', title: t('schools.school_targets.progress.expired.overall_change_since_last_year'),
                      progress: @progress,
                      data: @progress.monthly_performance,
                      keys: @reporting_months, partial_months: @progress.partial_months, percentage_synthetic: {},
                      units: :relative_percent, final_row: true %>
    </tbody>
  </table>

  <h3><%= t('schools.school_targets.progress.expired.cumulative_progress') %></h3>

  <table class="table table-bordered table-hover table-sm">
    <thead class="thead-dark">
    <tr>
      <th>
        <%= t('schools.school_targets.progress.expired.month') %>
      </th>
      <% @reporting_months.each do |month| %>
        <th class="text-right">
          <%= month.strftime('%b') %>
        </th>
      <% end %>
    </tr>
    </thead>
    <tbody>
    <%= render 'row', title: t('schools.school_targets.progress.expired.target_consumption_kwh'),
                      data: @progress.cumulative_targets_kwh, keys: @reporting_months,
                      partial_months: {}, percentage_synthetic: @progress.percentage_synthetic,
                      units: :kwh, final_row: false %>
    <%= render 'row', title: t('schools.school_targets.progress.expired.actual_consumption_kwh'),
                      data: @progress.cumulative_usage_kwh, keys: @reporting_months,
                      partial_months: @progress.partial_months, percentage_synthetic: {},
                      units: :kwh, final_row: false %>
    <%= render 'row', title: t('schools.school_targets.progress.expired.overall_performance_since_last_year'),
                      data: @progress.cumulative_performance, keys: @reporting_months,
                      partial_months: @progress.partial_months, percentage_synthetic: {},
                      units: :relative_percent, final_row: true %>
    </tbody>
  </table>

  <%= render 'footnotes', fuel_type: @fuel_type, school_target: @school_target,
                          show_storage_heater_notes: @show_storage_heater_notes, progress: @progress %>

<% end %>