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

{% block extrahead %}{{ block.super }}
<style>
    table td.faulty {
        background-color: var(--message-error-bg);
        font-weight: lighter;
    }
    table td.correct {
        background-color: var(--message-success-bg);
        font-weight: bold;
    }
</style>
{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% translate '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; {{ title }}
</div>
{% endblock %}

{% block content %}
<table class="table-bordered table-condensed table-striped">
    <thead>
    <tr>
        <th>{% trans "No." %}</th>
        <th>{% trans "Name" %}</th>
        <th>{% trans "Fully qualified domain name" %}</th>
        <th>{% trans "ping info" %}</th>
    </tr>
    </thead>
    <tbody>
    {% for entry in data %}
        <tr>
            <td>{{ forloop.counter }}</td>
            <td>{{ entry.name }}</td>
            <td>{{ entry.fqdn }}</td>
            <td>
                {% if entry.error %}
                    <pre>{{ entry.error }}</pre>
                {% else %}
                    <table class="table-bordered table-condensed table-striped">
                        <thead>
                        <tr>
                            <th>{% trans "HostModel.ip_v4.verbose_name" %}</th>
                            <th>{% trans "HostModel.mac.verbose_name" %}</th>
                            <th>{% trans "Output" %}</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for result in entry.ping_info %}
                            <tr>
                                <td>{{ result.ip_address }}</td>
                                <td>{{ result.mac_addresses|join:" | " }}</td>
                                <td class="{% if result.returncode == 0 %}correct{% else %}faulty{% endif %}">
                                    <pre>{{ result.output }}</pre>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                {% endif %}
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
{% endblock %}