sul-dlss/pre-assembly

View on GitHub
app/views/job_runs/discovery_report_summary.html.erb

Summary

Maintainability
Test Coverage

<%# In current reports, objects_with_error is an array; in legacy, it was an integer. %>
<% objects_with_error = @discovery_report['summary']['objects_with_error'] %>
<% objects_with_error_size = objects_with_error.is_a?(Array) ? objects_with_error.size : objects_with_error %>
<div class="row mt-5">
  <div class="col-sm-12">
    <h1><%= link_to @job_run.batch_context.project_name, @job_run.batch_context %> by <%= @job_run.batch_context.user.email %></h1>
    <p><%= @job_run.job_type.humanize %> #<%= @job_run.id %></p>
  </div>
</div>
<turbo-frame id="discovery-report-frame">
  <div class="row mt-5">
    <div class="col-12">
      <table class="table">
        <caption>Results summary</caption>
        <thead>
          <tr>
            <th class="text-center">Number of objects</th>
            <th class="text-center">Number with errors</th>
            <th class="text-center">Total size</th>
            <th class="text-center">Started</th>
            <th class="text-center">Run Time</th>
            <th class="text-center">MIME types</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="text-center"><%= @discovery_report['rows'].size %></td>
            <td class="text-center"><%= objects_with_error_size %></td>
            <td class="text-center"><%= number_to_human_size(@discovery_report['summary']['total_size'], precision: 2) %></td>
            <td class="text-center"><%= @discovery_report['summary']['start_time'].to_time.strftime('%-m/%-d/%y %T') %></td>
            <% if @discovery_report['summary']['end_time'] && @discovery_report['summary']['start_time'] # not all older discovery reports have both times available %>
              <td class="text-center"><%= distance_of_time_in_words(@discovery_report['summary']['end_time'].to_time - @discovery_report['summary']['start_time'].to_time) %></td>
            <% else %>
                <td class="text-center">unknown</td>
            <% end %>
            <td><%= render partial: 'mime_type_summary', locals: { mimetypes: @discovery_report['summary']['mimetypes'] } %></td>
          </tr>
        </tbody>
      </table>

      <% if objects_with_error_size.positive? %>
        <table class="table">
          <caption>Errors Summary</caption>
          <thead class="table">
            <tr>
              <th class="text-center">Druid</th>
              <th class="text-center">Errors</th>
              <th class="text-center">Number of files</th>
              <th class="text-center">Files w/o extension</th>
              <th class="text-center">Total Size</th>
              <th class="text-center">MIME types</th>
            </tr>
          </thead>
          <tbody>
        <% @discovery_report['rows'].each do |row|
            next if row['errors'].blank? %>
              <tr>
                <td><%= row['druid'] %></td>
                <td>
                  <% row['errors'].each do |error, val| %>
                    <%= error %> : <%= val %><br>
                  <% end %>
                </td>
                <td class="text-center"><%= row['counts']['files_found'] %></td>
                <td class="text-center"><%= row['counts']['filename_no_extension'] %></td>
                <td class="text-center"><%= number_to_human_size(row['counts']['total_size'], precision: 2) %></td>
                <td><%= render partial: 'mime_type_summary', locals: { mimetypes: row['counts']['mimetypes'] } %></td>
              </tr>
        <% end %>
        </tbody>
        </table>
      <% end %>

      <%= render partial: 'structural_updates_summary', locals: { druids: @discovery_report['rows'] } if @structural_has_changed %>
    </div>
  </div>
</turbo-frame>