{% extends 'dcim/device/base.html' %}
{% load helpers %}
{% load plugins %}
{% load render_table from django_tables2 %}

{% block content %}
<div class="tab-content">
  <div id="main" role="tabpanel" class="tab-pane {% if active_tab == 'device' and not request.GET.tab or request.GET.tab == 'main' %}active{% else %}fade{% endif %}">
    <div class="row">
        <div class="col-md-12">
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="details">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <strong>Device</strong>
                                </div>
                                <table class="table table-hover panel-body attr-table">
                                    <tr>
                                        <td>Location</td>
                                        <td>
                                            {% include 'dcim/inc/location_hierarchy.html' with location=object.location %}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Rack</td>
                                        <td>
                                            {% if object.rack and object.rack.rack_group %}
                                                {{ object.rack.rack_group|hyperlinked_object }} /
                                            {% endif %}
                                            {{ object.rack|hyperlinked_object }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Position</td>
                                        <td>
                                            {% if object.parent_bay %}
                                                {% with object.parent_bay.device as parent %}
                                                    {{ parent|hyperlinked_object }} / {{ object.parent_bay }}
                                                    {% if parent.position %}
                                                        (U{{ parent.position }} / {{ parent.get_face_display }})
                                                    {% endif %}
                                                {% endwith %}
                                            {% elif object.rack and object.position %}
                                                <span>U{{ object.position }} / {{ object.get_face_display }}</span>
                                            {% elif object.rack and object.device_type.u_height %}
                                                <span class="label label-warning">Not racked</span>
                                            {% else %}
                                                <span class="text-muted">&mdash;</span>
                                            {% endif %}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Tenant</td>
                                        <td>
                                            {% if object.tenant and object.tenant.tenant_group %}
                                                {{ object.tenant.tenant_group|hyperlinked_object }} /
                                            {% endif %}
                                            {{ object.tenant|hyperlinked_object }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Device Type</td>
                                        <td>
                                            <span><a href="{% url 'dcim:devicetype' pk=object.device_type.pk %}">{{ object.device_type.display }}</a> ({{ object.device_type.u_height }}U)</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Serial Number</td>
                                        <td>
                                            <span class="hover_copy">
                                                <span id="serial_number">{{ object.serial|placeholder }}</span>
                                                {% if object.serial %}
                                                    <button class="btn btn-inline btn-default hover_copy_button" data-clipboard-target="#serial_number">
                                                        <span class="mdi mdi-content-copy"></span>
                                                    </button>
                                                {% endif %}
                                            </span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Asset Tag</td>
                                        <td><span>{{ object.asset_tag|placeholder }}</span></td>
                                    </tr>
                                </table>
                            </div>
                            {% if vc_members %}
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <strong>Virtual Chassis</strong>
                                    </div>
                                    <table class="table table-hover panel-body attr-table">
                                        <tr>
                                            <th>Device</th>
                                            <th>Position</th>
                                            <th>Master</th>
                                            <th>Priority</th>
                                        </tr>
                                        {% for vc_member in vc_members %}
                                            <tr{% if vc_member == object %} class="info"{% endif %}>
                                                <td>{{ vc_member|hyperlinked_object }}</td>
                                                <td><span class="badge badge-default">{{ vc_member.vc_position }}</span></td>
                                                <td>{% if object.virtual_chassis.master == vc_member %}<i class="mdi mdi-check-bold"></i>{% endif %}</td>
                                                <td>{{ vc_member.vc_priority|default:"" }}</td>
                                            </tr>
                                        {% endfor %}
                                    </table>
                                    <div class="panel-footer text-right noprint">
                                        <a href="{{ object.virtual_chassis.get_absolute_url }}" class="btn btn-primary btn-xs">
                                            <span class="mdi mdi-arrow-right-bold" aria-hidden="true"></span> View Virtual Chassis
                                        </a>
                                    </div>
                                </div>
                            {% endif %}
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <strong>Management</strong>
                                </div>
                                <table class="table table-hover panel-body attr-table">
                                    <tr>
                                        <td>Role</td>
                                        <td>
                                            {{ object.role | hyperlinked_object_with_color }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Platform</td>
                                        <td>{{ object.platform|hyperlinked_object }}</td>
                                    </tr>
                                    <tr>
                                        <td>Status</td>
                                        <td>
                                            {{ object.status| hyperlinked_object_with_color }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Primary IPv4</td>
                                        <td>
                                            {% if object.primary_ip4 %}
                                                <span class="hover_copy">
                                                    {{ object.primary_ip4|hyperlinked_object|add_html_id:"ipv4" }} ({{ object.primary_ip4.parent.namespace|hyperlinked_object }})
                                                    {% if object.primary_ip4.nat_inside %}
                                                        <span>(NAT for {{ object.primary_ip4.nat_inside.address.ip }})</span>
                                                    {% elif object.primary_ip4.nat_outside_list.exists %}
                                                        <br /><span>NAT: </span>
                                                        <ul>
                                                            {% for nat in object.primary_ip4.nat_outside_list.all %}
                                                                <li>{{ nat|hyperlinked_object }}</li>
                                                            {% endfor %}
                                                        </ul>
                                                    {% endif %}
                                                    <button class="btn btn-inline btn-default hover_copy_button" data-clipboard-target="#ipv4">
                                                        <span class="mdi mdi-content-copy"></span>
                                                    </button>
                                                </span>
                                            {% else %}
                                                <span class="text-muted">&mdash;</span>
                                            {% endif %}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Primary IPv6</td>
                                        <td>
                                            {% if object.primary_ip6 %}
                                                <span class="hover_copy">
                                                    {{ object.primary_ip6|hyperlinked_object|add_html_id:"ipv6" }} ({{ object.primary_ip6.parent.namespace|hyperlinked_object }})
                                                    {% if object.primary_ip6.nat_inside %}
                                                        <span>(NAT for {{ object.primary_ip6.nat_inside.address.ip }})</span>
                                                    {% elif object.primary_ip6.nat_outside_list.exists %}
                                                        <br /><span>NAT: </span>
                                                        <ul>
                                                            {% for nat in object.primary_ip6.nat_outside_list.all %}
                                                                <li>{{ nat|hyperlinked_object }}</li>
                                                            {% endfor %}
                                                        </ul>
                                                    {% endif %}
                                                    <button class="btn btn-inline btn-default hover_copy_button" data-clipboard-target="#ipv6">
                                                        <span class="mdi mdi-content-copy"></span>
                                                    </button>
                                                </span>
                                            {% else %}
                                                <span class="text-muted">&mdash;</span>
                                            {% endif %}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Secrets Group</td>
                                        <td>
                                            {{ object.secrets_group|hyperlinked_object }}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Device Redundancy Group</td>
                                        <td>
                                            {% if object.device_redundancy_group %}
                                                {{ object.device_redundancy_group|hyperlinked_object }} <span class="badge badge-default">Priority: {{ object.device_redundancy_group_priority }}</span>
                                            {% else %}
                                                <span class="text-muted">&mdash;</span>
                                            {% endif %}
                                        </td>
                                    </tr>
                                    {% if object.cluster %}
                                        <tr>
                                            <td>Cluster</td>
                                            <td>
                                                {% if object.cluster.group %}
                                                    {{ object.cluster.group|hyperlinked_object }} /
                                                {% endif %}
                                                {{ object.cluster|hyperlinked_object }}
                                            </td>
                                        </tr>
                                    {% endif %}
                                </table>
                            </div>
                            {% include 'inc/custom_fields/panel.html' with custom_fields=object.get_custom_field_groupings_basic computed_fields_advanced_ui=False %}
                            {% include 'inc/relationships/panel_override.html' with relationships_fields_override=object.get_relationships_data_basic_fields %}
                            {% include 'extras/inc/tags_panel.html' with tags=object.tags.all url='dcim:device_list' %}
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <strong>Comments</strong>
                                </div>
                                <div class="panel-body rendered-markdown">
                                    {% if object.comments %}
                                        {{ object.comments|render_markdown }}
                                    {% else %}
                                        <span class="text-muted">None</span>
                                    {% endif %}
                                </div>
                            </div>
                            {% plugin_left_page object %}
                        </div>
                        <div class="col-md-6">
                            {% if object.powerports.exists and object.poweroutlets.exists %}
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <strong>Power Utilization</strong>
                                    </div>
                                    <table class="table table-hover panel-body">
                                        <tr>
                                            <th>Input</th>
                                            <th>Outlets</th>
                                            <th>Allocated</th>
                                            <th>Available</th>
                                            <th>Utilization</th>
                                        </tr>
                                        {% for powerport in object.powerports.all %}
                                            {% with utilization=powerport.get_power_draw powerfeed=powerport.connected_endpoint %}
                                                <tr>
                                                    <td>{{ powerport }}</td>
                                                    <td>{{ utilization.outlet_count }}</td>
                                                    <td>{{ utilization.allocated }}VA</td>
                                                    {% if powerfeed.available_power %}
                                                        <td>{{ powerfeed.available_power }}VA</td>
                                                        <td>{% utilization_graph_raw_data utilization.allocated powerfeed.available_power %}</td>
                                                    {% else %}
                                                        <td class="text-muted">&mdash;</td>
                                                        <td class="text-muted">&mdash;</td>
                                                    {% endif %}
                                                </tr>
                                                {% for leg in utilization.legs %}
                                                    <tr>
                                                        <td style="padding-left: 20px">Leg {{ leg.name }}</td>
                                                        <td>{{ leg.outlet_count }}</td>
                                                        <td>{{ leg.allocated }}</td>
                                                        <td>{{ powerfeed.available_power|divide:3 }}VA</td>
                                                        {% with phase_available=powerfeed.available_power|divide:3 %}
                                                            <td>{% utilization_graph_raw_data leg.allocated phase_available %}</td>
                                                        {% endwith %}
                                                    </tr>
                                                {% endfor %}
                                            {% endwith %}
                                        {% endfor %}
                                    </table>
                                </div>
                            {% endif %}
                            {% include 'panel_table.html' with table=vrf_table heading="Assigned VRFs" %}
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <strong>Services</strong>
                                </div>
                                {% if services %}
                                    <table class="table table-hover panel-body">
                                        {% for service in services %}
                                            {% include 'ipam/inc/service.html' %}
                                        {% endfor %}
                                    </table>
                                {% else %}
                                    <div class="panel-body text-muted">
                                        None
                                    </div>
                                {% endif %}
                                {% if perms.ipam.add_service %}
                                    <div class="panel-footer text-right noprint">
                                        <a href="{% url 'dcim:device_service_assign' device=object.pk %}" class="btn btn-xs btn-primary">
                                            <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Assign service
                                        </a>
                                    </div>
                                {% endif %}
                            </div>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <strong>Images</strong>
                                </div>
                                {% include 'inc/image_attachments.html' with images=object.images.all %}
                                {% if perms.extras.add_imageattachment %}
                                    <div class="panel-footer text-right noprint">
                                        <a href="{% url 'dcim:device_add_image' object_id=object.pk %}" class="btn btn-primary btn-xs">
                                            <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
                                            Attach an image
                                        </a>
                                    </div>
                                {% endif %}
                            </div>
                            {% plugin_right_page object %}
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            {% plugin_full_width_page object %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
  </div>
  <div id="advanced" role="tabpanel" class="tab-pane {% if active_tab == 'device' and request.GET.tab == 'advanced' %}active{% else %}fade{% endif %}">
    <div class="row">
        <div class="col-md-6">
            {% include 'inc/object_details_advanced_panel.html' %}
        </div>
        <div class="col-md-6">
            {% block advanced_content_right_page %}{% endblock advanced_content_right_page %}
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            {% block advanced_content_full_width_page %}{% endblock advanced_content_full_width_page %}
        </div>
    </div>
  </div>
</div>
{% endblock content %}
