{% extends "admin/base_site.html" %}
{% load i18n static admin_urls admin_modify %}

{% block title %}{% trans 'Inspect' %}{% if active %} {% trans 'DB' %}: {{ active.id }}{% endif %} - {{ original }}{% endblock %}

{% block extrahead %}
  {{ block.super }}
  <script src="{% url 'admin:jsi18n' %}"></script>
  {{ media }}
{% endblock %}

{% block extrastyle %}{{ block.super }}
  <link rel="stylesheet" type="text/css" href="{% static 'admin/css/forms.css' %}">
  <link rel="stylesheet" type="text/css" href="{% static 'redisboard/admin.css' %}"/>
{% endblock %}

{% block coltype %}colM{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} inspect-form{% endblock %}

{% block breadcrumbs %}
  <div class="breadcrumbs">
    <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
    &rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
    &rsaquo; <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
    &rsaquo; <a href="{% url opts|admin_urlname:'change' original.id %}">{{ original|truncatewords:"18" }}</a>
    {% if active %}
      &rsaquo; <a href="{% url opts|admin_urlname:'inspect' original.id %}">{% trans 'Inspect' %}</a>
      &rsaquo; <a href="{% url opts|admin_urlname:'inspect' original.id active.id %}">{% trans 'DB' %}: {{ active.id }}</a>
    {% else %}
      &rsaquo; {% trans 'Inspect' %}
    {% endif %}
  </div>
{% endblock %}

{% block content %}
  {% spaceless %}
    <div id="content-main" class="module">
      <h1>{% trans "Inspect" %}</h1>
      <ul class="object-tools">
        <li><a href="{% url opts|admin_urlname:'details' original.id %}">{% trans "Details" %}</a></li>
        <li><a href="{% url opts|admin_urlname:'change' original.id %}">{% trans "Change" %}</a></li>
      </ul>

      {% if not active %}
        <table class="server-status">
          <thead>
          <tr>
            <th>{% trans 'Status' %}</th>
            <th>{% trans 'Memory' %}</th>
            <th>{% trans 'Clients' %}</th>
            <th>{% trans 'Details' %}</th>
            <th>{% trans 'CPU Utilization' %}</th>
            <th>{% trans 'Slowlog' %}</th>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td>{{ stats.status }}</td>
            <td>{{ stats.memory }}</td>
            <td>{{ stats.clients }}</td>
            <td>{{ display.details }}</td>
            <td>{{ display.cpu }}</td>
            <td class="field-slowlog">{{ display.slowlog }}</td>
          </tr>
          </tbody>
        </table>
      {% endif %}
      {% for db in databases %}
        {% with db.scan as scan %}
          <fieldset class="module aligned key-details">
            <h2 id="db-{{ db.id }}">
              {% trans 'Database' %} {{ db.id }}:
              {% if scan %}
                {% if scan.count < db.stats.keys %}
                  {% blocktrans with total=scan.total count count=scan.count %}
                    {{ count }} key ({{ total }} total)
                  {% plural %}
                    {{ count }} keys ({{ total }} total)
                  {% endblocktrans %}
                {% else %}
                  {% blocktrans count count=scan.count %}
                    {{ count }} key
                  {% plural %}
                    {{ count }} keys
                  {% endblocktrans %}
                {% endif %}
                &larr;
              {% else %}
                {% blocktrans count total=db.stats.keys %}
                  {{ total }} key
                {% plural %}
                  {{ total }} keys
                {% endblocktrans %}
                &ndash;
                <a href="{% url 'admin:redisboard_redisserver_inspect' original.id db.id %}{{ filters }}">{% trans 'Show details' %}</a>
              {% endif %}
            </h2>
            {% if scan %}
              {{ scan.data }}
              {% if scan.cursor or db.cursor %}
                <p class="paginator">
                  {% if db.cursor %}
                    <a href="{% url 'admin:redisboard_redisserver_inspect' server_id=original.id db=db.id %}{{ filters }}">
                      {% trans 'Reset' %}</a>
                  {% endif %}
                  <span class="this-page">at cursor: {{ db.cursor }}</span>
                  {% if scan.cursor %}
                    <a
                      href="
                        {% url 'admin:redisboard_redisserver_inspect' server_id=original.id db=db.id cursor=scan.cursor %}{{ filters }}">
                      {% trans 'Next' %}</a>
                  {% endif %}
                </p>
              {% endif %}
            {% endif %}
          </fieldset>
        {% endwith %}
      {% empty %}
        <fieldset class="module aligned database-details">
          <h2>{% trans 'No database found!' %}</h2>
        </fieldset>
      {% endfor %}
    </div>
  {% endspaceless %}
{% endblock %}
