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

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

{% block sidebar %}
  <ul class="nav nav-list bs-docs-sidenav">
    <li><a href="{{ v4_url_for(".v4_machine_latest", machine_id=machine.id) }}"><i class="icon-time"></i> Latest Run</a></li>
    <li><a href="#fields"><i class="icon-chevron-right"></i> Fields</a></li>
    <li><a href="#parameters"><i class="icon-chevron-right"></i> Parameters</a></li>
    <li><a href="#submissions"><i class="icon-chevron-right"></i> Submissions</a></li>
  </ul>

  <h4>Relatives</h4>
  <ul class="nav nav-list bs-docs-sidenav">
    {# List all machines with this name. #}
    {% for m in relatives %}
    <li>{{ utils.render_machine(m) }}</li>
    {% endfor %}
  </ul>
{% endblock %}

{% block body %}
  <section id="fields">
  <h3>Fields</h3>
  <table class="table table-striped table-hover table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Value</th>
      </tr>
    </thead>
    {% for item in ts.machine_fields %}
    <tr>
      <td>{{item.name}}</td>
      <td>{{machine.get_field(item)}}</td>
    </tr>
    {% endfor %}
  </table>
  </section>

  <section id="parameters">
  <h3>Parameters</h3>
  <table class="table table-striped table-hover table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Value</th>
      </tr>
    </thead>
    {% for key,value in machine.parameters|dictsort %}
    <tr>
      <td>{{key}}</td>
      <td>{{ utils.newline_to_br(value) }}</td>
    </tr>
    {% endfor %}
  </table>
  </section>

    <section id="compare">
        <h3>Compare</h3>
            <p>Compare the latest run on this machine with the latest run on another.</p>

            <form action="{{ v4_url_for(".v4_machine_compare", machine_id=machine.id)}}" method="get">
                <p>
                Compare {{ machine.name }} to
                <select name="compare_to_id">
                    {%  for machine in machines %}
                        <option value="{{ machine.id }}">{{ machine.name }}:{{ machine.id }}</option>
                    {% endfor %}
                </select>
                </p>
                <p>
                    <input class="btn" type="submit" value="Compare"/>
                </p>

            </form>
    </section>

  <section id="submissions">
  <h3>Submissions</h3>
  <table class="table table-striped table-hover table-condensed">
    <thead>
      <tr>
        <th>Run Order</th>
        <th>Start Time</th>
        <th>Duration</th>
        <th>&nbsp;</th>
      </tr>
    </thead>
    {% for order,runs in associated_runs|sort|reverse %}
    {% for run in runs %}
    <tr>
      {% if loop.first %}
      <td rowspan="{{ runs|length }}" style="text-align:right">{{local.render_order_link(order)}}</td>
      {% endif %}
      <td><span class="utctime">{{ run.start_time.isoformat() }}</span></td>
      <td>{{ run.end_time - run.start_time }}s</td>
      <td>{{ utils.render_result(run) }}</td>
    </tr>
    {% endfor %}
    {% endfor %}
  </table>
  </section>
{% endblock %}
