{% extends "layouts/content.html" %}
{% load django_tables2 %}
{% load i18n %}
{% load static %}
{% load utils %}

{% block content %}
    <h2>LAVA Results for {{ job_link }}
      <span
          class="label {% if job.health == job.HEALTH_COMPLETE %}label-success{% else %}label-warning{% endif %}"
          {% if job.health == job.HEALTH_COMPLETE %}title="All submitted definitions have started execution."{% endif %}>{{ job.get_state_display }}
      </span>
    </h2>

<div class="row">
  <div class="col-md-4">
    <h4 class="modal-header">Exports
        </h4>
    <dl class="dl-horizontal">
      <dt>Test results summary :</dt>
      <dd><a class="btn btn-xs btn-info" href="{% url 'lava.results.testjob_yaml_summary' job.id %}"
         title="Download test job summary as YAML"><span class="glyphicon glyphicon-download"></span> YAML</a></dd>
      <dt>Test results :</dt>
      <dd><a class="btn btn-xs btn-info" href="{% url 'lava.results.testjob_csv' job.id %}"
         title="Download results as CSV"><span class="glyphicon glyphicon-download"></span> CSV</a> or <a
              class="btn btn-xs btn-info" href="{% url 'lava.results.testjob_yaml' job.id %}"
         title="Download results as YAML"><span class="glyphicon glyphicon-download"></span> YAML</a></dd>
      <dt>Job metadata :</dt>
      <dd><a class="btn btn-xs btn-info" href="{% url 'lava.results.job.metadata' job.id %}"
         title="Download metadata as YAML"><span class="glyphicon glyphicon-download"></span> YAML</a></dd>
    </dl>
  </div>
  <div class="col-md-4">
    <h4 class="modal-header">Actions</h4>
    <a href="#" data-toggle="modal" data-target="#similar_jobs_modal" class="btn btn-primary">Similar jobs</a>
  </div>
  <div class="col-md-4">
    <h4 class="modal-header">Details</h4>
    {% if job.actual_device %}
    <dl class="dl-horizontal">
        <dt>Device :</dt>
        <dd><a href="{{ job.actual_device.get_absolute_url }}">{{ job.actual_device.hostname }}</a></dd>
    {% endif %}
{% if job.is_multinode %}
    <dl class="dl-horizontal">
{% for role in job.sub_jobs_list %}
  {% if role.id != job.id %}
     <dt>{{ role.device_role }} role:</dt>
     <dd><a href="{{ role.results_link }}">{{ role.sub_id }}</a> ({{ role.id }})</dd>
  {% else %}
     <dt>{{ role.device_role }} role:</dt>
     <dd>{{ role.sub_id }} ({{ role.id }})</dd>
  {% endif %}
{% endfor %}
{% endif %}
    </dl>
  </div>
</div>
    {% render_table suite_table %}
<div class="panel-group" id="results_accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4><a data-toggle="collapse" data-parent="#results_accordion" href="#metadata_collapse">
        Metadata
      </a>
      </h4>
    </div>
  {% spaceless %}
    <div id="metadata_collapse" class="panel-collapse collapse">
      <div class="panel-body">
      <p>The <b>key</b> is the name of the metadata named attribute which can be used in query conditions.
          Values relating to devices, device-types and URLs are formatted as links. Due to
          the variation between different git server interfaces, it is not possible to construct
          a full URL to the test definition file. The commit id of the test definition is part of
          the <i>lava</i> results for the job.
      </p>
      <p>Inline test definitions which do not call <code>lava-test-case</code> will not record any
      results and are shown in the metadata with the <code>omitted</code> prefix.</p>
      <p>Attributes relating to items which can repeat within a single job include a number representing
          the sequence of that item within the job. For example, <i>boot.0.method</i> is the name of an
          attribute containing information on the first boot method used in the job. <i>boot.0.commands</i>
          would be an attribute containing information on the commands used by the first boot method in
          the job.
      </p>
      <p>Metadata submitted as part of the job submission is also included, if present.</p>
       <div class="row">
       <div class="col-xs-12">
        <ul>
          {% for key, value in metadata.items %}
              {% if 'target' in key %}
                  <li><b>{{ key }}</b>:
                  {{ key|markup_metadata:value }}</li>
              {% elif 'deploy' in key %}
                  <li><b>{{ key }}</b>:
                  {{ value }}</li>
              {% elif 'omit.' in key %}
                  <!-- inline without test cases -->
              {% elif 'boot' in key %}
                  <li><b>{{ key }}</b>:
                  {{ value }}</li>
              {% elif 'test' in key %}
                  <li><b>{{ key }}</b>:
                  {{ key|markup_metadata:value }}</li>
              {% elif 'parameters' in key %}
                  <li><b>{{ key }}</b>:
                  <ul>{% for paramkey, paramvalue in value.items %}
                      <li>{{ paramkey }}: {{ paramvalue }}</li>
                      {% endfor %}
                  </ul></li>
              {% else %}
                  <li><b>{{ key }}</b>:
                  {{ value }}</li>
              {% endif %}
          {% endfor %}
        </ul>
        </div>
        </div>
      </div>
    </div>
  {% endspaceless %}
  </div>
 </div>

<div class="panel-group" id="notifications_accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4><a data-toggle="collapse" data-parent="#notifications_accordion" href="#notification_collapse">
        Notifications
      </a>
      </h4>
    </div>
  {% spaceless %}
    <div id="notification_collapse" class="panel-collapse collapse">
      <div class="panel-body">
        {% if job.notification.notificationrecipient_set.all %}
        <dl class="dl-horizontal">
          {% for recipient in job.notification.notificationrecipient_set.all %}
          <dt>Recipient</dt>
          {% if recipient.method == 1 %}
          <dd>{{ recipient.irc_handle_name }} on {{ recipient.irc_server_name }}</dd>
          {% else %}
          <dd>{{ recipient.email_address }}</dd>
          {% endif %}
          <dt>Method</dt>
          <dd>{{ recipient.get_method_display }}</dd>
          <dt>Status</dt>
          <dd>{{ recipient.get_status_display }}</dd>
          <br/>
          {% endfor %}
        </dl>
        {% else %}
        No notifications for this job.
        {% endif %}
      </div>
    </div>
  {% endspaceless %}
  </div>
</div>

{% include "_similar_jobs.html" %}

{% endblock %}
{% block scripts %}
<script>
  var condition_choices = JSON.parse($("#id_condition_choices").val());
</script>
<script src="{% static "lava_server/js/jquery.typeahead.js" %}"></script>
<script src="{% static "lava_scheduler_app/js/tables.js" %}"></script>
<script src="{% static "lava_scheduler_app/js/similar-jobs.js" %}"></script>
{% endblock %}
