{% extends 'base.html' %}

{% load extra %}

{% block content %}

<div class="row">
  <div class="col-xs-12">
    <div class="col-xs-1"><h2><i class="glyphicon glyphicon-{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}signal{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}arrow-up{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}ok{% elif check.polymorphic_ctype.model == 'icmpstatuscheck' %}transfer{% endif %}"></i></h2></div>
    <div class="col-xs-5"><h2>{{ check.name }}</h2></div>
    <div class="col-xs-4 text-right"><h2><span class="label label-{% if check.calculated_status == 'passing' %}success{% else %}danger{% endif %}">{{ check.calculated_status|capfirst }}</span></h2></div>
    <div class="col-xs-2 text-right"><h2>
      {% if check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}
        <a href="{% jenkins_human_url check.name %}" class=""><i class="glyphicon glyphicon-link"></i></a>
      {% endif %}
      <a href="{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}{% url "update-graphite-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}{% url "update-http-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}{% url "update-jenkins-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'icmpstatuscheck' %}{% url "update-icmp-check" pk=check.id %}{% endif %}" class=""><i class="glyphicon glyphicon-edit"></i>
      <a href="{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}{% url "duplicate-graphite-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}{% url "duplicate-http-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}{% url "duplicate-jenkins-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'icmpstatuscheck' %}{% url "duplicate-icmp-check" pk=check.id %}{% endif %}" class=""><i class="fa fa-copy"></i>
      </a> <a href="{% url "run-check" pk=check.id %}"><i class="glyphicon glyphicon-refresh"></i></a>
    </h2></div>
  </div>
</div>
<hr>
<div class="row">
  <div class="col-xs-12">
    <div class="col-xs-1"><h3><i class="fa fa-list"></i></h3></div>
    <div class="col-xs-11"><h3>Check results</h3></div>
  </div>
  <div class="col-xs-12">
    {% if not checkresults %}
      <div class="col-xs-11 col-xs-offset-1">No results for this check</div>
    {% else %}
    <table class="table table-striped table-bordered">
      <thead>
        <tr>
          <th>Status</th>
          <th>Time started</th>
          <th>Time complete</th>
          <th>Took (ms)</th>
          <th>Error</th>
        </tr>
      </thead>
      <tbody>
      {% for result in checkresults %}
        <tr>
          <td>
            <span class="label {% if result.succeeded %}label-success{% else %}label-danger{% endif %}">{{ result.status }}
            </span>
          </td>
          <td>
            <a href="{% url "result" pk=result.id %}">{{ result.time }}</a>
          </td>
          <td>{{ result.time_complete }}</td>
          <td>{{ result.took }}</td>
          <td>{% autoescape off %}{{ result.error|default:"" }}{% endautoescape %}</td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
    {% endif %}
  </div>
</div>
<hr>
<div class="row">
  {% for service in check.service_set.all %}
  {% if service.hackpad_id or service.runbook_link%}
  <div class="col-xs-12">
    <div class="col-xs-1"><h3><i class="fa fa-exclamation-triangle"></i></h3></div>
    <div class="col-xs-11"><h3>Documentation for linked service <a href="{% url "service" service.id %}">{{ service.name }}</a></h3></div>
    {% if service.runbook_link %}
    <div class="col-xs-11 col-xs-offset-1">
      Runbook Link: <a href="{{ service.runbook_link }}">{{ service.runbook_link }}</a>
    </div>
    {% endif %}
    {% if service.hackpad_id %}
    <div class="col-xs-11 col-xs-offset-1">
      Displaying <a href="{{ service.hackpad_id }}">{{ service.hackpad_id }}</a>:
      <script src="{{ service.hackpad_id }}"></script>
    </div>
    {% endif %}
  </div>
  {% endif %}
  {% endfor %}
</div>
{% endblock content %}

{% block js %}
{% load compress %}
{{ block.super }}
{% compress js %}
<script type="text/coffeescript">

</script>
{% endcompress %}
{% endblock js %}
