{% import "utils.html" as utils %}

{% extends "layout.html" %}{
{% set components = [(ts.name, v4_url_for(".v4_recent_activity"))] %}
{% block title %}Order: {{order.id}}{% endblock %}

{% block sidebar %}
  <ul class="nav nav-list bs-docs-sidenav">
    <li><a href="#fields"><i class="icon-chevron-right"></i> Fields</a></li>
    <li><a href="#submissions"><i class="icon-chevron-right"></i> Submissions</a></li>
  </ul>
{% endblock %}

{% block body %}
  {# Provide links to the previous and next orders. #}
  <ul class="pager">
    {% if order.previous_order_id is not none %}
      <li class="previous"><a href="{{v4_url_for('.v4_order', id=order.previous_order_id)}}">
    {% else %}
      <li class="previous disabled"><a href="#">
    {% endif %}
    ← Previous</a></li>

    {% if order.next_order_id is not none %}
      <li class="next" ><a href="{{v4_url_for('.v4_order', id=order.next_order_id)}}">
    {% else %}
      <li class="next disabled"><a href="#">
    {% endif %}
    Next →</a></li>
  </ul>

  <section id="fields">
  <h3>Order Fields</h3>
  <table class="table table-striped table-hover table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>ID</th>
        {% for field in order.fields %}
           <th>{{field.name}}</th>
        {% endfor %}
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Current Order</td>
        <td>{{order.id}}</td>
        {% for field in order.fields %}
                <td>{{order.get_field(field)}}</td>
        {% endfor %}
      </tr>
      {% if previous_order %}
      <tr>
        <td>Previous Order</td>
          <td>
              <a href="{{ v4_url_for(".v4_order", id=order.previous_order_id) }}">
                  {{order.previous_order_id}}
              </a>
          </td>
          {% for field in previous_order.fields %}
                <td>
                    {{previous_order.get_field(field)}}
                </td>
          {% endfor %}
      </tr>
      {% endif %}

      {% if next_order %}
      <tr>
        <td>Next Order</td>
          <td><a href="{{ v4_url_for(".v4_order", id=order.next_order_id) }}">{{order.next_order_id}}</a></td>
          {% for field in next_order.fields %}
                <td>{{next_order.get_field(field)}}</td>
          {% endfor %}
      </tr>
      {%  endif %}
    </tbody>
  </table>
  </section>

  <section id="baseline">
  <div class="accordion" id="accordion">
    <div class="accordion-group">
      <div class="accordion-heading">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
           {% if form.name.data %}
               Baseline - {{ form.name.data }}
            {% else %}
               Configure as a baseline
            {% endif %}
        </a>
      </div>
      <div id="collapseOne" class="accordion-body collapse">
        <div class="accordion-inner">
          <form method="POST" action="">
            <div class="form-group">
         {{ form.hidden_tag() }}
            {{ utils.render_field(form.name) }}
            {{ utils.render_field(form.description) }}
           {% if form.name.data %}
                {{ form.update }}
                {{ form.demote }}
                {% else %}
                {{ form.promote }}
          {% endif %}
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

  </section>

  <section id="submissions">
  {# List all submissions which reported for this order. #}
  <h3>Submissions</h3>
  <b>Num. Submissions:</b> {{num_runs}}
  <table class="table table-striped table-hover table-condensed">
    <thead>
      <tr>
        <th>Start Time</th>
        <th>Duration</th>
        <th>Machine</th>
        <th>Results</th>
      </tr>
    </thead>
    <tbody>
      {# Show the active submissions. #}
      {% for run in runs %}
      <tr>
        <td><span class="utctime">{{ run.start_time.isoformat() }}</span></td>
        <td>{{run.end_time - run.start_time}}</td>
        <td>{{ utils.render_machine(run.machine) }}</td>
        <td>{{ utils.render_result(run) }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
  </section>
{% endblock %}
