<table class="table job-list">
  <tr>
    <% if fields.include?(:package) %>
      <th>Package</th>
    <% end %>
    <% if fields.include?(:suite) %>
      <th>Suite</th>
    <% end %>
    <% if fields.include?(:arch) %>
      <th>Architecture</th>
    <% end %>
    <% if fields.include?(:version) %>
      <th>Version</th>
    <% end %>
    <% if fields.include?(:date) %>
      <th>Date</th>
    <% end %>
    <% if fields.include?(:backend) %>
      <th>Backend</th>
    <% end %>
    <% if fields.include?(:trigger) %>
      <th>Trigger/Pinned packages</th>
    <% end %>
    <% if fields.include?(:duration) %>
      <th>Duration</th>
    <% end %>
    <% if fields.include?(:status) %>
      <th colspan='2'>Status</th>
    <% end %>
    <% if fields.include?(:requestor) %>
      <th>Requestor</th>
    <% end %>
    <% if fields.include?(:results) %>
      <th colspan='2'>Results</th>
    <% end %>
    <% if fields.include?(:requested) %>
      <th>Requested</th>
    <% end %>
  </tr>
  <% Array(jobs_list).each do |job| %>
    <tr class='pinned-<%= job.pinned? %>'>
    <% if fields.include?(:package) %>
      <td><a href="/packages/<%= job.package.prefix %>/<%= job.package.name%>/"><%= job.package.name %></a></td>
    <% end %>
    <% if fields.include?(:suite) %>
      <td><%= job.suite %></td>
    <% end %>
    <% if fields.include?(:arch) %>
      <td><%= job.arch %></td>
    <% end %>
    <% if fields.include?(:version) %>
      <% if job.version %>
        <td><%= job.version %></td>
      <% else %>
        <td><a href="/status/queue/"><em>TBD</em></a></td>
      <% end %>
    <% end %>
    <% if fields.include?(:date) %>
      <% if job.date %>
        <td><%=  job.date %></td>
      <% else %>
        <td>
          <small><a href="/status/queue/"><em>requested: <%= job.created_at %></em></a></small>
        </td>
      <% end %>
    <% end %>
    <% if fields.include?(:backend) %>
      <td><%= job.backend %></td>
    <% end %>
    <% if fields.include?(:trigger) %>
      <td>
        <% title = title_test_trigger_pin(job) %>
        <% unless title.blank? %>
          <div class='trigger-pinned-packages' title='<%= title %>'>
            <div class='trigger'>
              <em><%= h job.trigger&.truncate(40) %></em>
            </div>
            <% if job.pinned? %>
              <div class='pinned-packages'>
                <% expand_pin_packages(job).each do |p| %>
                  <%= p.truncate(40) %> <br/>
                <% end %>
              </div>
            <% end %>
          </div>
        <% end %>
      </td>
    <% end %>
    <% if fields.include?(:duration) %>
      <td><%= job.duration_human %></td>
    <% end%>
    <% if fields.include?(:status) %>
      <td>
        <%== icon(job.status) %>
        <%= job.status %>
      </td>
      <td>
        <% if logged_in? %>
          <a href="/user/<%= @user.username %>/retry/<%= job.run_id %>" ><i class='fa fa-recycle'></i></a>
        <% else %>
          <i class='fa fa-recycle' title="Login to be able to retry jobs"></i>
        <% end %>
      </td>
    <% end %>

    <% if fields.include?(:requestor) %>
      <td><a href="/user/<%= job.requestor.username %>/jobs?package=<%= job.package.name %>&suite[]=<%= job.suite %>&arch[]=<%= job.arch %>"><%= job.requestor.username %></a></td>
    <% end %>

    <% package_dir = [job.suite, job.arch, job.package.prefix, job.package.name].join('/') %>
    <% if fields.include?(:results) %>
      <% if !job.status %>
        <td colspan='2'><a href="/status/queue/"><em>(pending)</em></a></td>
      <% elsif job.files_purged? %>
        <td><span class='fa fa-trash' title='file has been removed due to data retention policy'></span></td>
        <td><span class='fa fa-trash' title='file has been removed due to data retention policy'></span></td>
      <% else %>
        <% dirname = File.join(Debci.config.data_basedir, 'autopkgtest', package_dir, job.run_id.to_s) %>
        <td>
          <%== file_link(job.log_size, "<a href=\"#{job.run_id}/\">test log</a> &nbsp; <a href=\"/data/autopkgtest/#{package_dir}/#{job.run_id}/log.gz\"><span class=\"fa fa-download\"></span></a> <small>(%s)</small>") %>
        </td>
        <td>
          <%== file_link(job.artifacts_size, "<a href=\"/data/autopkgtest/#{package_dir}/#{job.run_id}/artifacts.tar.gz\">artifacts</a> <small>(%s)</small>") %>
        </td>
      <% end %>
    <% end %>

    <% if fields.include?(:requested) %>
      <td><a href="/status/queue/"><%= job.created_at %> | <%= job.time %></a></td>
    <% end %>

    </tr>
  <% end %>
</table>
