BathHacked/energy-sparks

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

Summary

Maintainability
Test Coverage
<table id="<%= @id %>" class="table table-sm table-striped advice-table">
    <thead>
      <% if @year_header %>
        <tr>
          <th colspan="2"></th>
          <% years_header do |year| %>
            <th class="text-right"><%= year %></th>
          <% end %>
          <th></th>
        </tr>
      <% end %>
      <tr>
        <th colspan="2"></th>
        <% months_header do |month, full_month| %>
          <th class="text-right"><%= month %><%= '<sup>*</sup>'.html_safe if !full_month.nil? && !full_month %></th>
        <% end %>
        <th class="text-right"><%= t('advice_pages.tables.labels.total') %></th>
      </tr>
    </thead>
    <tbody>
      <% all_components.each do |group| %>
        <% group[:list].each do |component| %>
          <% if bill_component?(component: component) %>
            <tr>
              <td>
                <% if component[2] == "_" %>
                  <% component_times = component.to_s.gsub('_to_',' ').gsub('_',':').split(' ') %>
                  <%= t("advice_pages.tables.labels.bill_components.day_night", time_from: component_times.first, time_to: component_times.last) %>
                <% else %>
                  <%= t("advice_pages.tables.labels.bill_components.#{component}") %>
                <% end %>
              </td>
              <td>
                <%= tooltip(component: component) %>
              </td>

              <% bill_component_row(component: component) do |v| %>
                <td class="text-right"><%= v %></td>
              <% end %>
            </tr>
          <% end %>
        <% end %>
      <% end %>
      <tr class="table-success">
        <td><%= t('advice_pages.tables.labels.total') %></td>
        <td></td>
        <% totals_row do |total| %>
          <td class="text-right"><%= total %></td>
        <% end %>
      </tr>
      <% if include_change_in_costs_row? %>
        <tr class="bg-light">
          <td><%= t('advice_pages.tables.labels.change_prev_year') %></td>
          <td></td>
          <% change_in_costs_row do |change| %>
            <td class="text-right"><%= change %></td>
          <% end %>
        </tr>
      <% end %>
    </tbody>
</table>
<% if @any_partial_months %>
  <div class="text-right advice-table-caption">
    <sup>*</sup> <%= t('advice_pages.tables.notice.partial_months')%>
  </div>
<% end %>