<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
    <link rel="icon" href="{% static 'favicon.ico' %}" type="image/x-icon">
    <link href="https://yandex.st/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
    <link href="{% static 'css/links.css' %}" rel="stylesheet" />
    <title>{% if my %}My {% endif %}SAAS services</title>
    <script src="https://yandex.st/jquery/2.0.3/jquery.min.js"></script>
    <script src="https://yandex.st/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <script src="{% static 'js/cgi_switcher.js' %}"></script>
    <script type="text/javascript" src="{% static 'js/jquery.tablesorter.min.js'%}"></script>
</head>

<style>
    .serv-ctype {
        background-color: #fbe7fb;
        color: #9b6897;
        margin: 5px;
    }
    .button-mine {
        border-radius:3px;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        border: 1px solid grey;
        margin:0;
        margin-right:-1px;
        padding:5px;
    }
    .button-all-owners {
        border-radius:3px;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
        border:1px solid grey;
        margin:0;
        padding:5px;
    }
    .button-selected {
        background-color: #fbe7fb;
    }
    .button-unselected {
        background-color:white;
    }
    .buttons-group {
        padding: 5px;
    }
</style>

<script type='text/javascript'>
    $(document).ready(function(){
        //alert('ready');
        {% for ct in slots %}
            $('#slots-{{ ct }}').tablesorter();
        {% endfor %}
   //     $('#slots-stable').tablesorter();
 //       $('#slots-prestable').tablesorter();
    });

    function switch_mine_all() {
        window.location.search = switch_cgi_param_my();
    }

    function go_to_service(){
        let serv = document.getElementById('service').value;
        window.location.assign("/edit_service/" + serv + '?new_service=yes');
    }
    function check_ent(){
        if (event.keyCode === 13) {
            go_to_service();
        }
    }


</script>
<body>
<div style="width:100%">
    <div class="buttons-group" style="float:left">
        <button
                class="button-mine {% if my %}button-selected{% else %}button-unselected{% endif %}"
            onclick="switch_mine_all()">
            My
        </button><button
                class="button-all-owners {% if my %}button-unselected{% else %}button-selected{% endif %}"
            onclick="switch_mine_all()">
            All services
        </button>
    </div>
    <div style='float:right;padding-right:3%'>
        <div><a href='{% url 'monitor_gui'%}' target='_blank'><b>Monitor all</b></a></div>
        <div><a href='{% url 'service_alerts'%}' target='_blank'><b>All alerts</b></a></div>
        <div class="dropdown"><a data-toggle="dropdown" style="cursor:pointer"><b>Sla tables <span class="caret"></span></b></a>
            <ul class="dropdown-menu">
                {% for ct in sla_ctypes %}
                <li><a href='{% url 'sla_info'%}?ctype={{ ct }}' target='_blank'>{{ ct }}</a></li>
                {% endfor %}
            </ul>
        </div>
        <div class="dropdown"><a data-toggle="dropdown" style="cursor:pointer"><b>Nanny info <span class="caret"></span></b></a>
            <ul class="dropdown-menu">
                {% for ct in all_ctypes %}
                <li><a href='{% url 'nanny_info'%}?ctype={{ ct }}' target='_blank'>{{ ct }}</a></li>
                {% endfor %}
            </ul>
        </div>
        <div class="dropdown"><a data-toggle="dropdown" style="cursor:pointer"><b>Cluster map <span class="caret"></span></b></a>
            <ul class="dropdown-menu">
                {% for ct in all_ctypes %}
                <li><a href='{% url 'cluster_map'%}?ctype={{ ct }}' target='_blank'>{{ ct }}</a></li>
                {% endfor %}
            </ul>
        </div>
        <div hidden><a data-target='#slots2serv' data-toggle="collapse"><b>Slots2Services</b></a></div>
        <div class='collapse' id='slots2serv' style='float:right'>
            {% for ct, cts in slots.items %}
            <div style='float:right'>
                <h5 class='h-p'>{{ ct }}:</h5>
                <table class='tablesorter' id='slots-{{ ct }}' style='border:1px solid pink'>
                <thead><tr><th style='margin:2px;'>Slot</th><th style='margin:2px'>Service</th></tr></thead>
                <tbody>
                {% for slot in cts %}
                    <tr><td style='margin:2px'>{{ slot.slot }}</td> <td style='margin:2px'>{{ slot.service }}</td></tr>
                {% endfor %}
                </tbody>
                </table>
            </div>
            {% endfor %}
        </div>
    </div>
    <div style="float:right">
        <a href="https://ssm.n.yandex-team.ru/" target="_blank"
           style="margin-right:10px;color:black;font-weight: bold;">
            +Add service</a>
        <a href="https://wiki.yandex-team.ru/jandekspoisk/saas/"
           style="margin-right:10px" target="_blank">wiki</a>
        <a href="https://wiki.yandex-team.ru/jandekspoisk/saas/Support/"
           style="margin-right:10px" target="_blank">support</a>
    </div>
</div>

<div style="width:100%;display:table">
    <br>
    <div style='float:left; padding-right:20%;padding-left:3%'>
    <h4>Saas services:</h4>
    {% if errors|length > 0 %}
            <h5 class='h-p'>Errors!</h5>
            <table>
            {% for er, erd in errors.items %}
                <tr>
                <td><span style='color: #f462b5'><b>{{ er }}</b></span></td><td>{{ erd }}</td>
                </tr>
            {% endfor %}
            </table>
    {% endif %}
    {% if errors|length > 0 %}
        <h5 class='h-p'>Errors!</h5>
        <table>
        {% for err, erd in errors.items %}
            <tr>
            <td><b><span style='color: #f462b5'>{{ err }}</span></b></td><td>{{ erd }}</td>
            </tr>
        {% endfor %}
        </table>
    {% endif %}
    <table>
    {% for serv in services %}
        <tr>

            <td><b>{{ serv.service }}:</b>
            {% for ct in serv.ctypes %}
                <span class="serv-ctype dropdown">
                <span data-toggle="dropdown" style="cursor:pointer">{{ ct }}</span>
                <ul class="dropdown-menu">
                    {% if not serv.is_meta %}
                    <li><a href="{% url 'deploy_page' %}?ctype={{ ct }}&service={{ serv.service }}">cluster & deploy</a></li>
                    <li><a href="{% url 'cluster_total' %}?ctype={{ ct }}&service={{ serv.service }}">cluster hardware</a></li>
                    {% endif %}
                    <li><a href="{% url 'monitor_gui' %}/?ctype={{ ct }}&service={{ serv.service }}">monitor</a></li>
                    <li><a href="{% url 'monitor_hosts' %}/?ctype={{ ct }}&service={{ serv.service }}">monitor-hosts</a></li>
                </ul>
                </span>
            {% endfor %}
            {% if serv.is_meta %}
                <span class="serv-ctype" style="background-color:#fef5fb">metaservices</span>
            {% endif %}
            </td>
            <td style='padding-right:10px'><a href="{% url 'service_info' %}?service={{ serv.service }}&ctype={{ serv.ctypes.0 }}" target="_blank">configs</a></td>
            <td style='padding-right:10px'><a href="{% url 'deploy_page' %}?service={{ serv.service }}&ctype={{ serv.ctypes.0 }}" target="_blank">cluster</a></td>
            <td style='padding-right:10px'><a href="{% url 'monitor_gui' %}/?service={{ serv.service }}&ctype={{ serv.ctypes.0 }}" target='_blank'> monitor</a></td>
            <td style='padding-right:10px'><a href="{% url 'polynom_converter' %}?service={{ serv.service }}" target="_blank"> polynom</a></td>
            <td style='padding-right:10px'><a href="{% url 'service_alerts' %}?service={{ serv.service }}" target='_blank'> alerts</a></td>

        </tr>
    {% endfor %}
    {% if serv_inact|length > 0 %}
    {% for serv in serv_inact %}
        <tr>
            <td style='color:grey'><b>{{ serv }}:</b></td>
            <td><a href="{% url 'storage' %}?path=/configs/{{ serv }}" target="_blank">storage</a></td>
        </tr>
    {% endfor %}
    {% endif %}
    </table>

    <br>
    <b>searchproxy</b> {% for ct in all_ctypes %}
        <span class="serv-ctype dropdown">
                <span data-toggle="dropdown" style="cursor:pointer">{{ ct }}</span>
                <ul class="dropdown-menu">
                    <li><a href="{% url 'deploy_page' %}?ctype={{ ct }}&service=searchproxy">cluster & deploy</a></li>
                    <li><a href="{% url 'cluster_total' %}?ctype={{ ct }}&service=searchproxy">cluster hardware</a></li>
                    <li><a href="{% url 'monitor_gui' %}/?ctype={{ ct }}">monitor</a></li>
                    <li><a href="{% url 'monitor_hosts' %}/?ctype={{ ct }}&service=searchproxy">monitor-hosts</a></li>
                </ul>
        </span>
    {% endfor %}
    <a href="{% url 'service_info' %}?service=searchproxy&ctype=stable">configs</a>
        <br>
    <b>indexerproxy</b>{% for ct in all_ctypes %}
        <span class="serv-ctype dropdown">
                <span data-toggle="dropdown" style="cursor:pointer">{{ ct }}</span>
                <ul class="dropdown-menu">
                    <li><a href="{% url 'deploy_page' %}?ctype={{ ct }}&service=indexerproxy">cluster & deploy</a></li>
                    <li><a href="{% url 'cluster_total' %}?ctype={{ ct }}&service=indexerproxy">cluster hardware</a></li>
                    <li><a href="{% url 'monitor_gui' %}/?ctype={{ ct }}">monitor</a></li>
                    <li><a href="{% url 'monitor_hosts' %}/?ctype={{ ct }}&service=indexerproxy">monitor-hosts</a></li>
                </ul>
        </span>
    {% endfor %}
    <a href="{% url 'service_info' %}?service=indexerproxy&ctype=stable">configs</a>
        <br>

    <a href="{% url 'storage' %}?path=/common"><b>common</b></a><br>
    <a href="{% url 'storage' %}?path=/defaults"><b>defaults</b></a><br>
    </div>
</div>
{% if user %}
    <div><br><br><i>We are watching you, {{ user }}</i></div>{% endif %}
</body>
</html>
