{% extends 'mesh/base.html' %}
{% load i18n %}
{% load mesh_node %}

{% block heading %}{% trans 'Mesh Nodes' %}{% endblock %}

{% block subcontent %}
    <table>
        <tr>
            <th>{% trans 'Node' %}</th>
            <th>{% trans 'Chip' %}</th>
            <th>{% trans 'Firmware' %}</th>
            <th>{% trans 'Last msg' %}</th>
            <th>{% trans 'Last signin' %}</th>
            <th>{% trans 'Connection' %}</th>
        </tr>
        {% for node in nodes %}
            <tr>
                <td>
                    <a href="{% url "mesh.node.detail" pk=node.address %}">{{ node }}</a>
                    {% if node.ranging_beacon %}
                        <br>
                        <a href="{% url "editor.ranging_beacons.edit" space=node.ranging_beacon.space_id pk=node.ranging_beacon.pk %}">Ranging Beacon #{{ node.ranging_beacon.pk }}</a>
                        {% if node.ranging_beacon.comment and node.ranging_beacon.comment != node.name %}({{ node.ranging_beacon.comment }}){% endif %}
                        in {{ node.ranging_beacon.space.title }}
                    {% endif %}
                </td>
                <td>
                    {{ node.last_messages.CONFIG_BOARD.parsed.content.board_config.board.pretty_name }}<br>
                    <small>({{ node.last_messages.CONFIG_HARDWARE.parsed.content.chip.pretty_name }} rev{{ node.last_messages.CONFIG_HARDWARE.parsed.content.revision_major }}.{{ node.last_messages.CONFIG_HARDWARE.parsed.content.revision_minor }})</small>
                </td>
                <td>
                    {% include "mesh/fragment_firmware_cell.html" with firmware_desc=node.firmware_description %}
                </td>
                <td>
                    {% blocktrans trimmed with timesince=node.last_messages.any.datetime|timesince %}
                        {{ timesince }} ago
                    {% endblocktrans %}
                </td>
                <td>
                    {% blocktrans trimmed with timesince=node.last_signin|timesince %}
                        {{ timesince }} ago
                    {% endblocktrans %}
                </td>
                <td>
                    {% with uplink=node.get_uplink %}
                        {% if uplink %}
                            {% mesh_node uplink.node %}<br>
                            {% if uplink.node == node %}
                                {% trans '(is an uplink)' %}
                            {% elif node.upstream %}
                                {% trans 'via:' %} {% mesh_node node.upstream %}
                            {% else %}
                                {% trans '(direct)' %}
                            {% endif %}
                        {% else %}
                            <em>offline</em>
                        {% endif %}
                    {% endwith %}
                </td>
            </tr>
        {% endfor %}
    </table>
{% endblock %}
