{% extends "base_status.html" %}

{% load i18n %}

{% block title %}{% trans "Hostgroup" %} {{ hostgroup_name }}{% endblock %}
{% block nav2 %}<a href="{% url 'status.views.status_hostgroups' %}">{% trans "Hostgroups" %}</a> / {{ hostgroup_name }}{% endblock %}
{% block smallheader %}{% trans "hostgroup" %}{% endblock %}
{% block largeheader %}{{ hostgroup_name }}{% endblock %}

{% block content %}
    <ul class="nav nav-tabs" id="objecttab">
        <li class="active"><a href="#information" data-toggle="tab">{% trans "Information" %}</a></li>
        <li><a href="#child_hostgroups" data-toggle="tab" id="hostgroups_link">{% trans "Child Hostgroups" %} {% if hostgroups %}<span class="muted">({{ hostgroups|length }})</span>{% endif %}</a></li>
        <li><a href="#hosts" data-toggle="tab" id="hosts_link">{% trans "Hosts" %} {% if hosts %}<span class="muted">({{ hosts|length }})</span>{% endif %}</a></li>
        <li><a href="#services" data-toggle="tab" id="services_link">{% trans "Services" %} {% if services %}<span class="muted">({{ services|length }})</span>{% endif %}</a></li>
        <li><a href="#history" data-toggle="tab" id="history_link">{% trans "History" %}</a></li>
        <li><a href="#debug" data-toggle="tab">{% trans "Debug" %}</a></li>

    </ul>
    <div class="tab-content">

        <div class="tab-pane active" id="information">
            {% if my_hostgroup %}
                <table class="table">
                    <tr>
                        <td>{% trans "Hostgroup Name" %}</td>
                        <td>{{ my_hostgroup.name }}</td>
                    </tr>
                    <tr>
                        <td>{% trans "Alias" %}</td>
                        <td>{{ my_hostgroup.alias }}</td>
                    </tr>
                    <tr>
                        <td>{% trans "External links" %}</td>
                        <td>
                            {% if my_hostgroup.action_url %}
                                <a href="{{ my_hostgroup.action_url }}">action url</a>
                            {% endif %}

                            {% if my_hostgroup.notes_url %}
                                <a href="{{ my_hostgroup.notes_url }}">notes_url</a>
                            {% endif %}

                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="id_notes">{% trans "Notes" %}</label>
                        </td>
                        <td><textarea id="id_notes" cols="100" rows=3 name="notes">{{ my_object.notes }}</textarea></td>
                    </tr>
                    <tr>
                        <td>{% trans "Parent Hostgroups" %}</td>
                        <td>
                            {% for i in my_hostgroup.parent_hostgroups %}
                                <a href="{% url 'status.views.detail' %}?hostgroup_name={{  i  }}">{{ i }}</a>,
                            {% endfor %}
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table class="table well table-condensed">
                                <thead>
                                <tr><td colspan=2>{% trans "Host Status" %}</td></tr>
                                </thead>
                                <tbody>
                                <tr>
                                    <td><div class="circle state_0"> </div> {% trans "Hosts up:" %} </td>
                                    <td>{{ my_hostgroup.num_hosts_up }}</td>
                                </tr>
                                <tr>
                                    <td><div class="circle state_2"> </div> {% trans "Hosts down:" %} </td>
                                    <td>{{ my_hostgroup.num_hosts_down }}</td>
                                </tr>
                                <tr>
                                    <td><div class="circle state_3"> </div> {% trans "Hosts unreachable:" %} </td>
                                    <td>{{ my_hostgroup.num_hosts_unreach }}</td>
                                </tr>
                                <tr><td colspan=2>...</td></tr>

                                <tr>
                                    <th>{% trans "Total:" %}</th>
                                    <th>{{ my_hostgroup.num_hosts }}</th>
                                </tr>
                                </tbody>
                            </table>
                        </td>
                        <td>
                            <table class="table well table-condensed">
                                <thead>
                                <tr><td colspan=2>{% trans "Service Status" %}</td></tr>
                                </thead>
                                <tbody>
                                <tr>
                                    <td><div class="circle state_0"> </div> OK: </td>
                                    <td>{{ my_hostgroup.num_services_ok }}</td>
                                </tr>
                                <tr>
                                    <td><div class="circle state_1"> </div> Warning: </td>
                                    <td>{{ my_hostgroup.num_services_warn }}</td>
                                </tr>
                                <tr>
                                    <td><div class="circle state_2"> </div> Critical: </td>
                                    <td>{{ my_hostgroup.num_services_crit }}</td>
                                </tr>
                                <tr>
                                    <td><div class="circle state_3"> </div> Unknown: </td>
                                    <td>{{ my_hostgroup.num_services_unknown }}</td>
                                </tr>
                                <tr>
                                    <th>{% trans "Total:" %}</th>
                                    <th>{{ my_hostgroup.num_services }}</th>
                                </tr>
                                </tbody>
                            </table>

                        </td>
                    </tr>
                </table>
            {% else %}
                {% blocktrans %}No Information found for hostgroup {{ hostgroup_name }}. Are you sure it exists ?{% endblocktrans %}
            {% endif %}

        </div>

        <div class="tab-pane " id="child_hostgroups">
            {% blocktrans %}hostgroups that belong to {{ hostgroup_name }}{% endblocktrans %}
            {% include "snippets/status_hostgrouplist_snippet.html" %}

        </div>

        <div class="tab-pane " id="hosts">
            {% blocktrans %}Hosts that belong to {{ hostgroup_name }}{% endblocktrans %}
            <div id="hostlist">{% trans "This dialog should start loading when you click the hosts tab" %}</div>
        </div>

        <div class="tab-pane " id="services">
            {% blocktrans %}Services that belong to {{ hostgroup_name }}{% endblocktrans %}
            <div id="servicelist">{% trans "This dialog should start loading when you click the services tab" %}</div>
        </div>

        <div class="tab-pane" id="history">
            <div id="logdiv">
                {% trans "This dialog should reload when the history tab is clicked." %}
            </div>
        </div>
        <div class="tab-pane" id="debug">
            <h4>Information available via livestatus:</h4>
            <table class="table-condensed table">
                {% for k,v in my_hostgroup.items %}
                    <tr>
                        <td>                {{ k }}
                        </td>
                        <td>
                            {{ v }}
                        </td>
                    </tr>
                {% endfor %}
            </table>
        </div>
    </div>

    <!-- has to be here for the action buttons to work -->
    <div  id="hostgroupstatus" class="hide">
        <table>
            <tbody>
            <tr>
                <td class="selectable">
                    <input class="chkbox chkbox-primary"  style="margin: -2px; padding: 0px;" type="checkbox" checked="checked" name="hostgroup" value="{{ hostgroup_name }}" data-hostgroup_name="{{ hostgroup_name }}" data-object_type="hostgroup">
                    <input type="hidden" class="input_hostname" name="host_name" value="{{ host_name }}">
                    <input type="hidden" class="input_service_description" name="service_description" value="{{ service_description }}">

                </td>
            </tr>
            </tbody>
        </table>
    </div>


{% endblock %}

{% block footer %}
    {{ block.super }}
    <style>
    .input-append button.add-on {
        height: inherit !important;
    }
        /* avoid bootstrap highlight */
    .table tbody tr:hover td, .table tbody tr:hover th {
        background-color: transparent;
    }
    </style>
    <script>
        // When history link is clicked, load the log history for this object
        $('#history_link').click(function(event) {
            // Load log history in its own tab
            $('#logdiv').html(gettext("Loading ..."));
            var hostgroup_name = encodeURIComponent("{{ hostgroup_name }}");
            var snippet_url = '{% url "adagios.status.views.snippets_log" %}?object_type=hostgroup&hostgroup_name=' + hostgroup_name;
            $('#logdiv').load(snippet_url);
        });

        $('#services_link').click(function(event) {
            // Load log history in its own tab
            $('#servicelist').html(gettext("Loading ..."));
            var hostgroup_name = encodeURIComponent("{{ hostgroup_name }}");
            var snippet_url = '{% url 'adagios.status.views.snippets_services' %}?host_groups__has_field=' + hostgroup_name;
            $('#servicelist').load(snippet_url, function() {
                adagios.status.initilize_multiselect_checkboxes();
            });
        });

        $('#hosts_link').click(function(event) {
            // Load log history in its own tab
            $('#hostlist').html(gettext("Loading ..."));
            var hostgroup_name = encodeURIComponent("{{ hostgroup_name }}");
            var snippet_url = '{% url 'adagios.status.views.snippets_hosts' %}?host_groups__has_field=' + hostgroup_name;
            $('#hostlist').load(snippet_url, function() {
                adagios.status.initilize_multiselect_checkboxes();
            });
        });

    </script>

{% endblock %}
