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

{% 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_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>
{% if key_details %}
    &rsaquo; <a href="{% url 'admin:redisboard_redisserver_inspect' original.id %}">{% trans 'Inspect' %} {{ original|truncatewords:"18" }}</a>
    &rsaquo; {% trans "Key details" %}: {{ key_details.name }}
{% else %}
    &rsaquo; {% trans 'Inspect' %} {{ original|truncatewords:"18" }}
{% endif %}
</div>
{% endblock %}
{% endif %}

{% block content %}
{% spaceless %}
<div id="content-main">
    <table class="server-status">
        <tr>
            <th>{% trans "Status" %}</th>
            <th>{% trans "Memory" %}</th>
            <th>{% trans "Clients" %}</th>
            <th>{% trans "Details" %}</th>
        </tr>
        <tr>
            <td>{{ stats.status }}</td>
            <td>{{ stats.memory }}</td>
            <td>{{ stats.clients }}</td>
            <td>
                <table>
                {% for key, value in stats.brief_details.items %}
                    <tr><td>{{ key }}</td><td>{{ value }}</td></tr>
                {% endfor %}
                </table>
            </td>
        </tr>
    </table>



    {% for db, db_detail in databases.items %}
        <fieldset class="module aligned database-details">
            <h2>
                {% trans "Database" %} {{ db }}:
                {% if db_detail.sampling %}
                    {% with db_detail.size as total %}
                        {% blocktrans count original.sampling_threshold as size %}
                            {{ size }} random key our of {{ total }}
                        {% plural %}
                            {{ size }} random keys our of {{ total }}
                        {% endblocktrans %}
                    {% endwith %}
                {% else %}
                    {% blocktrans count db_detail.size as size %}
                        {{ size }} key,
                    {% plural %}
                        {{ size }} keys,
                    {% endblocktrans %}
                    {% trans "memory:" %}
                    ~{{ db_detail.total_memory|filesizeformat }} total,
                    ~{{ db_detail.volatile_memory|filesizeformat }} volatile,
                    ~{{ db_detail.persistent_memory|filesizeformat }} persistent
                {% endif %}

                {% if db_detail.active %}
                    &larr;
                {% else %}
                    &ndash; <a href="{% url 'admin:redisboard_redisserver_inspect' original.id %}?db={{ db }}">{% trans "Show details" %}</a>
                {% endif %}
            </h2>
            {% if db_detail.active %}
            <table>
                <tr>
                    <th rowspan="2">{% trans "Keys" %} ({{ db_detail.keys|length }})</th>
                    <th colspan="7">{% trans "Details" %}</th>
                </tr>
                <tr>
                    <th>{% trans "Type" %}</th>
                    <th>{% trans "TTL" %}</th>
                    <th>{% trans "Encoding" %}</th>
                    <th>{% trans "Items" %}</th>
                    <th>{% trans "Idletime" %}</th>
                    <th>{% trans "Refs" %}</th>
                </tr>

                {% for key, key_detail in db_detail.keys.items %}
                <tr>
                    <td><a href="{% url 'admin:redisboard_redisserver_inspect' original.id %}?key={{ key|escape }}&db={{ db }}">{{ key }}</a></td>
                    {% if key_detail.error %}
                    <td class="error" colspan="6">{% trans "ERROR:" %} {{ key_detail.error }}</td>
                    {% else %}
                    <td>{{ key_detail.type }}</td>
                    <td>{{ key_detail.ttl }}</td>
                    <td>{{ key_detail.encoding }}</td>
                    <td>{{ key_detail.length }}</td>
                    <td>{{ key_detail.idletime }}</td>
                    <td>{{ key_detail.refcount }}</td>
                    {% endif %}
                </tr>
                {% endfor %}

            </table>
            {% endif %}
        </fieldset>
    {% endfor %}
    {% if key_details %}
        <fieldset class="module aligned key-details">
            <h2>{% trans "Key details" %}: {{ key_details.name }}</h2>
            <table>
                <tr>
                    <th>{% trans "Type" %}</th>
                    <th>{% trans "TTL" %}</th>
                    <th>{% trans "Encoding" %}</th>
                    <th>{% trans "Items" %}</th>
                    <th>{% trans "Idletime" %}</th>
                    <th>{% trans "Refs" %}</th>
                </tr>
                <tr>
                    {% if key_details.error %}
                    <td class="error" colspan="6">{% trans "ERROR:" %} {{ key_details.error }}</td>
                    {% else %}
                    <td>{{ key_details.type }}</td>
                    <td>{{ key_details.ttl }}</td>
                    <td>{{ key_details.encoding }}</td>
                    <td>{{ key_details.length }}</td>
                    <td>{{ key_details.idletime }}</td>
                    <td>{{ key_details.refcount }}</td>
                    {% endif %}
                </tr>
            </table>
        </fieldset>
        <fieldset class="module aligned key-data">
            <h2>{% trans "Key data" %}: {{ key_details.name }}</h2>
            <table>
                {% for key, value in key_details.data.object_list|default:key_details.data %}
                <tr><td>{{ key }}</td><td>{{ value|pprint }}</td></tr>
                {% endfor %}
            </table>
            {% if key_details.data.paginator and key_details.data.paginator.num_pages > 1 %}
            <p class="paginator">
                {% for nr in key_details.data.paginator.page_range %}
                {% if key_details.data.number == nr %}
                    <span class="this-page">{{ nr }}</span>
                {% else %}
                    <a href="?key={{ key_details.name|escape }}&db={{ key_details.db }}&page={{ nr }}">{{ nr }}</a>
                {% endif %}
                {% endfor %}
                {{ key_details.data.paginator.count }} items
            </p>
            {% endif %}
        </fieldset>
    {% endif %}
</div>
{% endspaceless %}
{% endblock %}
