{% extends "nexus/module.html" %}

{% block head %}
    {{ block.super }}
    <link rel="stylesheet" href="{{ nexus_media_prefix }}/redis/css/redis.css">
    <script src="{{ nexus_media_prefix }}/redis/js/redis.js"></script>
{% endblock %}

{% load redis_helpers %}

{% block content %}
    <ul class="tabs">
        <li class="active"><a href="{% url redis:index %}">All Connections</a></li>
        <li><a href="{% url redis:by-server %}">Physical Hosts</a></li>
    </ul>
    <p>Displaying statistics for {{ cache_stats|length }} Redis server{{ cache_stats|length|pluralize }}</p>
    {% for group, hosts in cache_stats.iteritems %}
        <h2>{{ group|title }}</h2>
        <ul class="server-list">
            {% for server, stats in hosts %}
                <li class="server server-{% if stats.online %}online{% else %}offline{% endif %}" id="{{ forloop.index }}">
                    <h3>{{ server.host }}{% if server.port %}:{{ server.port }}{% endif %}{% if server.db %} (db {{ server.db }}){% endif %}</h3>
                    {% if stats.online %}
                        <button class="button small toggle">Expand</button>
                    {% endif %}
                    <table>
                        <colgroup>
                            <col width="35%"/>
                            <col/>
                        </colgroup>
                        <tbody>
                            <tr>
                                <th>Uptime:</th>
                                <td>
                                    {% if stats.online %}
                                        {{ stats.uptime_in_seconds|duration }}
                                    {% else %}
                                        Offline
                                    {% endif %}
                                </td>
                            </tr>
                            <tr>
                                <th>Usage:</th>
                                <td>
                                    {% if stats.online %}
                                        {{ stats.used_memory|humanize_bytes }}
                                    {% else %}
                                        <em>n/a</em>
                                    {% endif %}
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    {% if stats.online %}
                        <div class="more">
                            <table>
                                <caption>Detailed Statistics</caption>
                                <colgroup>
                                    <col width="35%"/>
                                    <col/>
                                </colgroup>
                                {% for k, v in stats.iteritems %}
                                    <tr>
                                        <th>{{ k|titlize }}</th>
                                        <td>{{ v|intcomma }}</td>
                                    </tr>
                                {% endfor %}
                            </table>
                        </div>
                    {% endif %}
                </li>
            {% endfor %}
        </ul>
    {% endfor %}
{% endblock %}