{% extends 'detail.html.j2' %}

{% load json %}
{% load markdown %}


{% block tabs %}

<div id="details" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.details %}

    <hr />

    <div style="display: block; width: 100%;">

        <h3>Nodes</h3>

        <table>
            <tr>
                <th>Name</th>
                <th>Organization</th>
            </tr>
            {% if cluster.nodes.all %}
            {% for node in cluster.nodes.all %}
            <tr>
                <td><a href="{% url 'ITAM:_device_view' node.pk %}">{{ node }}</a></td>
                <td>{{ node.organization }}</td>
            </tr>
            {% endfor%}
            {% else %}
            <tr>
            <td colspan="2"> Nothing Found</td>
            </tr>
            {% endif %}
        </table>

    </div>

    <div style="display: block; width: 100%;">

        <h3>Devices</h3>

        <table>
            <tr>
                <th>Name</th>
                <th>Organization</th>
            </tr>
            {% if cluster.devices.all %}
            {% for device in cluster.devices.all %}
            <tr>
                <td><a href="{% url 'ITAM:_device_view' device.pk %}">{{ device }}</a></td>
                <td>{{ device.organization }}</td>
            </tr>
            {% endfor%}
            {% else %}
            <tr>
            <td colspan="2"> Nothing Found</td>
            </tr>
            {% endif %}
        </table>

    </div>

    <div style="display: block; width: 100%;">

        <h3>Services</h3>

        <table>
            <tr>
                <th>Name</th>
                <th>Ports</th>
            </tr>
            {% if services %}
            {% for service in services.all %}
            <tr>
                <td><a href="{% url 'ITIM:_service_view' service.id %}">{{ service.name }}</a></td>
                <td>
                    {% for port in service.port.all %}
                    {{ port.protocol }}/{{ port.number }} - {{ port.description }},
                    {% endfor %}
                </td>
            </tr>
            {% endfor%}
            {% else %}
            <tr>
            <td colspan="2"> Nothing Found</td>
            </tr>
            {% endif %}
        </table>

    </div>

    <div style="display: block; width: 100%;">
        <h3>Config</h3>
        <pre>{{ cluster.config | json_pretty }}</pre>
    </div>

</div>


<div id="rendered_config" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.rendered_config %}

</div>

<div id="tickets" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.tickets %}

    <table>
        <thead>
          <th>Name</th>
          <th>Status</th>
          <th>&nbsp</th>
        </thead>
        {% if tickets %}
        {% for ticket in tickets %}
        <tr>
          <td>{% concat_strings "#" ticket.ticket.id as ticket_ref %}{{ ticket_ref | markdown | safe}}</td>
          <td>{% include 'core/ticket/badge_ticket_status.html.j2' with ticket_status_text=ticket.ticket.get_status_display ticket_status=ticket.ticket.get_status_display|ticket_status %}</td>
          <td>&nbsp;</td>
        </tr>
        {% endfor %}
        {% else %}
        <tr>
            <td colspan="3">No related tickets exist</td>
        </tr>
        {% endif %}
    </table>

</div>

{% endblock %}