BathHacked/energy-sparks

View on GitHub
app/views/admin/dcc_consents/index.html.erb

Summary

Maintainability
Test Coverage
<h1>DCC Consents</h1>

<h2>Total schools with DCC consents: <%= @dcc_consent_calcs.total_schools_with_consents %></h2>
<h2>Total meters with DCC consents: <%= @dcc_consent_calcs.total_meters_with_consents %></h2>

<% if @dcc_consent_calcs.orphan_consents.any? %>
  <h2>MPANs in n3rgy list but not in our DCC records</h2>
  <% @dcc_consent_calcs.orphan_consents.each do |mpxn|  %>
    <p><%= "#{mpxn}" %></p>
  <% end %>
<% end %>

<br>
<br>

<% @dcc_consent_calcs.grouped_meters.each do |school_group, school_meters| %>
  <div class="nav-anchor">
    <% if school_group %>
      <h2><%= "#{school_group.name} (#{school_meters.count} consented schools)" %></h2>
    <% else %>
      <h2><%= "No group (#{school_meters.count} consented schools)" %></h2>
    <% end %>
  </div>

  <table class="table">
    <thead>
    <tr>
      <th>School</th>
      <th>Consented meters</th>
      <th>MPAN</th>
      <th>Type</th>
      <th>Reviewed</th>
      <th>User consented?</th>
      <th>DCC consented?</th>
      <th>Active?</th>
      <th>Actions</th>
    </tr>
    </thead>
    <tbody>
    <% school_meters.each do |school, meters| %>
      <% meters.each do |meter| %>
      <tr>
        <td><%= link_to school.name, school_meters_path(school) if meter == meters.first %></td>
        <td><%= meters.count if meter == meters.first %></td>
        <td><%= link_to meter.mpan_mprn, school_meter_path(school, meter) %></td>
        <td><%= meter.meter_type.capitalize %></td>
        <td><%= link_to nice_dates(meter.meter_review.created_at), admin_school_meter_review_path(school, meter.meter_review) if meter.meter_review %></td>
        <td><%= meter.meter_review.present? %></td>
        <td><%= meter.consent_granted? %></td>
        <td><%= meter.active? %></td>
        <td>
          <% if meter.can_withdraw_consent? && can?(:withdraw_consent, meter) %>
            <%= link_to 'Withdraw consent', admin_withdraw_dcc_consent_path(mpxn: meter.mpan_mprn), method: :post, class: 'btn btn-info btn-sm' %>
          <% end %>
          <% if meter.can_grant_consent? && can?(:grant_consent, meter) %>
            <%= link_to 'Grant consent', admin_grant_dcc_consent_path(mpxn: meter.mpan_mprn), method: :post, class: 'btn btn-info btn-sm' %>
          <% end %>
        </td>
      </tr>
      <% end %>
    <% end %>
    </tbody>
  </table>
<% end %>