<ol class="breadcrumb">
  <li><a href="/user">Welcome <%= @user.username %>!</a></li>
  <li class="active">Request Test</li>
</ol>
<% if @error_msg %>
<div class="panel panel-danger">
  <div class="panel-heading">
    <h3 class="panel-title">Form error</h3>
  </div>
  <div class="panel-body"><%= @error_msg %></div>
</div>
<% end %>
<% if @success %>
<div class="alert alert-success" role="alert">Test submitted successfully!</div>
<% end %>
<header class="well">
  <h1>Request Test</h1>
  <p>You can choose to request a test by either uploading a JSON file or by filling the form.</p>
</header>
<div class="col-xs-12">
  <div class="page-header">
    <h3>Send Request by Uploading JSON File</h3>
  </div>
  <form action="/user/<%= @user.username %>/test/upload" method="post" enctype="multipart/form-data">
    <div class="form-group">
      <input name="tests" type="file" id="submit-json">
      <p class="help-block">You can get an example JSON through exporting the filled-out form below or click <a
          href="#json-doc">here</a> to view the thorough documentation.</p>
    </div>
    <div class="form-group">
      <button type="submit" name="submit" class="btn btn-default" autocomplete="off">
        Upload JSON File
      </button>
    </div>
  </form>
  <div class="page-header">
    <h3>Send Request by Form</h3>
  </div>
  <form action="/user/<%= @user.username %>/test/submit" method="post">
    <div class="row">
      <div class="col-xs-12 col-sm-6">
        <div class="form-group">
          <label for="package">Package Name</label>
          <input class="form-control" id="package" name="package">
        </div>
      </div>
      <div class="col-xs-12 col-sm-6">
        <div class="form-group">
          <label for="suite">Suite</label>
          <select class="form-control" id="suite" name="suite">
            <% settings.suites.each do |suite| %>
            <option><%= suite %></option>
            <% end %>
          </select>
        </div>
      </div>
      <div class="col-xs-12 col-sm-6">
        <label>Architecture</label>
        <div class="row">
          <div class="col-xs-12">
            <div class="form-group">
              <% settings.archs.each do |arch| %>
              <label class="checkbox-inline">
                <input name="arch[]" type="checkbox" value="<%= arch %>"><%= arch %>
              </label>
              <% end %>
            </div>
          </div>
        </div>
      </div>
      <div class="col-xs-12 col-sm-6">
        <div class="form-group">
          <label for="trigger">Trigger (optional)</label>
          <input class="form-control" id="trigger" name="trigger">
        </div>
      </div>
    </div>
    <div class="form-group">
      <label for="pin-packages">Pin Packages (optional)</label>
      <textarea id="pin-packages" name="pin_packages" class="form-control" rows="5" style="resize: vertical"
        placeholder="src:bar, experimental"></textarea>
      <p class="help-block">
        Pin packages are packages that need to be obtained from a different suite than the main suite that you
        selected.<br>
        This is used e.g. to run tests on testing with a few packages from unstable, or on unstable with a few packages
        from experimental.
      </p>
      <p class="help-block">
        Format should be <code>package, ..., package, suite</code><br>
        Examples:<br>
        <ul>
          <li><code>src:bar, unstable</code>: get all binaries built from bar from unstable</li>
          <li><code>foo, src:bar, experimental</code>: get foo and all binaries built from bar from experimental</li>
        </ul>
        <strong>Note: each suite can be only present once. please separate by line.</strong>
      </p>
    </div>
    <button type="submit" name="submit" class="btn btn-default" autocomplete="off">
      Submit
    </button>
    <button type="submit" name="export" class="btn btn-default" autocomplete="off">
      Export to JSON
    </button>
  </form>
  <div id="json-doc" class="page-header">
    <h3>Documentation for JSON file</h3>
  </div>
  <p>The request should be an <strong>array of Test Request objects</strong>.</p>
  <h4>Test Request Object</h4>
  <table class="table">
    <thead>
      <tr>
        <th>property</th>
        <th>type</th>
        <th>description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>archs</td>
        <td>Array of Architectures</td>
        <td>Architectures available: <%= settings.archs %></td>
      </tr>
      <tr>
        <td>suite</td>
        <td>String</td>
        <td>Suites available: <%= settings.suites %></td>
      </tr>
      <tr>
        <td>tests</td>
        <td>Array of Test Objects</td>
        <td>See <strong>Test Object</strong></td>
      </tr>
    </tbody>
  </table>
  <h4>Test Object</h4>
  <table class="table">
    <thead>
      <tr>
        <th>property</th>
        <th>type</th>
        <th>description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>package</td>
        <td>String</td>
        <td>The package that the requestor wants to test</td>
      </tr>
      <tr>
        <td>trigger</td>
        <td>String (optional)</td>
        <td>Works as an identifier for the requestor</td>
      </tr>
      <tr>
        <td>pin-packages</td>
        <td>Array of Pin-packages Arrays (optional)</td>
        <td>See <strong>Pin-packages Array</strong></td>
      </tr>
    </tbody>
  </table>
  <h4>Pin-packages Array</h4>
  <ul>
    <li>An array of Strings with at least 2 elements</li>
    <li>The last element should be a suite and can only be used <strong>once</strong>, Suites available: <%= settings.suites %></li>
    <li><code>:bar</code> can be added to the pin-package to retrieve all binaries for the specified pin-package</li>
  </ul>
  <p>Example JSON file</p>
  <pre><code>[
  {
    "archs": ["amd64"],
    "suite": "unstable",
    "tests": [
      {
        "trigger": "testpackage v1.2",
        "package": "testpackage",
        "pin-packages": [
          ["src:bar", "unstable"],
          ["foo", "src:bar", "experimental"]
        ]
      }
    ]
  }
]</code></pre>
</div>
