{% extends "dashboard_app/_content_with_sidebar.html" %}
{% load i18n %}
{% load humanize %}


{% block sidebar %}
<div class="ui-widget">
  <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0.7em">
    <span
      class="ui-icon ui-icon-info"
      style="float: left; margin-right: 0.3em;"></span>
    <strong>Note:</strong> This is all the information that the dashboard has
    about this result. Log analyzers can provide additional information by
    scrubbing it from the log file.  Information that is global to a test run
    can be attached to test run attributes instead.
  </div>
</div>
<br/>
{% if test_result.test_run.get_results.count > 1 %}
<h3>Other results</h3>
<p class="hint">Results from the same test run are available here</p>
<select id="other_results">
  {% regroup test_result.test_run.get_results by test_case as test_result_group_list %}
  {% for test_result_group in test_result_group_list %}
  {% if test_result_group.list|length > 1 %}<optgroup label="Results for test case {{ test_result_group.grouper }}">{% endif %}
    {% for other_test_result in test_result_group.list %}
    <option value="{{ other_test_result.get_absolute_url }}"
    {% if other_test_result.pk == test_result.pk %}disabled selected{% endif %}
    >
      Result #{{ other_test_result.relative_index }}: {{ other_test_result.get_result_display }}
      {% if test_result_group.list|length == 1 %} from test case {{ test_result_group.grouper }}{% endif %}
      {% if other_test_result.measurement != None %} ({{ other_test_result.measurement }}){% endif %}
    </option>
    {% endfor %}
  {% if test_result_group.list|length > 1 %}</optgroup>{% endif %}
  {% endfor %}
</select>
<script type="text/javascript">
  $("#other_results").change(function (event) {
    location.href=$(this).val();
  });
</script>
{% endif %}
{% endblock %}


{% block content %}
<h2>{% trans "Test Result Details" %}</h2>
<dl>
  <dt>{% trans "Result ID:" %}</dt>
  <dd>
  {{ test_result }}
  <div class="ui-widget" style="width: 30em">
    <div class="ui-state-highlight ui-corner-all" style="padding: 0.7em">
      <span
        class="ui-icon ui-icon-info"
        style="float: left; margin-right: 0.3em;"></span>
      <strong>{% trans "Note:" %}</strong>
      {% blocktrans %}
      You can navigate to this test result, regardless of the bundle stream it is
      located in, by using this
      {% endblocktrans %}
      <a href="{{ test_result.get_permalink }}" >{% trans "permalink" %}</a>
    </div>
  </div>
  </dd> 
  <dt>{% trans "Test case:" %}</dt>
  <dd>
  {% if test_result.test_case %}
    <b>{{ test_result.test_case }}</b>
  {% else %}
  <i>{% trans "unknown test case" %}</i>
  {% endif %}
  {% trans "from test" %} <b><a href="{{ test_result.test_run.test.get_absolute_url }}">{{ test_result.test_run.test }}</a></b>
  </dd>
  <dt>{% trans "Test outcome:" %}</dt>
  <dd>{{ test_result.get_result_display }}</dd>
  <dt>{% trans "Measurement:" %}</dt>
  <dd>
  {% if test_result.measurement != None %}
    {{ test_result.measurement|floatformat }} {{ test_result.test_case.units }}
  {% else %}
    <i>{% trans "no measurement taken" %}</i>
  {% endif %}
  </dd>
  <dt>{% trans "Location in the original log file:" %}</dt>
  <dd>
    {% if test_result.filename %}
        {% if test_result.related_attachment_available %}
        {% with test_result.related_attachment as attachment %}
        <a href="{{ attachment.get_absolute_url }}">{{ test_result.filename }}</a> line <a href="{{ attachment.get_absolute_url }}#L{{test_result.lineno}}">{{ test_result.lineno }}</a>
        {% endwith %}
        {% else %}
            {{ test_result.filename }} line {{ test_result.lineno }}
        {% endif %}
    {% else %}
        <i>{% trans "information not provided" %}</i>
    {% endif %}
  </dd>
  <dt>{% trans "Message from the log file:" %}</dt>
  <dd>
  {% if test_result.message %}
    <code>{{ test_result.message }}</code>
  {% else %}
    <i>{% trans "information not provided" %}</i>
  {% endif %}
  </dd>
  <dt>{% trans "Test started on:" %}</dt>
  <dd>
  {% if test_result.timestamp %}
    {{ test_result.timestamp|naturalday }}
    {{ test_result.timestamp|time }}
  {% else %}
    <i>{% trans "information not provided" %}</i>
  {% endif %}
  </dd>
  <dt>{% trans "Test duration:" %}</dt>
  <dd>
  {% if test_result.duration %}
    {# TODO need a filter for displaying this sensibly. Currently there are some rounding errors #}
    {{ test_result.duration }}
  {% else %}
    <i>{% trans "information not provided" %}</i>
  {% endif %}
  </dd>
  <dt>{% trans "Custom attributes (defined at test result level):" %}</dt>
  <dd>
  {% with test_result.attributes.values as attrs %}
  {% if attrs %}
  <dl>
    {% for item in attrs|dictsort:"name" %}
    <dt>{{ item.name|title }}</dt>
    <dd>{{ item.value }}</dd>
    {% endfor %}
  </dl>
  {% else %}
  <i>{% trans "none specified" %}</i>
  {% endif %}
  {% endwith %}
  </dd>
  <dt>{% trans "Custom attributes (defined at test run level):" %}</dt>
  <dd>
  {% with test_result.test_run.attributes.values as attrs %}
  {% if attrs %}
  <dl>
    {% for item in attrs|dictsort:"name" %}
    <dt>{{ item.name|title }}</dt>
    <dd>{{ item.value }}</dd>
    {% endfor %}
  </dl>
  {% else %}
  <i>{% trans "none specified" %}</i>
  {% endif %}
  {% endwith %}
  </dd>
</dl>
{% endblock %}
