{% import "utils.html" as utils %}
{% set db = request.get_db() %}

{% extends "layout.html" %}
{% set components = [(testsuite_name, v4_url_for(".v4_recent_activity"))] %}
{% block title %}Recent Activity{% endblock %}



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

{% block body %}
  {# Find recent runs. #}
  <section id="machines">
  <h3>Active Machines</h3>
  <table class="table table-striped table-hover table-condensed">
    <thead>
    <tr>
      <th>Machine</th>
      <th>Latest Submission</th>
      <th>Results</th>
    </tr>
    </thead>
    <tbody>
      {# Show the most active machines. #}
      {% for machine_name,r in active_machines|dictsort %}
      <tr>
        <td>{{ utils.render_machine(r.machine) }}</td>
        <td><span class="reltime">{{r.end_time.isoformat()}}</span></td>
        <td>{{ utils.render_result(r) }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
  </section>

  <section id="submissions">
  <h3>Recent Submissions</h3>
  <table class="table table-striped table-hover table-condensed">
    <thead>
    <tr>
      <th>Run Order</th>
      <th>Started</th>
      <th>Duration</th>
      <th>Machine</th>
      <th>Results</th>
    </tr>
    </thead>
    <tbody>
      {# Show the active submissions. #}
      {% for r,run_order in active_submissions %}
      <tr>
        <td><a href="{{v4_url_for('.v4_order', id=r.order.id)}}">{{run_order}}</a></td>
        <td><span class="reltime" data-toggle="tooltip" title="{{r.start_time}}">{{ r.start_time.isoformat() }}</span></td>
        <td>{{ r.end_time - r.start_time }}</td>
        <td>{{ utils.render_machine(r.machine) }}</td>
        <td>{{ utils.render_result(r) }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
  </section>
{% endblock %}
