<div class='row'>
  <div class='col-lg-12'>
    <ol class='breadcrumb'>
      <li><a href='/packages/<%= @package.prefix %>'><%= @package.prefix %></a></li>
      <li><a href='/packages/<%= @package.prefix %>/<%= @package.name %>'><%= @package.name %></a></li>
      <li class='active'><%= @suite %>/<%= @architecture %></li>
    </ol>

    <h2>
      <%= @package.name %>
      <small>
        [ <%= @suite %>/<%= @architecture %> ]
      </small>
      <%= @package_links %>
    </h2>

    <div class='job-list-legend'>
      Legend:
      <span class='pinned-false'>Test with packages from <em><%= @suite %></em> only</span>
      <span class='pinned-true'>Test with packages from other suites</span>
    </div>

    <% if @package.blacklisted? %>
      <div class='alert alert-warning'>
        This package is currently <a href="/status/blacklist/">blacklisted</a> and will not have any new test runs.
      </div>
    <% end %>

    <table class="table job-list">
      <tr>
        <th>Version</th>
        <th>Date</th>
        <th>Trigger/Pinned packages</th>
        <th>Duration</th>
        <th colspan='2'>Status</th>
        <th>Requestor</th>
        <th>Results</th>
        <th></th>
        <th></th>
      </tr>

      <% Array(@history).each do |test| %>
	<tr class='pinned-<%= test.pinned? %>'>
	  <td><%= test.version %></td>
	  <td><%= test.date %></td>
	  <td>
	    <% title = title_test_trigger_pin(test) %>
	    <% if title %>
	      <div class='trigger-pinned-packages' title='<%= title %>'>
		<div class='trigger'>
		  <em><%= h test.trigger&.truncate(40) %></em>
		</div>
		<% if test.pinned? %>
		  <div class='pinned-packages'>
		    <%= expand_pin_packages(test).truncate(40).gsub("\n", '<br/>') %>
		  </div>
		<% end %>
	      </div>
	    <% end %>
	  </td>
	  <td><%= test.duration_human %></td>
	  <td>
	    <%= icon(test.status) %>
	    <%= test.status %>
	  </td>
	  <td>
	    <a href="/api/v1/retry/<%= test.run_id %>"><i class='fa fa-recycle'></i></a>
	  </td>
	  <td><a href="/user/<%= test.requestor %>/jobs?package=<%= @package.name %>&suite[]=<%= @suite %>&arch[]=<%= @architecture %>"><%= test.requestor %></a></td>
	  <% package_dir = [test.suite, test.arch, test.package.prefix, test.package.name].join('/') %>
	  <% if @artifacts_url_base %>
	    <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= test.run_id %>/log.gz">test log</a></td>
	    <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= test.run_id %>/artifacts.tar.gz">artifacts</a></td>
	  <% else %>
	    <% if test.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, test.run_id.to_s) %>
	      <td>
		<%= filesize(File.join(dirname,'log.gz'),"<a href=\"/data/autopkgtest/#{package_dir}/#{test.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}/#{test.run_id}/artifacts.tar.gz\">artifacts</a> <small>(%s)</small>")%>
	      </td>

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

    </table>

    <p>Automate:</p>

    <% automation_info = "<code># latest status of the package\n" +
                          "$ curl #{@site_url}/#{@packages_dir}/#{@package_dir}/latest.json\n\n"

        if not @artifacts_url_base
                automation_info += "# latest autopkgtest log of the package\n" +
                          "$ curl #{@site_url}/#{@packages_dir}/#{@package_dir}/latest-autopkgtest/log.gz\n\n"
        end

        automation_info += "# test run history of the package\n" +
                          "$ curl #{@site_url}/#{@packages_dir}/#{@package_dir}/history.json</code>"
    %>

    <pre><%= automation_info %></pre>

  </div>
</div>
