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

{% block app_content %}
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item active">
          <a href="{{ url_for('app.run', run_id=benchmark.run_id) }}">Run</a>
        </li>
        <li class="breadcrumb-item active">
          <a href="{{ url_for('app.batch', batch_id=benchmark.batch_id) }}">Batch</a>
        </li>
        <li class="breadcrumb-item active">Benchmark</li>
        <li class="breadcrumb-item active" aria-current="page">{{ benchmark.id }}</li>
      </ol>
    </nav>


    <div id="plot-history" align="center"></div>
    <br/>

    <div class="row">
      <div class="col-md-6">
        <ul class="list-group">
          <li class="list-group-item active">Benchmark</li>
            <li class="list-group-item" style="overflow-y: auto;">
              <b>benchmark</b>
              <div class="ellipsis-500" align="right" style="display:inline-block; float: right;">
                {{ benchmark.display_name }}
              </div>
            </li>
            <li class="list-group-item" style="overflow-y: auto;">
              <b>batch</b>
              <div align="right" style="display:inline-block; float: right;">
                <a href="{{ url_for('app.batch', batch_id=benchmark.batch_id ) }}">{{ benchmark.display_batch }}</a>
              </div>
            </li>
            <li class="list-group-item" style="overflow-y: auto;">
              <b>run</b>
              <div align="right" style="display:inline-block; float: right;">
                <a href="{{ url_for('app.run', run_id=benchmark.run_id) }}">{{ benchmark.run_id }}</a>
              </div>
            </li>
            {% if run and not run.commit.url and run.commit.display_repository %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>repository</b>
              <div align="right" style="display:inline-block; float: right;">
                <a href="{{ run.commit.repository }}">{{ run.commit.display_repository }}</a>
              </div>
            </li>
            {% endif %}
            {% if run.name %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>reason</b>
              <div align="right" style="display:inline-block; float: right;">
                {{ run.name }}
              </div>
            </li>
            {% endif %}
            <li class="list-group-item active">Result</li>
            <li class="list-group-item" style="overflow-y: auto;">
              <b>timestamp</b>
              <div align="right" style="display:inline-block; float: right;">
                {{ benchmark.display_timestamp }}
              </div>
            </li>
          {% for k,v in benchmark.stats.items() %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>{{ k }}</b>
              {% if v is not none %}
                <div align="right" style="display:inline-block; float: right;">{{ v }}</div>
              {% endif %}
            </li>
          {% endfor %}
            <li class="list-group-item active">Tags</li>
          {% for k,v in benchmark.tags.items() %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>{{ k }}</b>
              {% if v is not none %}
                <div align="right" style="display:inline-block; float: right;">{{ v }}</div>
              {% endif %}
            </li>
          {% endfor %}
        </ul>
      </div>

      <div class="col-md-6">
        <ul class="list-group">
            {% if run and run.commit.url %}
            <li class="list-group-item active">Commit</li>
            <li class="list-group-item" style="overflow-y: auto;">
              <b>commit</b>
              <div class="ellipsis-500" align="right" style="display:inline-block; float: right;">
                {% if run.commit.message %}
                <a href="{{ run.commit.url }}">{{ run.commit.message }}</a>
                {% else %}
                <a href="{{ run.commit.url }}">{{ run.commit.sha }}</a>
                {% endif %}
              </div>
            </li>
            {% if run.commit.display_timestamp %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>date</b>
              <div align="right" style="display:inline-block; float: right;">
                {{ run.commit.display_timestamp }}
              </div>
            </li>
            {% endif %}
            {% if run.commit.message %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>author</b>
              <div align="right" style="display:inline-block; float: right;">
                {{ run.commit.author_name }}
              </div>
            </li>
            {% endif %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>repository</b>
              <div align="right" style="display:inline-block; float: right;">
                <a href="{{ run.commit.repository }}">{{ run.commit.display_repository }}</a>
              </div>
            </li>
            {% endif %}
            <li class="list-group-item active">Machine</li>
            {% for k,v in run.machine.items() %}
            <li class="list-group-item" style="overflow-y: auto;">
              <b>{{ k }}</b>
              <div align="right" style="display:inline-block; float: right;">{{ v }}</div>
            </li>
            {% endfor %}
            <li class="list-group-item active" >Context</li>
            {% for k,v in benchmark.context.items() %}
              <li class="list-group-item" style="overflow-y: auto;">
                <b>{{ k }}</b>
                <div align="right" style="display:inline-block; float: right;">{{ v }}</div>
              </li>
            {% endfor %}
        </ul>
      </div>
    </div>

    <div class="row">
        <div class="col-md-8">
            {{ wtf.quick_form(form, id="benchmark-form", button_map={'delete': 'primary'}) }}
        </div>
    </div>


{% endblock %}

{% block scripts %}
{{super()}}

{{ resources | safe }}

<script type="text/javascript">
$(document).ready(function($) {
    $("#benchmark-form").find("#delete").attr("type", "button");
    $("#benchmark-form").find("#delete").attr("data-toggle", "modal");
    $("#benchmark-form").find("#delete").attr("data-target", "#confirm-delete");
    $("#benchmark-form").find("#delete").attr("data-form-id", "#benchmark-form");
    $("#benchmark-form").find("#delete").attr("data-href", "{{ url_for('app.benchmark', benchmark_id=benchmark.id) }}");
    $("#benchmark-form").find("#delete").attr("data-message", "<ul><li>Delete benchmark: <strong>{{ benchmark.id }}</strong></li></ul>");
});

{% if plot_history %}
$(document).ready(function() {
    Bokeh.embed.embed_item({{ plot_history | safe }});
});
{% endif %}

</script>
{% endblock %}
