{% extends '_base.html' %}
{% load static from staticfiles %}
{% load helpers %}

{% block content %}
<div class="row">
    <div class="col-sm-8 col-md-9">
        <ol class="breadcrumb">
            {% if site.region %}
                {% for region in site.region.get_ancestors %}
                    <li><a href="{{ region.get_absolute_url }}">{{ region }}</a></li>
                {% endfor %}
                <li><a href="{{ site.region.get_absolute_url }}">{{ site.region }}</a></li>
            {% endif %}
            <li>{{ site }}</li>
        </ol>
    </div>
    <div class="col-sm-4 col-md-3">
        <form action="{% url 'dcim:site_list' %}" method="get">
            <div class="input-group">
                <input type="text" name="q" class="form-control" placeholder="Search sites" />
                <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 show_graphs %}
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#graphs_modal" data-obj="{{ site.name }}" data-url="{% url 'dcim-api:site-graphs' pk=site.pk %}" title="Show graphs">
            <i class="fa fa-signal" aria-hidden="true"></i>
            Graphs
        </button>
    {% endif %}
    {% if perms.dcim.change_site %}
		<a href="{% url 'dcim:site_edit' slug=site.slug %}" class="btn btn-warning">
			<span class="fa fa-pencil" aria-hidden="true"></span>
			Edit this site
		</a>
    {% endif %}
    {% if perms.dcim.delete_site %}
		<a href="{% url 'dcim:site_delete' slug=site.slug %}" class="btn btn-danger">
			<span class="fa fa-trash" aria-hidden="true"></span>
			Delete this site
		</a>
    {% endif %}
</div>
<h1>{% block title %}{{ site }}{% endblock %}</h1>
{% include 'inc/created_updated.html' with obj=site %}
<div class="row">
	<div class="col-md-7">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Site</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Region</td>
                    <td>
                        {% if site.region %}
                            {% for region in site.region.get_ancestors %}
                                <a href="{{ region.get_absolute_url }}">{{ region }}</a>
                                <i class="fa fa-angle-right"></i>
                            {% endfor %}
                            <a href="{{ site.region.get_absolute_url }}">{{ site.region }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Tenant</td>
                    <td>
                        {% if site.tenant %}
                            {% if site.tenant.group %}
                                <a href="{{ site.tenant.group.get_absolute_url }}">{{ site.tenant.group.name }}</a>
                                <i class="fa fa-angle-right"></i>
                            {% endif %}
                            <a href="{{ site.tenant.get_absolute_url }}">{{ site.tenant }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Facility</td>
                    <td>
                        {% if site.facility %}
                            {{ site.facility }}
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>AS Number</td>
                    <td>
                        {% if site.asn %}
                            {{ site.asn }}
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Contact Info</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Physical Address</td>
                    <td>
                        {% if site.physical_address %}
                            <div class="pull-right">
                                <a href="http://maps.google.com/?q={{ site.physical_address|oneline }}" target="_blank" class="btn btn-primary btn-xs">
                                    <i class="glyphicon glyphicon-map-marker"></i> Map it
                                </a>
                            </div>
                            <span>{{ site.physical_address|linebreaksbr }}</span>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Shipping Address</td>
                    <td>
                        {% if site.shipping_address %}
                            <span>{{ site.shipping_address|linebreaksbr }}</span>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Contact Name</td>
                    <td>
                        {% if site.contact_name %}
                            <span>{{ site.contact_name }}</span>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Contact Phone</td>
                    <td>
                        {% if site.contact_phone %}
                            <a href="tel:{{ site.contact_phone }}">{{ site.contact_phone }}</a>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Contact E-Mail</td>
                    <td>
                        {% if site.contact_email %}
                            <a href="mailto:{{ site.contact_email }}">{{ site.contact_email }}</a>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>
        {% with site.get_custom_fields as custom_fields %}
            {% include 'inc/custom_fields_panel.html' %}
        {% endwith %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Comments</strong>
            </div>
            <div class="panel-body">
                {% if site.comments %}
                    {{ site.comments|gfm }}
                {% else %}
                    <span class="text-muted">None</span>
                {% endif %}
            </div>
        </div>
    </div>
    <div class="col-md-5">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Stats</strong>
            </div>
            <div class="row panel-body">
                <div class="col-md-4 text-center">
                    <h2><a href="{% url 'dcim:rack_list' %}?site={{ site.slug }}" class="btn {% if stats.rack_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.rack_count }}</a></h2>
                    <p>Racks</p>
                </div>
                <div class="col-md-4 text-center">
                    <h2><a href="{% url 'dcim:device_list' %}?site={{ site.slug }}" class="btn {% if stats.device_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.device_count }}</a></h2>
                    <p>Devices</p>
                </div>
                <div class="col-md-4 text-center">
                    <h2><a href="{% url 'ipam:prefix_list' %}?site={{ site.slug }}" class="btn {% if stats.prefix_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.prefix_count }}</a></h2>
                    <p>Prefixes</p>
                </div>
                <div class="col-md-4 text-center">
                    <h2><a href="{% url 'ipam:vlan_list' %}?site={{ site.slug }}" class="btn {% if stats.vlan_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.vlan_count }}</a></h2>
                    <p>VLANs</p>
                </div>
                <div class="col-md-4 text-center">
                    <h2><a href="{% url 'circuits:circuit_list' %}?site={{ site.slug }}" class="btn {% if stats.circuit_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.circuit_count }}</a></h2>
                    <p>Circuits</p>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Rack Groups</strong>
            </div>
            {% if rack_groups %}
                <table class="table table-hover panel-body">
                    {% for rg in rack_groups %}
                        <tr>
                            <td><i class="fa fa-fw fa-folder-o"></i> <a href="{{ rg.get_absolute_url }}">{{ rg.name }}</a></td>
                            <td>{{ rg.rack_count }}</td>
                        </tr>
                    {% endfor %}
                </table>
            {% else %}
                <div class="panel-body text-muted">
                    None
                </div>
            {% endif %}
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Images</strong>
            </div>
            {% include 'inc/image_attachments.html' with images=site.images.all %}
            {% if perms.extras.add_imageattachment %}
                <div class="panel-footer text-right">
                    <a href="{% url 'dcim:site_add_image' object_id=site.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>Topology Maps</strong>
            </div>
            {% if topology_maps %}
                <table class="table table-hover panel-body">
                    {% for tm in topology_maps %}
                        <tr>
                            <td><i class="fa fa-fw fa-map-o"></i> <a href="{% url 'extras-api:topologymap-render' pk=tm.pk %}" target="_blank">{{ tm }}</a></td>
                            <td>{{ tm.description }}</td>
                        </tr>
                    {% endfor %}
                </table>
            {% else %}
                <div class="panel-body text-muted">
                    None
                </div>
            {% endif %}
        </div>
	</div>
</div>
{% include 'inc/graphs_modal.html' %}
{% endblock %}

{% block javascript %}
<script src="{% static 'js/graphs.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}
