{% extends "base.html" %}
{% load grafana %}
{% block content %}

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="{% url 'grafana:org-list' %}">Organizations</a></li>
    <li class="breadcrumb-item active" aria-current="page">
      <a href="{% url 'grafana:org-detail' object.organization.pk %}">{{ object.organization.name }}</a>
    </li>
    <li class="breadcrumb-item active" aria-current="page">
      <a href="{% url 'grafana:dash-detail' object.pk %}">
        {{object.title}}
      </a>
    </li>
  </ol>
</nav>

<a href="{{object.get_public_link}}">View on Grafana</a>

<ul class="nav nav-tabs">
  <li class="nav-item">
    <a class="nav-link active" href="#json" data-toggle="tab">JSON</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#mutators" data-toggle="tab">Mutators</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#versions" data-toggle="tab">Versions</a>
  </li>
</ul>

<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="json">
    <pre>{{object.data|json}}</pre>
  </div>

  <div role="tabpanel" class="tab-pane" id="mutators">
    <table class="table">
      {% for driver in mutators %}
      <form method="post" action="{% url 'grafana:dash-mutate' object.pk %}">
        {% csrf_token %}
        <input name="driver" value="{{driver.model}}" type="hidden" />
        <tr>
          <td>{{driver.name}}</td>
          <td>{{driver.help}}</td>
          <td>{{driver.model}}</td>
          <td>
            <button class="btn btn-warning">Preview</button>
          </td>
        </tr>
      </form>
      {% endfor %}
    </table>
  </div>

  <div role="tabpanel" class="tab-pane" id="versions">
    <table class="table">
      <tr>
        <th>Version</th>
        <th>Created</th>
        <th>Created by</th>
        <th>Message</th>
      </tr>
      {% for version in object.version_set.all|dictsortreversed:'created' %}
      <tr>
        <td><a href="{{version.get_absolute_url}}">{{version.version}}</a></td>
        <td>{{version.created}}</td>
        <td>{{version.created_by.login}}</td>
        <td>{{version.message}}</td>
      </tr>
      {% endfor %}
    </table>
  </div>

</div>

{% endblock %}
