{% extends "app.html" %}
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item active">Run</li>
        {% if run_id %}
        <li class="breadcrumb-item active" aria-current="page">{{ run_id }}</li>
        {% endif %}
        {% if compare_runs_url %}
        <span align="right" style="display:inline-block; float: right;">
          <a href="{{ compare_runs_url }}">compare <span class="glyphicon glyphicon-arrow-right"></span></a>
        </span>
        {% endif %}
      </ol>
    </nav>

    <div class="col-md-12">
        <table id="benchmarks" class="table table-striped table-bordered table-hover">
        <caption>Benchmarks{% include 'units-tooltip.html' %}</caption>
            <thead>
                <tr>
                    <th scope="col">Date</th>
                    <th scope="col">Language</th>
                    <th scope="col">Batch</th>
                    <th scope="col">Benchmark</th>
                    <th scope="col">Mean</th>
                    <th scope="col" nowrap>Z-Score</th>
                </tr>
            </thead>
            <tbody>
                {% for benchmark in benchmarks %}
                <tr>
                     <td style="white-space: nowrap;">{{ benchmark.display_timestamp }}</td>
                     <td style="white-space: nowrap;">{{ benchmark.display_language }}</td>
                     <td style="white-space: nowrap;">
                       <a href="{{ url_for('app.batch', batch_id=benchmark.batch_id) }}">
                         <div>{{ benchmark.display_batch }}</div>
                       </a>
                     </td>
                     <td><a href="{{ url_for('app.benchmark', benchmark_id=benchmark.id) }}">
                         <div>{{ benchmark.display_name }}</div>
                     </a></td>
                     <td>{{ benchmark.display_mean }}</td>
                     {% if benchmark.stats.z_score is not none %}
                       <td>{{ benchmark.stats.z_score }}</td>
                     {% else %}
                       <td></td>
                     {% endif %}
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% if run_id %}
            {{ wtf.quick_form(form, id="run-form", button_map={'delete': 'primary'}) }}
        {%  endif %}
    </div>

{% endblock %}

{% block scripts %}
{{super()}}
<script type="text/javascript">
var table = $('#benchmarks').dataTable( {
    "responsive": true,
    "order": [[0, 'desc']],
    "columnDefs": [{ "orderable": false, "targets": [4] }]
} );

$(document).ready(function() {
    $('#unit-tooltip').tooltip()
    {% if run_id %}
        $("#run-form").find("#delete").attr("type", "button");
        $("#run-form").find("#delete").attr("data-toggle", "modal");
        $("#run-form").find("#delete").attr("data-target", "#confirm-delete");
        $("#run-form").find("#delete").attr("data-form-id", "#run-form");
        $("#run-form").find("#delete").attr("data-href", "{{ url_for('app.run', run_id=run_id) }}");
        $("#run-form").find("#delete").attr("data-message", "<ul><li>Delete run: <strong>{{ run_id }}</strong></li></ul>");
    {% endif %}
   });
</script>
{% endblock %}
