{% extends '_base.html' %}
{% load helpers %}

{% block content %}
<div class="row">
    <div class="col-sm-8 col-md-9">
        <ol class="breadcrumb">
            <li><a href="{% url 'dcim:rack_list' %}">Racks</a></li>
            <li><a href="{% url 'dcim:rack_list' %}?site={{ rack.site.slug }}">{{ rack.site }}</a></li>
            <li>{{ rack }}</li>
        </ol>
    </div>
    <div class="col-sm-4 col-md-3">
        <form action="{% url 'dcim:rack_list' %}" method="get">
            <div class="input-group">
                <input type="text" name="q" class="form-control" placeholder="Search racks" />
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                        <span class="fa fa-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="fa fa-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="fa fa-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="fa fa-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="fa fa-trash" aria-hidden="true"></span>
			Delete this rack
		</a>
    {% endif %}
</div>
<h1>{% block title %}Rack {{ rack.name }}{% endblock %}</h1>
{% include 'inc/created_updated.html' with obj=rack %}
<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 attr-table">
                <tr>
                    <td>Site</td>
                    <td>
                        {% if rack.site.region %}
                            <a href="{{ rack.site.region.get_absolute_url }}">{{ rack.site.region }}</a>
                            <i class="fa fa-angle-right"></i>
                        {% endif %}
                        <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">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Tenant</td>
                    <td>
                        {% if rack.tenant %}
                            {% if rack.tenant.group %}
                                <a href="{{ rack.tenant.group.get_absolute_url }}">{{ rack.tenant.group.name }}</a>
                                <i class="fa fa-angle-right"></i>
                            {% endif %}
                            <a href="{{ rack.tenant.get_absolute_url }}">{{ rack.tenant }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Role</td>
                    <td>
                        {% if rack.role %}
                            <a href="{{ rack.role.get_absolute_url }}">{{ rack.role }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Serial Number</td>
                    <td>
                        {% if rack.serial %}
                            <span>{{ rack.serial }}</span>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Devices</td>
                    <td>
                        <a href="{% url 'dcim:device_list' %}?rack_id={{ rack.id }}">{{ rack.devices.count }}</a>
                    </td>
                </tr>
            </table>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Dimensions</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Type</td>
                    <td>
                        {% if rack.type %}
                            {{ rack.get_type_display }}
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Width</td>
                    <td>{{ rack.get_width_display }}</td>
                </tr>
                <tr>
                    <td>Height</td>
                    <td>{{ rack.u_height }}U ({% if rack.desc_units %}descending{% else %}ascending{% endif %})</td>
                </tr>
            </table>
        </div>
        {% with rack.get_custom_fields as custom_fields %}
            {% include 'inc/custom_fields_panel.html' %}
        {% endwith %}
        <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">
                    <tr>
                        <th>Name</th>
                        <th>Role</th>
                        <th>Type</th>
                        <th>Parent</th>
                    </tr>
                    {% 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.full_name }}</td>
                            <td>
                                {% if device.parent_bay %}
                                    <a href="{{ device.parent_bay.device.get_absolute_url }}">{{ device.parent_bay }}</a>
                                {% else %}
                                    <span class="text-muted">N/A</span>
                                {% endif %}
                            </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 class="panel panel-default">
            <div class="panel-heading">
                <strong>Images</strong>
            </div>
            {% include 'inc/image_attachments.html' with images=rack.images.all %}
            {% if perms.extras.add_imageattachment %}
                <div class="panel-footer text-right">
                    <a href="{% url 'dcim:rack_add_image' object_id=rack.pk %}" class="btn btn-primary btn-xs">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                        Attach an image
                    </a>
                </div>
            {% endif %}
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Reservations</strong>
            </div>
            {% if reservations %}
                <table class="table table-hover panel-body">
                    <tr>
                        <th>Units</th>
                        <th>Description</th>
                        <th></th>
                    </tr>
                    {% for resv in reservations %}
                        <tr>
                            <td>{{ resv.unit_list }}</td>
                            <td>
                                {{ resv.description }}<br />
                                <small>{{ resv.user }} &middot; {{ resv.created }}</small>
                            </td>
                            <td class="text-right">
                                {% if perms.dcim.change_rackreservation %}
                                    <a href="{% url 'dcim:rackreservation_edit' pk=resv.pk %}" class="btn btn-warning btn-xs" title="Edit reservation">
                                        <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
                                    </a>
                                {% endif %}
                                {% if perms.dcim.delete_rackreservation %}
                                    <a href="{% url 'dcim:rackreservation_delete' pk=resv.pk %}" class="btn btn-danger btn-xs" title="Delete reservation">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                    </a>
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            {% else %}
                <div class="panel-body text-muted">None</div>
            {% endif %}
            {% if perms.dcim.add_rackreservation %}
                <div class="panel-footer text-right">
                    <a href="{% url 'dcim:rack_add_reservation' rack=rack.pk %}" class="btn btn-primary btn-xs">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                        Add a reservation
                    </a>
                </div>
            {% endif %}
        </div>
	</div>
    <div class="row col-md-6">
       <div class="col-md-6 col-sm-6 col-xs-12">
          <div class="rack_header">
            <h4>Front</h4>
          </div>
          {% include 'dcim/inc/rack_elevation.html' with primary_face=front_elevation secondary_face=rear_elevation face_id=0 reserved_units=rack.get_reserved_units %}
      </div>
      <div class="col-md-6 col-sm-6 col-xs-12">
        <div class="rack_header">
            <h4>Rear</h4>
        </div>
        {% include 'dcim/inc/rack_elevation.html' with primary_face=rear_elevation secondary_face=front_elevation face_id=1 reserved_units=rack.get_reserved_units %}
      </div>
    </div>
</div>
{% endblock %}

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