BathHacked/energy-sparks

View on GitHub
app/views/schools/advice/index/_page_list.html.erb

Summary

Maintainability
Test Coverage
<% AdvicePage.display_fuel_types.keys.each_with_index do |fuel_type, idx| %>
  <div class="col">
    <% if display_advice_page?(school, fuel_type) %>
      <div class="row mt-4">
        <div class="col-3">
          <h4>
            <span class="<%= fuel_type_class(fuel_type) %>">
              <%= fa_icon(fuel_type_icon(fuel_type)) %>
            </span>
            <%= t("advice_pages.nav.sections.#{fuel_type}") %>
          </h4>
        </div>
        <div class="col-7"></div>
        <div class="col-2 <%= idx.zero? ? 'bg-light' : '' %>">
          <% if idx == 0 %>
            <div class="advice-page-benchmark-label">
              <strong><%= t('advice_pages.index.show.how_do_you_compare') %></strong>
            </div>
          <% end %>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <% sort_by_label(advice_pages.where(fuel_type: fuel_type)).each do |ap| %>
            <div class="mt-3 row d-flex align-items-center">
              <div class="col-3">
                <h5 class="advice-page-label"><%= link_to translated_label(ap), advice_page_path(school, ap) %></h5>
              </div>
              <div class="col">
                <% if ap.key == 'solar_pv' %>
                  <% solar_status = @school.has_solar_pv? ? 'has_solar' : 'no_solar' %>
                  <%= t("advice_pages.index.show.page_summary.solar_pv.#{solar_status}") %>
                <% else %>
                  <%= t("advice_pages.index.show.page_summary.#{ap.key}") %>
                <% end %>
              </div>
              <% school_benchmark = advice_page_benchmarks.where(advice_page: ap).first %>
              <% if school_benchmark.present? %>
                <div class="col-2 bg-<%= school_benchmark.benchmarked_as %>">
                  <div class="advice-page-benchmark-colored-label">
                    <%= link_to t("advice_pages.benchmarks.#{school_benchmark.benchmarked_as}"),
                                advice_page_path(school, ap) %>
                  </div>
                </div>
              <% else %>
                <div class="col-2 bg-light">
                  <div class="advice-page-benchmark-muted-label">
                    <% if can_benchmark?(advice_page: ap) %>
                      <%= t('advice_pages.index.show.not_available') %>
                    <% else %>
                      <%= t('advice_pages.index.show.not_applicable') %>
                    <% end %>
                  </div>
                </div>
              <% end %>
            </div>
          <% end %>
        </div>
      </div>
    <% end %>
  </div>
<% end %>