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

{% block app_content %}
    <div class="row">
        <div class="hidden">{{ wtf.quick_form(delete_benchmark_form, id="delete-benchmark-form") }}</div>
        <div class="col-md-12">
            <table id="benchmarks" class="table table-striped table-bordered table-hover">
            <caption>Benchmarks</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>
                        {% if not current_user.is_anonymous %}
                          <th scope="col"></th>
                        {% endif %}
                    </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 not current_user.is_anonymous %}
                         <td data-href="{{ url_for('app.benchmark', benchmark_id=benchmark.id) }}"
                             data-toggle="modal"
                             data-target="#confirm-delete"
                             data-form-id="#delete-benchmark-form"
                             data-message="<ul><li>Delete benchmark: <strong>{{ benchmark.id }}</strong></li></ul>">
                             <span class="glyphicon glyphicon-trash submenu"></span>
                         </td>
                         {% endif %}
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}

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