{% extends request.is_ajax|yesno:'nullcont.htm,devapp/ext.htm' %}
{% load i18n %}
{% block content %}

    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-default">
                {% with uptime=dev_manager.uptime %}
                <div class="panel-heading">
                    <div class="panel-title">{{ dev.get_devtype_display|default:_('Title of the type of switch') }}.
                        {% if uptime %}
                            {% trans 'Uptime' %} {{ uptime }}
                        {% endif %}
                    </div>
                </div>
                {% endwith %}
                <div class="panel-body">

                    {% for port in ports %}
                        {% if port.st %}
                            {% if port.sp == 10000000 %}
                                <div class="port kilo text-center">
                                    <b>10 mbps</b>
                                    <span>{{ port.uptime_str }}</span>
                            {% elif port.sp == 100000000 %}
                                <div class="port mega text-center">
                                    <b>100 mbps</b>
                                    <span>{{ port.uptime_str }}</span>
                            {% elif port.sp == 1000000000 %}
                                <div class="port giga text-center">
                                    <b>1 gbps</b>
                                    <span>{{ port.uptime_str }}</span>
                            {% elif port.sp == 10000000000 %}
                                <div class="port ten text-center">
                                    <b>10 gbps</b>
                                    <span>{{ port.uptime_str }}</span>
                            {% else %}
                                <div class="port text-center">
                            {% endif %}
                        {% else %}
                            <div class="port dis text-center">
                        {% endif %}

                            <a href="javascript:void(0);" class="port-img" title="{{ port.nm }}">
                                <b>{{ port.num }}</b>
                            </a>
                            {% if port.writable %}
                                {% if port.st %}
                                    <a href="{% url 'devapp:port_toggle' dev.group.pk|default:0 dev.id port.snmp_num 0 %}" class="btn btn-xs btn-danger" title="{% trans 'Disable port' %}">
                                        <span class="glyphicon glyphicon-off"></span>
                                    </a>
                                {% else %}
                                    <a href="{% url 'devapp:port_toggle' dev.group.pk|default:0 dev.id port.snmp_num 1 %}" class="btn btn-xs btn-success" title="{% trans 'Enable port' %}">
                                        <span class="glyphicon glyphicon-ok"></span>
                                    </a>
                                {% endif %}
                            {% else %}
                                <a href="#" class="btn btn-xs btn-danger disabled">
                                    <span class="glyphicon glyphicon-off"></span>
                                </a>
                            {% endif %}
                        </div>
                    {% empty %}
                        <h3>{% trans 'We have not received info, please check options :(' %}</h3>
                    {% endfor %}

                </div>
                <div class="panel-footer">
                    {% trans 'Parent device' %}
                    {% with pdev=dev.parent_dev %}
                        {% if pdev %}
                            {% if pdev.group %}
                                <a href="{% url 'devapp:view' pdev.group.pk pdev.pk %}" title="{{ pdev.ip_address|default:'-' }}" data-toggle="tooltip">{{ pdev.comment }}</a>
                            {% else %}
                                <a href="{% url 'devapp:fix_device_group' pdev.pk %}" title="{{ pdev.ip_address|default:'-' }}" data-toggle="tooltip">{{ pdev.comment }}</a>
                            {% endif %}
                        {% else %}
                            {% trans 'Not assigned' %}
                        {% endif %}
                    {% endwith %}
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">{% trans 'Ports management' %}</h3>
                </div>
                <table class="table table-responsive">
                    <thead>
                    <tr>
                        <th class="col-sm-1">{% trans 'Number' %}</th>
                        <th class="col-sm-5">{% trans 'Description' %}</th>
                        <th class="col-sm-5">{% trans 'Count of subscribers' %}</th>
                        <th class="col-sm-1">#</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% with gid=dev.group.pk did=dev.pk can_del_port=perms.devapp.delete_port can_edit_port=perms.devapp.change_port %}
                    {% for port in ports_db %}
                        <tr>
                            <td>{{ port.num }}</td>
                            <td>{{ port.descr|default:'-' }}</td>
                            {% if port.num_abons > 1 %}
                                {% url 'devapp:fix_port_conflict' gid did port.id as fixurl %}
                                <td class="text-danger"><b>{{ port.num_abons }}</b>. {% blocktrans with furl=fixurl %}Port should not have more than one subscriber, <a href='{{ furl }}'>fix that</a>{% endblocktrans %}</td>
                            {% else %}
                                <td>{{ port.num_abons }}</td>
                            {% endif %}
                            <td class="btn-group btn-group-sm btn-group-justified">
                                <a href="{% url 'devapp:show_subscriber_on_port' gid did port.id %}" class="btn btn-default btn-modal" title="{% trans 'Show subscriber on port' %}" data-toggle="tooltip">
                                    <span class="glyphicon glyphicon-eye-open"></span>
                                </a>
                                {% if can_del_port %}
                                    <a href="{% url 'devapp:del_port' gid did port.pk %}" class="btn btn-danger btn-modal" title="{% trans 'Delete' %}">
                                        <span class="glyphicon glyphicon-remove-circle"></span>
                                    </a>
                                {% endif %}
                                {% if can_edit_port %}
                                    <a href="{% url 'devapp:edit_port' gid did port.pk %}" class="btn btn-primary btn-modal" title="{% trans 'Edit' %}">
                                        <span class="glyphicon glyphicon-edit"></span>
                                    </a>
                                {% endif %}
                            </td>
                        </tr>
                    {% empty %}
                        <tr>
                            <td colspan="4">{% trans 'Ports not found' %}</td>
                        </tr>
                    {% endfor %}
                    {% endwith %}
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="4">
                            {% if perms.devapp.add_port %}
                                {% if ports %}
                                    <a href="{% url 'devapp:add_ports' dev.group.pk dev.pk %}" class="btn btn-sm btn-default" title="{% trans 'Add' %}">
                                        <span class="glyphicon glyphicon-plus"></span> {% trans 'Add ports' %}
                                    </a>
                                {% else %}
                                    <a href="{% url 'devapp:add_port' dev.group.pk dev.pk %}" class="btn btn-sm btn-default btn-modal">
                                        <span class="glyphicon glyphicon-plus"></span> {% trans 'Add ports' %}
                                    </a>
                                {% endif %}
                            {% endif %}
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">{% trans 'Ports comment' %}</h3>
                </div>
                <table class="table table-responsive">
                    <thead>
                    <tr>
                        <th width="50">{% trans 'Port' %}</th>
                        <th>{% trans 'Title' %}</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for port in ports %}
                        <tr>
                            <td>{{ port.num }}</td>
                            <td>{{ port.nm|default:'-' }}</td>
                        </tr>
                    {% empty %}
                        <tr>
                        <td colspan="2">{% trans 'We have not received info for ports' %}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

{% endblock %}
