<h1>Publish Tests</h1>
<% if defined?(@success) && @success %>
  <div class="alert alert-success" role="alert">Tests Published Successfully!</div>
<% elsif @jobs.length == 0 %>
  <div class="panel panel-danger">
    <div class="panel-heading"><h4>No private tests selected!</h4></div>
  </div>
<% else %>
  <h4>Are you sure you want to publish the following <%= @jobs.length %> tests?</h4>
  <table class="table table-striped">
    <tr>
      <td>Date</td>
      <td>Package</td>
      <td>Suite</td>
      <td>Architecture</td>
      <td>Status</td>
      <td>Duration</td>
      <td>Trigger</td>
      <td>Pin-Packages</td>
      <td colspan='2'>Results</td>
    </tr>
  <% Array(@jobs).each do |test| %>
  <tr>
      <td><%= test.date %></td>
      <td><%= test.package.name %></td>
      <td><%= test.suite %></td>
      <td><%= test.arch %></td>
      <td>
      <%== icon(test.status) %>
      <%= test.status %>
      </td>
      <td>
      <%= test.duration_human %>
      </td>
      <td><%= h test.trigger %></td>
      <td>
      <% expand_pin_packages(test).each do |pin| %>
          <%= pin.truncate(40) %> <br/>
      <% end %>
      </td>
      <% package_dir = [test.suite, test.arch, test.package.prefix, test.package.name].join('/') %>
      <% if !test.status %>
      <td><span class='fa fa-clock-o' title='Results are not in yet'></span></td>
      <td><span class='fa fa-clock-o' title='Results are not in yet'></span></td>
      <td><span class='fa fa-clock-o' title='Results are not in yet'></span></td>
      <% elsif test.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>
      <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>
          <%== file_link(test.log_size, "<a href=\"/data/autopkgtest/#{package_dir}/#{test.run_id}/log.gz\">test log</a> <small>(%s)</small>") %>
      </td>
      <td>
          <%== file_link(test.artifacts_size, "<a href=\"/data/autopkgtest/#{package_dir}/#{test.run_id}/artifacts.tar.gz\">artifacts</a> <small>(%s)</small>") %>
      </td>
      <% end %>
  </tr>
  <% end %>
  </table>
  <div class="row">
    <div class="col-xs-3 col-sm-1">
      <div class="form-group">
        <form action="/user/<%= params[:user] %>/test/publish" method="post">
          <input type="hidden" name="run_ids" value="<%= params[:run_ids].join(',') %>"/>
          <button type="submit" class="btn btn-secondary" autocomplete="off">
          Publish
          </button>
        </form>
      </div>
    </div>
    <div class="col-xs-3 col-sm-1">
      <div class="form-group">
        <form action="/user/<%= params[:user] %>/jobs">
          <button type="submit" class="btn btn-secondary" autocomplete="off">
          Cancel
          </button>
        </form>
      </div>
    </div>
  </div>
<% end %>
