<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?(: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) %>
      <td><%= job.version %></td>
    <% end %>
    <% if fields.include?(:date) %>
      <td><%=  job.date %></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>
        <a href="/user/:user/retry/<%= job.run_id %>" ><i class='fa fa-recycle'></i></a>
      </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 Debci.config.artifacts_url_base  %>
        <td><a href="<%= Debci.config.artifacts_url_base%>/<%= package_dir %>/<%= job.run_id %>/log.gz">test log</a></td>
        <td><a href="<%= Debci.config.artifacts_url_base %>/<%= package_dir %>/<%= job.run_id %>/artifacts.tar.gz">artifacts</a></td>
      <% else %>
        <% if 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 %>
    <% end %>
    <% if fields.include?(:requested) %>
      <td><%= job.created_at %> | <%= job.time %></td>
    <% end %>
    </tr>
  <% end %>
</table>
