<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><%= job.package.name %></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 %>
      <td><a href="/user/<%= job.requestor.username %>/jobs?package=<%= @package.name %>&suite[]=<%= @suite %>&arch[]=<%= @architecture %>"><%= job.requestor.username %></a></td>
      <% package_dir = [job.suite, job.arch, job.package.prefix, job.package.name].join('/') %>
    <% if fields.include?(:results) %>
      <% if @artifacts_url_base %>
        <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= job.run_id %>/log.gz">test log</a></td>
        <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= job.run_id %>/artifacts.tar.gz">artifacts</a></td>
      <% else %>
        <% if job.expired? %>
          <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>
            <%== filesize(File.join(dirname,'log.gz'),"<a href=\"/data/autopkgtest/#{package_dir}/#{job.run_id}/log.gz\">test log</a> <small>(%s)</small>")%>
          </td>
          <td>
            <%== filesize(File.join(dirname,'artifacts.tar.gz'),"<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> 