{% extends '_base.html' %}
{% load helpers %}
{% load render_table from django_tables2 %}

{% block title %}{{ rack.site }} - Rack {{ rack.name }}{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-9">
        <ol class="breadcrumb">
            <li><a href="{% url 'dcim:site' slug=rack.site.slug %}">{{ rack.site }}</a></li>
            <li><a href="{% url 'dcim:rack_list' %}?site={{ rack.site.slug }}">Racks</a></li>
            <li>{{ rack }}</li>
        </ol>
    </div>
    <div class="col-md-3">
        <form action="{% url 'dcim:rack_list' %}" method="get">
            <div class="input-group">
                <input type="text" name="q" class="form-control" placeholder="Rack name or ID" />
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                        <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                    </button>
                </span>
            </div>
        </form>
    </div>
</div>
<div class="pull-right">
    {% if prev_rack %}
        <a href="{% url 'dcim:rack' pk=prev_rack.pk %}" class="btn btn-primary">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            Previous Rack
        </a>
    {% endif %}
    {% if next_rack %}
        <a href="{% url 'dcim:rack' pk=next_rack.pk %}" class="btn btn-primary">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            Next Rack
        </a>
    {% endif %}
    {% if perms.dcim.change_rack %}
		<a href="{% url 'dcim:rack_edit' pk=rack.pk %}" class="btn btn-warning">
			<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
			Edit this rack
		</a>
    {% endif %}
    {% if perms.dcim.delete_rack %}
		<a href="{% url 'dcim:rack_delete' pk=rack.pk %}" class="btn btn-danger">
			<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
			Delete this rack
		</a>
    {% endif %}
</div>
<h1>Rack {{ rack.name }}</h1>
<div class="row">
	<div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Rack</strong>
            </div>
            <table class="table table-hover panel-body">
                <tr>
                    <td>Site</td>
                    <td>
                        <a href="{% url 'dcim:site' slug=rack.site.slug %}">{{ rack.site }}</a>
                    </td>
                </tr>
                <tr>
                    <td>Group</td>
                    <td>
                        {% if rack.group %}
                            <a href="{% url 'dcim:rack_list' %}?site={{ rack.site.slug }}&group={{ rack.group.slug }}">{{ rack.group.name }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Facility ID</td>
                    <td>
                        {% if rack.facility_id %}
                            <span>{{ rack.facility_id }}</span>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Height</td>
                    <td>{{ rack.u_height }}U</td>
                </tr>
                <tr>
                    <td>Devices</td>
                    <td>
                        <a href="{% url 'dcim:device_list' %}?rack_id={{ rack.id }}">{{ rack.devices.count }}</a>
                    </td>
                </tr>
                <tr>
                    <td>Created</td>
                    <td>{{ rack.created }}</td>
                </tr>
                <tr>
                    <td>Last Updated</td>
                    <td>{{ rack.last_updated }}</td>
                </tr>
            </table>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Non-Racked Devices</strong>
            </div>
            {% if nonracked_devices %}
                <table class="table table-hover panel-body">
                    {% for device in nonracked_devices %}
                        <tr{% if device.device_type.u_height %} class="warning"{% endif %}>
                            <td>
                                <a href="{% url 'dcim:device' pk=device.pk %}">{{ device.name }}</a>
                            </td>
                            <td>{{ device.device_role }}</td>
                            <td>{{ device.device_type }}</td>
                        </tr>
                    {% endfor %}
                </table>
            {% else %}
                <div class="panel-body text-muted">None</div>
            {% endif %}
            {% if perms.dcim.add_device %}
                <div class="panel-footer text-right">
                    <a href="{% url 'dcim:device_add' %}?site={{ rack.site.pk }}&rack={{ rack.pk }}" class="btn btn-primary btn-xs">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                        Add a non-racked device
                    </a>
                </div>
            {% endif %}
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Comments</strong>
            </div>
            <div class="panel-body">
                {% if rack.comments  %}
                    {{ rack.comments|gfm }}
                {% else %}
                    <span class="text-muted">None</span>
                {% endif %}
            </div>
        </div>
	</div>
    <div class="col-md-3">
        <div class="rack_header">
            <h4>Front</h4>
        </div>
        {% include 'dcim/_rack_elevation.html' with primary_face=front_elevation secondary_face=rear_elevation face_id=0 %}
    </div>
    <div class="col-md-3">
        <div class="rack_header">
            <h4>Rear</h4>
        </div>
        {% include 'dcim/_rack_elevation.html' with primary_face=rear_elevation secondary_face=front_elevation face_id=1 %}
    </div>
</div>
{% endblock %}

{% block javascript %}
<script type="text/javascript">
$(function() {
  $('[data-toggle="popover"]').popover()
})
</script>
{% endblock %}
