<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
    <title>Config diffs {{ service }}-{{ ctype }}</title>
    <link href="https://yandex.st/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
</head>
    <script src="https://yandex.st/jquery/2.0.3/jquery.min.js" type="text/javascript"></script>
    <script src="https://yandex.st/bootstrap/3.3.4/js/bootstrap.min.js" type="text/javascript"></script>
    <script type='text/javascript' src="{% static 'js/xmlhttp.js' %}"></script>
    <script type='text/javascript' src="{% static 'js/answer_set.js' %}"></script>
    <script type='text/javascript' src="{% static 'js/data_load.js' %}"></script>
<style>
    ins {
        text-decoration: none;
        background-color: #cbeeba;
    }
    del {
        text-decoration: none;
        background-color: #f0a5a0;
    }
</style>
<script type='text/javascript'>
    function render_diff(res) {
        let el = document.getElementById("diff");
        el.innerHTML = 'Added: ' + res['stats']['added'] + ' (lines: ' + res['stats']['added_lines'] + ')'
            + '; Deleted: ' + res['stats']['deleted'] + ' (lines: ' + res['stats']['deleted_lines'] + ')'
            + '<br>' + res['diff'];
    }
    function load_diff(url1, version2) {
        let url = '{% url "diff_do" %}?url1=' + url1 + '&version2=' + version2;
        let cb = { url: url, do_once_any_case: true,
            answer_id: 'diff_ans_id', hr_legend: 'diff-load',
            on_load: render_diff};
        do_data_load(cb);
    }

    function switch_element_hidden(id) {
        try {
            let el = document.getElementById(id);
            if (el.hasAttribute('hidden')) {
                el.removeAttribute('hidden');
            } else {
                el.setAttribute('hidden', 1);
            }
        } catch(err)  {console.log(err); }
    }

</script>
<body>
<table>
    <tr><td>Diff: {{ different|length }} files</td><td>Versions (current->next)</td></tr>
{% for file in different %}
    <tr><td>{{ file.rename }}</td>
        <td><a onclick="load_diff('{{ file.url }}', '{{ file.last_version }}')"
               style="cursor:pointer;text-decoration: dotted underline"
               title="Show diff below"
        >
            {{ file.version }}->{{ file.last_version }}</a></td>
    </tr>
{% endfor %}
</table>
<br>
Add: {{ added|length }} files ({% for file in added %}{{ file.rename }}, {% endfor %})
<br>
Removed: {{ removed|length }} files ({% for file in removed %}{{ file.rename }}, {% endfor %})
<br>
Same: <span style="cursor:pointer;text-decoration: dotted underline" onclick="switch_element_hidden('same_files')">{{ same|length }} files</span>
    <span id="same_files" hidden>({% for file in same %}{{ file.rename }}, {% endfor %})</span>
<br>
<div id="diff_ans_id"></div>
<div id="diff"></div>
<div id="raw_data" hidden></div>
</body>
</html>
