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

{% block header %}
    <div class="row noprint" xmlns="http://www.w3.org/1999/html">
        <div class="col-sm-8 col-md-9">
            <ol class="breadcrumb">
                <li><a href="{{ cluster.type.get_absolute_url }}">{{ cluster.type }}</a></li>
                {% if cluster.group %}
                    <li><a href="{{ cluster.group.get_absolute_url }}">{{ cluster.group }}</a></li>
                {% endif %}
                <li>{{ cluster }}</li>
            </ol>
        </div>
        <div class="col-sm-4 col-md-3">
            <form action="{% url 'virtualization:cluster_list' %}" method="get">
                <div class="input-group">
                    <input type="text" name="q" class="form-control" placeholder="Search clusters" />
                    <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 cluster %}
        {% if perms.virtualization.add_cluster %}
            {% clone_button cluster %}
        {% endif %}
        {% if perms.virtualization.change_cluster %}
            {% edit_button cluster %}
        {% endif %}
        {% if perms.virtualization.delete_cluster %}
            {% delete_button cluster %}
        {% endif %}
    </div>
    <h1>{% block title %}{{ cluster }}{% endblock %}</h1>
    {% include 'inc/created_updated.html' with obj=cluster %}
    <div class="pull-right noprint">
        {% custom_links cluster %}
    </div>
    <ul class="nav nav-tabs">
        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
            <a href="{{ cluster.get_absolute_url }}">Cluster</a>
        </li>
        {% if perms.extras.view_objectchange %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{% url 'virtualization:cluster_changelog' pk=cluster.pk %}">Change Log</a>
            </li>
        {% endif %}
    </ul>
{% endblock %}

{% block content %}
<div class="row">
	<div class="col-md-5">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Cluster</strong>
            </div>
            <table class="table table-hover panel-body attr-table">
                <tr>
                    <td>Name</td>
                    <td>{{ cluster.name }}</td>
                </tr>
                <tr>
                    <td>Type</td>
                    <td><a href="{{ cluster.type.get_absolute_url }}">{{ cluster.type }}</a></td>
                </tr>
                <tr>
                    <td>Group</td>
                    <td>
                        {% if cluster.group %}
                            <a href="{{ cluster.group.get_absolute_url }}">{{ cluster.group }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Tenant</td>
                    <td>
                        {% if cluster.tenant %}
                            <a href="{{ cluster.tenant.get_absolute_url }}">{{ cluster.tenant }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Site</td>
                    <td>
                        {% if cluster.site %}
                            <a href="{{ cluster.site.get_absolute_url }}">{{ cluster.site }}</a>
                        {% else %}
                            <span class="text-muted">None</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <td>Virtual Machines</td>
                    <td><a href="{% url 'virtualization:virtualmachine_list' %}?cluster_id={{ cluster.pk }}">{{ cluster.virtual_machines.count }}</a></td>
                </tr>
            </table>
        </div>
        {% include 'inc/custom_fields_panel.html' with obj=cluster %}
        {% include 'extras/inc/tags_panel.html' with tags=cluster.tags.all url='virtualization:cluster_list' %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Comments</strong>
            </div>
            <div class="panel-body rendered-markdown">
                {% if cluster.comments %}
                    {{ cluster.comments|render_markdown }}
                {% else %}
                    <span class="text-muted">None</span>
                {% endif %}
            </div>
        </div>
        {% plugin_left_page cluster %}
    </div>
    <div class="col-md-7">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Host Devices</strong>
            </div>
            {% if perms.virtualization.change_cluster %}
                <form action="{% url 'virtualization:cluster_remove_devices' pk=cluster.pk %}" method="post">
                {% csrf_token %}
            {% endif %}
            {% include 'responsive_table.html' with table=device_table %}
            {% if perms.virtualization.change_cluster %}
                <div class="panel-footer noprint">
                    <div class="pull-right">
                        <a href="{% url 'virtualization:cluster_add_devices' pk=cluster.pk %}?site={{ cluster.site.pk }}" class="btn btn-primary btn-xs">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                            Add devices
                        </a>
                    </div>
                    <button type="submit" name="_remove" class="btn btn-danger primary btn-xs">
                        <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                        Remove devices
                    </button>
                </div>
                </form>
            {% endif %}
        </div>
        {% plugin_right_page cluster %}
	</div>
</div>
<div class="row">
    <div class="col-md-12">
        {% plugin_full_width_page cluster %}
    </div>
</div>
{% endblock %}
