{% extends frame.html %}

{% block head %}
<meta http-equiv="refresh" content="30" />
{% end %}

{% block body %}
<h1>Builds    <a href="/admin/build/add" class="w3-right w3-btn w3-blue w3-large">+ New Build</a></h1>

<form action="{{request.uri}}" method="POST">
    {% raw xsrf_form_html() %}
    <table class="w3-table-all w3-responsive">
        <tr>
            <th>Version</th>
            <th>Build</th>
            <th>Deploy</th>
            <th>Revert</th>
            <th>Size</th>
            <th></th>
        </tr>

        {% for build in builds %}
        <tr {% if live_build and build['build_id'] == live_build['build_id'] %} class="w3-pale-yellow"{% end %}>
            <td nowrap="nowrap">{{build['version']}}</td>
            <td><a href="/admin/build/{{build['build_id']}}">{% if build['build_exit_status'] %}ERROR {{build['build_exit_status']}}{% elif build['build_exit_status'] == 0 %}SUCCESS{% else %}RUNNING{% end %}</a> <br/><span class="w3-small">{{build['create_dttm']}}</span></td>

            <td>{% if build['build_exit_status'] == 0 %}
                {% if build['deploy_output_tx'] is None %}
                <a href="/admin/build/{{build['build_id']}}/deploy" class="w3-button w3-blue w3-center w3-medium w3-padding-small">Deploy</a>
                {% else %}
                <a href="/admin/build/{{build['build_id']}}?build_step=deploy">{% if build['deploy_exit_status'] %}ERROR {{build['deploy_exit_status']}}{% elif build['deploy_exit_status'] == 0 %}SUCCESS{% else %}RUNNING{% end %}</a> <br/><span class="w3-small">{{build['deploy_dttm']}}</span>
                {% end %}
                {% end %}
            </td>

            <td>
                {% if build['revert_dttm'] or build['revert_output_tx'] is not None %}
                <a href="/admin/build/{{build['build_id']}}?build_step=revert">
                    {% if build['revert_exit_status'] %}ERROR {{build['revert_exit_status']}}
                    {% elif build['revert_exit_status'] == 0 %}SUCCESS
                    {% else %}RUNNING{% end %}
                </a> <br/><span class="w3-small">{{build['revert_dttm']}}</span>
                {% else %}
                {% if live_build and build.get('previous_version') and build['build_id'] == live_build['build_id'] %}<a href="/admin/build/{{build['build_id']}}/revert" class="w3-button w3-blue w3-center w3-medium w3-padding-small">Revert</a>{% end %}
                {% end %}</td>
            <td>{% if build['build_size'] %}{{"%4.2f MB" % (build['build_size'] / 1024 / 1024)}}{% end %}</td>
            <td>{% if live_build and not build['build_id'] == live_build['build_id'] and not build['deploy_dttm'] %}<input type="submit" class="w3-button w3-blue w3-center w3-medium w3-padding-small" name="delete_{{build['build_id']}}" value="Delete"/>{% end %}</td>
        </tr>
        {% end %}

    </table>
</form>

<div class="debug-panel">
    Debug Info<br/>
    Env: {{env}}<br/>
    Hostname: {{host}}<br/>
    Aegis Version: {{aegis_version}}<br/>
    App Version: {{app_version}}
</div>

{% end %}
