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

{% block title %}Inspect {{ original }}{% endblock %}

{% block extrahead %}{{ block.super }}
  {% url 'admin:jsi18n' as jsi18nurl %}
  <script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
  {{ media }}
{% endblock %}

{% block extrastyle %}
  {{ block.super }}
  {% get_static_prefix as STATIC_PREFIX %}
  {% get_media_prefix as MEDIA_PREFIX %}

  <link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}">
  <link rel="stylesheet" type="text/css" href="{{ STATIC_PREFIX|default:MEDIA_PREFIX }}redisboard/admin.css"/>
{% endblock %}

{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}

{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} inspect-form{% endblock %}

{% if is_popup %}
  {% block breadcrumbs %}
    <div class="breadcrumbs">
      <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
      &rsaquo; <a href="{% url 'admin:app_list' app_label='redisboard' %}">{{ 'redisboard'|capfirst|escape }}</a>
      &rsaquo; <a href="{% url 'admin:redisboard_redisserver_changelist' %}">{{ 'redisserver'|capfirst }}</a>
      &rsaquo; <a href="{% url 'admin:redisboard_redisserver_change' original.id %}">{{ original|truncatewords:"18" }}</a>
      {% if active %}
        &rsaquo; <a href="{% url 'admin:redisboard_redisserver_inspect' original.id %}">{% trans 'Inspect' %}</a>
        &rsaquo; <a href="{% url 'admin:redisboard_redisserver_inspect' original.id active.id %}">{% trans 'DB' %}: {{ active.id }}</a>
      {% else %}
        &rsaquo; {% trans 'Inspect' %}
      {% endif %}
    </div>
  {% endblock %}
{% endif %}

{% block content %}
  {% spaceless %}
    <div id="content-main" class="module">
      <h1>{% trans "Inspect" %}</h1>
      {% 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 %}
