{% extends 'base.html' %}
{% load buttons %}
{% load custom_links %}
{% load helpers %}
{% load plugins %}
{% load static %}
{% load tz %}

{% block header %}
    <div class="row noprint">
        <div class="col-sm-8 col-md-9">
            <ol class="breadcrumb">
                <li><a href="{% url 'dcim:site_list' %}">Sites</a></li>
                {% 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 noprint">
        {% plugin_buttons site %}
        {% 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.add_site %}
            {% clone_button site %}
        {% endif %}
        {% if perms.dcim.change_site %}
            {% edit_button site %}
        {% endif %}
        {% if perms.dcim.delete_site %}
            {% delete_button site %}
        {% endif %}
    </div>
    <h1>{% block title %}{{ site }}{% endblock %}</h1>
    {% include 'inc/created_updated.html' with obj=site %}
    <div class="pull-right noprint">
        {% custom_links site %}
    </div>
    <ul class="nav nav-tabs">
        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
            <a href="{{ site.get_absolute_url }}">Site</a>
        </li>
        {% if perms.extras.view_objectchange %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{% url 'dcim:site_changelog' slug=site.slug %}">Change Log</a>
            </li>
        {% endif %}
    </ul>
{% endblock %}

{% block content %}
<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>Status</td>
                    <td>
                        <span class="label label-{{ site.get_status_class }}">{{ site.get_status_display }}</span>
                    </td>
                </tr>
                <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 }}</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>{{ site.facility|placeholder }}</td>
                </tr>
                <tr>
                    <td>AS Number</td>
                    <td>{{ site.asn|placeholder }}</td>
                </tr>
                <tr>
                    <td>Time Zone</td>
                    <td>
                        {% if site.time_zone %}
                            {{ site.time_zone }} (UTC {{ site.time_zone|tzoffset }})<br />
                            <small class="text-muted">Site time: {% timezone site.time_zone %}{% now "SHORT_DATETIME_FORMAT" %}{% endtimezone %}</small>
                        {% else %}
                            <span class="text-muted">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Description</td>
                    <td>{{ site.description|placeholder }}</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 noprint">
                                <a href="http://maps.google.com/?q={{ site.physical_address|urlencode }}" 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">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Shipping Address</td>
                    <td>{{ site.shipping_address|linebreaksbr|placeholder }}</td>
                </tr>
                <tr>
                    <td>GPS Coordinates</td>
                    <td>
                        {% if site.latitude and site.longitude %}
                            <div class="pull-right noprint">
                                <a href="http://maps.google.com/?q={{ site.latitude }},{{ site.longitude }}" target="_blank" class="btn btn-primary btn-xs">
                                    <i class="glyphicon glyphicon-map-marker"></i> Map it
                                </a>
                            </div>
                            <span>{{ site.latitude }}, {{ site.longitude }}</span>
                        {% else %}
                            <span class="text-muted">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Contact Name</td>
                    <td>{{ site.contact_name|placeholder }}</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">&mdash;</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">&mdash;</span>
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>
        {% include 'inc/custom_fields_panel.html' with obj=site %}
        {% include 'extras/inc/tags_panel.html' with tags=site.tags.all url='dcim:site_list' %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Comments</strong>
            </div>
            <div class="panel-body rendered-markdown">
                {% if site.comments %}
                    {{ site.comments|render_markdown }}
                {% else %}
                    <span class="text-muted">None</span>
                {% endif %}
            </div>
        </div>
        {% plugin_left_page site %}
    </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 class="col-md-4 text-center">
                    <h2><a href="{% url 'virtualization:virtualmachine_list' %}?site={{ site.slug }}" class="btn {% if stats.vm_count %}btn-primary{% else %}btn-default{% endif %} btn-lg">{{ stats.vm_count }}</a></h2>
                    <p>Virtual Machines</p>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Rack Groups</strong>
            </div>
            <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 }}</a></td>
                        <td>{{ rg.rack_count }}</td>
                        <td class="text-right noprint">
                            <a href="{% url 'dcim:rack_elevation_list' %}?group_id={{ rg.pk }}" class="btn btn-xs btn-primary" title="View elevations">
                                <i class="fa fa-eye"></i>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                <tr>
                    <td><i class="fa fa-fw fa-folder-o"></i> All racks</td>
                    <td>{{ stats.rack_count }}</td>
                    <td class="text-right noprint">
                        <a href="{% url 'dcim:rack_elevation_list' %}?site={{ site.slug }}" class="btn btn-xs btn-primary" title="View elevations">
                            <i class="fa fa-eye"></i>
                        </a>
                    </td>
                </tr>
            </table>
        </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 noprint">
                    <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>
        {% plugin_right_page site %}
	</div>
</div>
{% include 'inc/modal.html' with name='graphs' title='Graphs' %}
<div class="row">
    <div class="col-md-12">
        {% plugin_full_width_page site %}
    </div>
</div>
{% endblock %}

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