{% extends "squad/base.jinja2" %}

{% block content %}
<div ng-app='Build'>
    <div>
    {% include "squad/build-nav.jinja2" %}
    </div>
    <h1>{{ _('Test Jobs') }}</h1>
    <div ng-app='SquadResubmit'>
    {% for testjob in testjobs %}
    <div class="row row-bordered project">
        <div class="col-md-12 col-sm-12 project-listing-info">
            <div title='Test Job'>
                {% if not testjob.failure %}
                    <span class="badge alert-success"><i class='fa fa-check'></i></span>
                {% else %}
                    <span class="badge alert-danger"><i class="fa fa-close"></i></span>
                {% endif %}
                {% if testjob.url %}<a href="{{ testjob.url }}">{% endif %}{{ testjob.job_id }}, {{ testjob.environment }}, {{ testjob.name }} ({{testjob.job_status}}){% if testjob.url %}</a>{% endif %}
                {% if testjob.submitted %}
                    <span class="badge alert-success">{{ _('Submitted') }} <i class='fa fa-check'></i></span>
                {% else %}
                    <span class="badge alert-danger">{{ _('Not submitted') }} <i class="fa fa-close"></i></span>
                {% endif %}
                {% if testjob.fetched %}
                    <span class="badge alert-success">{{ _('Fetched') }} <i class='fa fa-check'></i></span>
                {% else %}
                    <span class="badge alert-danger">{{ _('Not fetched') }} <i class="fa fa-close"></i></span>
                    {{ _('Last fetch attempt: %s') % testjob.last_fetch_attempt|naturaltime }}
                {% endif %}

                {% if testjob.testrun %}
                    <a href="{{project_url(testjob.testrun)}}">{{ _('Test run #%s') % testjob.testrun.job_id }}</a>
                {% endif %}
                {% if testjob.parent_job %}
                    <a href="{{ testjob.parent_job.url }}">{{ _('Resubmitted from #%s') % testjob.parent_job.job_id }}</a>
                {% endif %}
                {% if testjob.failure %}
                <button class="btn btn-default btn-sm" type="button" data-toggle="collapse" data-target="#collapse-failure-{{testjob.pk}}" aria-expanded="false" aria-controls="collapse-failure-{{testjob.pk}}"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span></button>
                {% endif %}
                {% if testjob.definition %}
                <button class="btn btn-default btn-sm" type="button" data-toggle="collapse" data-target="#collapse-definition-{{testjob.pk}}" aria-expanded="false" aria-controls="collapse-definition-{{testjob.pk}}"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></button>
                {% endif %}
                {% if project.can_submit(user) %}
                <div class='pull-right' ng-controller='ResubmitController'>
                    <a class="btn" ng-click="resubmit({{testjob.id}}, true)" ng-class="{'btn-info': !done, 'btn-success': done, 'btn-danger': error}" ng-disabled="done" ><span ng-class="{'fa':true, 'fa-recycle':!done, 'fa-check': done && !error, 'fa-spin': loading, 'fa-close': error}" ng-disabled="done"></span> {{ _('%s - force resubmit') % testjob.job_id }}</a>
                {% if testjob.can_resubmit %}
                    <a class="btn" ng-click="resubmit({{testjob.id}}, false)" ng-class="{'btn-info': !done, 'btn-success': done, 'btn-danger': error}" ng-disabled="done" ><span ng-class="{'fa':true, 'fa-recycle':!done, 'fa-check': done && !error, 'fa-spin': loading, 'fa-close': error}" ng-disabled="done"></span> {{ _('%s - resubmit')  % testjob.job_id }}</a>
                {% endif %}
                </div>
                {% endif %}

            </div>
            {% if testjob.failure %}
            <div class="collapse" id="collapse-failure-{{testjob.pk}}">
                <h4>{{ _('Error message') }}</h4>
                <pre>{{ testjob.failure }}</pre>
            </div>
            {% endif %}
            {% if testjob.definition %}
            <div class="collapse" id="collapse-definition-{{testjob.pk}}">
                <h4>{{ _('Definition') }}</h4>
                <pre>{{ testjob.show_definition }}</pre>
            </div>
            {% endif %}
        </div>
    </div>
    {% endfor %}
    </div>
</div>
{% endblock %}

{% block javascript %}
<script type="module" src='{{static("squad/build.js")}}'></script>
{% endblock %}
