{% extends "base.html" %}
{% load backend_tags %}
{% load humanize %}
{% block content %}
{% with output=res.json %}
<h1>{{ section }}</h1>

{% if section == 'index' %}
<ul>
  {% for r in output.result.resources %}
  <li><a href="{% url "backend:service_status" %}?cmd={{ r.URI }}&section={{ r.name }}">{{ r.display_name }}</li>
  {% endfor %}
</ul>
{% endif %}
{% if section == 'test_status' %}
  {% for r in output.result %}
    {% if forloop.first %}
    <h2>{{ r.sla_name }} / {{ r.service_name }}</h2>
    {% endif %}
    {% if forloop.first %}
    <table class='table table-striped table-bordered'>

    <thead>
      <tr>
      <th>Timestamp</th>
      {% for r0 in r.results_scores %}
      <th class='text-end'>{{ r0.name }} / Score</th>
      {% endfor %}
      </tr>
    </thead>
    {% endif %}
      <tr>
        <td>{{ r.time_stamp_display }}</td>
        {% for r0 in r.results_scores %}
        <td class='text-end'>{{ r0.raw_value|intcomma }} / {{ r0.score }}</td>
        {% endfor %}
      </tr>
    {% if forloop.last %}
    </table>
    {% endif %}
  {% endfor %}
{% endif %}
{% if section == 'ConfigCur' %}
<ul>
  {% for r in output.result %}
  <li><a class='text-decoration-none' href="{% url "backend:service_status" %}?cmd={{ r.ids.test_instance_uri }}&section=test_instance">{{ r.ids.test_display_name }} / {{ r.ids.test_type_name }}</a> <a href="{% url "backend:service_status" %}?cmd=/API/REST/Status/v1/TestStatus/{{ r.ids.test_instance_id }}&section=test_status" class='ms-3 text-decoration-none badge bg-primary'>Status</a></li>
  {% endfor %}
</ul>
{% endif %}
{% if section == 'test_type' %}
    {% with ids=output.result.ids %}
      {{ ids.test_display_name }}
      {{ ids.test_type_name }}
      <a href="{% url "backend:service_status" %}?cmd={{ ids.mdf_uri }}&section=mdf" class='text-decoration-none badge bg-primary'>MDF URI</a>
      <a href="{% url "backend:service_status" %}?cmd={{ ids.test_type_uri }}&section=test_type" class='text-decoration-none badge bg-primary'>Test Type</a>
    {% endwith %}
{% endif %}
{% if section == 'test_define' %}
{% endif %}
{% if section == "detail" %}
<h1>{{ output.result.ids.service_name }}</h1>
<a href="{% url "backend:service_status" %}?cmd={{ output.result.ids.overall_service_status_uri }}&section=overall">Overall</a>
<table class='table table-bordered table-striped'>
  <thead>
    <tr><th>Status</th><th>Result</th></tr>
  </thead>
  <tbody>
  {% for k,v in output.result.service_status.items %}
  <tr>
  <td>{{ k }}</td><td>{{ v }}</td>
  </tr>
  {% endfor %}
  </tbody>
</table>

<h3>Test Templates</h3>
<ul>
  {% for si in  output.result.test_templates %}
  <li>{{ si.test_name }} 
    <a href="{% url "backend:service_status" %}?cmd={{ si.test_defn_uri }}&section=test_define" class='text-decoration-none badge bg-primary'>Test Define</a>
    <a href="{% url "backend:service_status" %}?cmd={{ si.test_type_uri }}&section=test_type" class='text-decoration-none badge bg-primary'>Test Type</a>
    <a href="{% url "backend:service_status" %}?cmd={{ si.test_name|config_cur }}&section=ConfigCur" class='text-decoration-none badge bg-primary'>Config Cur</a>
  </li>
  {% endfor %}
</ul>
{% endif %}
{% if section == "overall" %}
<h1>Overall</h1>
<div class='table-responsive'>
<table class='table table-striped table-bordered'>
  <thead>
    <tr>
  {% for k in output.result.0.keys %}
  <th>{{ k }}</th>
  {% endfor %}
    </tr>
  </thead>
  <tbody>
  {% for o in output.result %}
    <tr>
      {% for k1,v1 in o.items %}
      <td>{{ v1 }}</td>
      {% endfor %}
    </tr>
  {% endfor %}
  </tbody>
</table>
</div>
{% endif %}
{% endwith %}
  <p>
    <a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
      Raw JSON
    </a>
  </p>
  <div class="collapse" id="collapseExample">
    <div class="card card-body">
      <pre>
        {{ res.json | pprint }}
      </pre>
    </div>
  </div>


{% endblock %}
