<nav aria-label="breadcrumb">
<ol class="breadcrumb">
  <li class="breadcrumb-item"><a href="/user">Welcome <%= @user.username %>!</a></li>
  <li class="breadcrumb-item active">Request Test</li>
</ol>
</nav>
<% if defined?(@error_msg) && @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 defined?(@success) && @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-secondary" 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" value="<%= params[: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 <%= "selected" if suite == params[:suite] %> value="<%= suite %>"><%= 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| %>
                <div class="arch-checkbox">
                  <input id="arch-<%= arch %>" name="arch[]" type="checkbox" value="<%= arch %>" <%= "checked" if params[:arch]&.include?(arch) || !params[:arch] %>>
                  <label for="arch-<%= arch%>">
                    <%= arch %>
                  </label>
                </div>
              <% end %>
            </div>
          </div>
        </div>
      </div>
      <div class="col-xs-12 col-sm-6">
        <div class="form-group">
          <label for="backend">Backend</label>
          <select class="form-control" id="backend" name="backend">
            <option value="">(package default)</option>
            <% settings.backends.each do |backend| %>
            <option <%= "selected" if backend == params[:backend] %> value="<%= backend %>"><%= backend %></option>
            <% end %>
          </select>
        </div>
      </div>
      <div class="col-xs-12 col-sm-6">
        <div class="form-group">
          <label for="autopkgtest">autopkgtest</label>
          <select class="form-control" id="autopkgtest" name="autopkgtest">
            <option <%= "selected" if params[:autopkgtest].blank? %> value="">default</option>
            <% settings.autopkgtest_variants.each do |v| %>
            <option <%= "selected" if v == params[:autopkgtest] %> value="<%= v %>"><%= v %></option>
            <% end %>
          </select>
        </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" value="<%= params[:trigger] %>">
        </div>
      </div>
      <div class="col-xs-12 col-sm-6">
        <label>Private</label>
        <div class="form-group">
          <label class="radio-inline">
            <input type="radio" name="is_private" value=true <%= 'checked' if params[:is_private] == 'true' %>>Yes
          </label>
          <label class="radio-inline">
            <input type="radio" name="is_private" value=false <%= 'checked' if params[:is_private] != 'true' %>>No
          </label>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12 col-sm-6">
        <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"><%= params[:pin_packages] %></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>
      </div>
      <div class="col-xs-12 col-sm-6">
        <div class="form-group">
          <label for="extra-apt-sources">Extra APT Sources (optional)</label>
          <select class="form-control" id="extra-apt-sources" name="extra_apt_sources[]" multiple>
            <% Debci.extra_apt_sources_list.allowed_extra_apt_sources(@user).each do |extra_apt_source| %>
              <option <%= "selected" if params[:extra_apt_sources]&.include?(extra_apt_source) %>><%= extra_apt_source %></option>
            <% end %>
          </select>
          <p class="help-block">
          You can select multiple Extra APT Sources. Hold down the control (ctrl) button and click on entries to select/deselect.
        </p>
          <p class="help-block">
          <strong>Notes:</strong>
          <ul>
            <li>
              When you add extra APT sources and use pinning, you must
              explicitly add <em>all</em> sources needed to resolve your
              pinnings.
            </li>
            <li>New archives can be added by talking to the admins.</li>
          </ul>
          </p>
        </div>
      </div>
    </div>
  </div>
    <button type="submit" name="submit" class="btn btn-secondary" autocomplete="off">
      Submit
    </button>
    <button type="submit" name="export" class="btn btn-secondary" 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>arch</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>
      <tr>
        <td>is_private</td>
        <td>Boolean with false as default value</td>
        <td>Specify whether test is private or not</td>
      </tr>
      <tr>
        <td>extra-apt-sources</td>
        <td>Array of apt-sources Arrays (optional)</td>
        <td>Specify extra apt sources to add for the test</td>
      </tr>
    </tbody>
  </table>
  <h4>Pin-packages Array</h4>
  <ul>
    <li>An array of arrays, with each item containing 2 elements</li>
    <li>The first element must be a comma-separated list of package names</li>
    <li>The second slement must be a suite name, which can only be used <strong>once</strong>. Suites available: <%= settings.suites %></li>
    <li>You can use <code>scr:bar</code> to pin all binaries from the specified source package <code>bar</code></li>
  </ul>
  <h4>Example JSON file</h4>
  <p>The example below requests a <code>private</code> test of <code>testpackage</code>, pulling all binaries from source <code>bar</code> from <code>unstable</code>, as well as <code>foo</code> and all <code>baz</code> binaries from <code>experimental</code>.
  </p>
  <pre><code>[
  {
    "arch": ["amd64"],
    "suite": "unstable",
    "tests": [
      {
        "trigger": "testpackage v1.2",
        "package": "testpackage",
        "pin-packages": [
          ["src:bar", "unstable"],
          ["foo,src:baz", "experimental"]
        ],
        "is_private": true
      }
    ]
  }
]</code></pre>
</div>
