{% extends "base_misc.html" %}

{% block title %}Audit Log{% endblock %}
{% block smallheader %}audit{% endblock %}
{% block largeheader %}log{% endblock %}
{% block nav1 %}misc{% endblock %}


{% block content %}
    {% if no_git_repo_found %}
        <p class="lead">
        No git repository found in {{ nagiosdir }}.</p>
        <form method="post" class="form-horizontal">{% csrf_token %}
        <button name="git_init" type="post" class="pull-right btn btn-success">Init a new git repo</button>
        </form>
    {% endif %}
    
    {% if uncommited_files %}
        <h2>There are uncommited files in your git repo</h2>
        <form method="post" class="form-horizontal">{% csrf_token %}
            <table class="gitlog table table-condensed">
            <tr>
                <th><input id="check_all" name="check_all" type="checkbox"/></th>
                <th>status</th>
                <th>filename</th>
            </tr>
            {% for i in uncommited_files %}
                <tr>
                    <td><input id="commit_{{ i.filename }}" name="commit_{{ i.filename }}" checked="1" type="checkbox"/></td>
                    <td>{{ i.status }}</td>
                    <td>{{ i.filename }}</td>
                </tr>
            {% endfor %}
            <tr><td colspan=3>
            <div id="form_control" class="pull-right">
            <input id="git_commit_message" type="text" value="Bulk commit by adagios" name="git_commit_message" />
            <button name="git_commit" type="post" class="btn btn-success">ok, commit selected files</button>
            </div>
            </td></tr>
            </table>
        </form>
    {% endif %}
    {% if commits %}
        <!-- List of recent commits -->
        <h2>Previous changes (via git log)</h2>
        <table class="gitlog table table-condensed" >
        <tr>
            <th>Date</th>
            <th>Summary</th>
            <th>Name</th>
            <th>Email</th>
            <th>Actions</th>
        </tr>
        {% for commit in commits %}
            <tr id="{{ commit.hash }}">
                <td>{{ commit.author_time }}</td>
                <td>{{ commit.comment }}</td>
                <td>{{ commit.author_name }}</td>
                <td>{{ commit.author_email }}</td>
                <td>
                    {% if commit_id != commit.hash %}
                        <a href="{% url misc.views.gitlog %}?show={{ commit.hash }}#{{ commit.hash }}">diff</a>
                    {% else %}
                        <a href="{% url misc.views.gitlog %}">hide</a>
                    {% endif %}
                </td>
            </tr>
            {% if commit_id == commit.hash %}
            <tr>
            <td colspan=5>
                {% if difflines %}
                    <table class="well" width="100%">
                        <thead>
                            <tr>
                                <th>Diff</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for i in difflines %}
                            <tr class={{ i.tag }}>
                                <td>
                                    <div class={{ i.tag }}>{{ i.line }}</div>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                {% else %}
                    <pre>There is nothing in this commit</pre>
                {% endif %}
            </td>
            </tr>
            {% endif %}

        {% endfor %}
        </table>
    {% else %}
        <h2>No git commits found in {{ nagiosdir }}</h2>
    {% endif %}
 {% endblock %}

{% block sidebar %} {{ block.super }} {% endblock %}

{% block footer %} {{ block.super }} {% endblock %}