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

{% block title %}{{ site }}{% endblock %}

{% block content %}
<div class="pull-right">
    <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="glyphicon glyphicon-signal" aria-hidden="true"></i>
        Graphs
    </button>
    {% if perms.dcim.change_site %}
		<a href="{% url 'dcim:site_edit' slug=site.slug %}" class="btn btn-warning">
			<span class="glyphicon glyphicon-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="glyphicon glyphicon-trash" aria-hidden="true"></span>
			Delete this site
		</a>
    {% endif %}
</div>
<h1>{{ site.name }}</h1>
<div class="row">
	<div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Site</strong>
            </div>
            <table class="table table-hover panel-body">
                <tr>
                    <td>Facility</td>
                    <td>{{ site.facility }}</td>
                </tr>
                <tr>
                    <td>AS Number</td>
                    <td>{{ site.asn }}</td>
                </tr>
                <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>
                        {% endif %}
                        <span>{{ site.physical_address|linebreaksbr }}</span>
                    </td>
                </tr>
                <tr>
                    <td>Shipping Address</td>
                    <td>
                        {% if site.shipping_address %}
                            <span>{{ site.shipping_address|linebreaksbr }}</span>
                        {% else %}
                            <span class="text-muted">See physical address</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Created</td>
                    <td>{{ site.created }}</td>
                </tr>
                <tr>
                    <td>Last Updated</td>
                    <td>{{ site.last_updated }}</td>
                </tr>
            </table>
        </div>
        <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-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Stats</strong>
            </div>
            <table class="table table-hover panel-body">
                <tr>
                    <td>Racks</td>
                    <td>
                        <a href="{% url 'dcim:rack_list' %}?site={{ site.slug }}">{{ stats.rack_count }}</a>
                    </td>
                </tr>
                <tr>
                    <td>Devices</td>
                    <td>
                        <a href="{% url 'dcim:device_list' %}?site={{ site.slug }}">{{ stats.device_count }}</a>
                    </td>
                </tr>
                <tr>
                    <td>Prefixes</td>
                    <td>
                        <a href="{% url 'ipam:prefix_list' %}?site={{ site.slug }}">{{ stats.prefix_count }}</a>
                    </td>
                </tr>
                <tr>
                    <td>VLANs</td>
                    <td>
                        <a href="{% url 'ipam:vlan_list' %}?site={{ site.slug }}">{{ stats.vlan_count }}</a>
                    </td>
                </tr>
                <tr>
                    <td>Circuits</td>
                    <td>
                        <a href="{% url 'circuits:circuit_list' %}?site={{ site.slug }}">{{ stats.circuit_count }}</a>
                    </td>
                </tr>
            </table>
        </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 text-success"></i> <a href="{% url 'dcim-api:topology_map' slug=tm.slug %}" 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' %}"></script>
{% endblock %}
