
{% extends "layout.html" %}
{% block content %}
<script type="text/javascript">
    $(function() {
        {% if data['test_batch'].ending_timestamp is none %}
            $('#testprogress').puiprogressbar();
        {% endif %}
     
        $('#accordion').puiaccordion({multiple:true});
        $('#accordion').puiaccordion('select', 1);

        {% if data['test_batch'].ending_timestamp is none %}
            var interval_id = setInterval(function() {
                var runner_log_length = $('#runnerlog > h6').length,
                    current_progress = $('.pui-progressbar-label').html();

                Sijax.request('update_info', [{{ testbatch_id }}, interval_id, runner_log_length, current_progress]);

            }, 2000);
        {% endif %}

    });
</script>
<div>
    {% if data['test_batch'].ending_timestamp is none %}
        <a class="btn btn-danger" href="javascript://" onclick="onTestBatchStop({{ testbatch_id }});" title="Stop this test batch" style="float: right; margin-right: 10px;">
           <i class="fa fa-stop"></i>
        </a>
    {% else %}
        <a class="btn btn-danger" href="javascript://" onclick="onTestBatchDelete({{ testbatch_id }});" title="Delete this test batch" style="float: right; margin-right: 10px;">
            <i class="fa fa-remove"></i>
        </a>
    {% endif %}
    <h1>Test Batch id: {{ testbatch_id }}</h1>
</div>
<div>
    {% if data['test_batch'].ending_timestamp is none %}
        <div id="testprogressdiv">
            <label>Test batch progress:</label>
            <div id="testprogress"></div>
        </div>
    {% endif %}
    <div id="testexecutiontimediv" {%if data['test_batch'].ending_timestamp is none %} style="display: none;" {% endif %}>
        <label>Total execution time:</label>
        <span id="testexecutiontimespan">
            <strong>{{ data['test_batch'].total_execution_time }}</strong>
        </span>
    </div>
    <div class="container-fluid">
        <div class="row-fluid text-center">
                <strong style="padding-left:20px;">Total tests:</strong> <span>{{ data['test_batch'].total_tests}}</span>
                <strong style="padding-left:20px;">Total finished tests:</strong> <span id="total_finished_tests">{{ data['test_batch'].total_finished_tests }}</span>
                <strong style="padding-left:20px;">Total executing tests:</strong> <span id="total_executing_tests">{{ data['test_batch'].total_executing_tests}}</span>
        </div>
    </div>
</div>
<div id="accordion">
    <h3>Report:</h3>
    <div>
        <ul class="list-unstyled">
            {% if show_network_capture %}
                <li>
                    <a class="unlink" href="{{ url_for('testbatch.network_capture', testbatch_id = testbatch_id) }}"><i class="fa fa-cubes"></i> Network Capture</a>
                </li>
            {% endif %}
            {% if show_video_capture %}
                <li>
                    <a class="unlink" href="{{ url_for('testbatch.video_recording_list', testbatch_id = testbatch_id) }}"><i class="fa fa-television"></i> Video recordings</a>
                </li>
            {% endif %}
            {% if show_test_instances %}
                <li>
                    <a class="unlink" href="{{ url_for('testbatch.test_instances', testbatch_id = testbatch_id) }}"><i class="fa fa-eye"></i> Test intances</a>
                </li>
            {% endif %}
            <li>
                <a class="unlink" href="{{ url_for('testbatch.screenshot', testbatch_id = testbatch_id) }}"><i class="fa fa-file-image-o"></i> Screenshots (<span id="total_screenshots">{{ data['test_batch'].total_screenshots}}</span>)</a>
            </li>
            <li>
                <a class="unlink" href="{{ url_for('testbatch.testresult', testbatch_id = testbatch_id) }}">
                    <i class="fa fa-bar-chart"></i> 
                    Test results (<span id="total_test_results">{{ data['test_batch'].total_test_results}}</span>) Failed (<span id="total_failed_tests" style="color:red;"> {{ data['test_batch'].total_failed_tests }} </span>)
                </a>
            </li>
            <li>
                <a class="unlink" href="{{ url_for('testbatch.crash', testbatch_id = testbatch_id) }}"><i class="fa fa-exclamation-triangle"></i> Crash reports (<span id="total_crashes">{{ data['test_batch'].total_crashes}}</span>)</a>
            </li>
        </ul>
    </div>
 
    <h3>Runner's log:</h3>
    <div>
        <div id="runnerlog" style="overflow: auto; max-height: 500px;">
            {% for line in data['runner_log'] %}
                <h6>{{ line }}</h6>
            {% endfor %}
        </div>
    </div>

    <h3>Test instance's log:</h3>
    <div>
        {% if not data['logs']|count %}
            <div>
                <p>No logs</p>
            </div>
        {% else %}
            <div style="overflow: auto; max-height: 500px;">
                <ul class="list-unstyled">
                    {% for log in data['logs'] %}
                        <li>
                            <a class="unlink" target="_blank" href="{{ url_for('testbatch.test_batch_report_file', filename = log['path']) }}"><i class="fa fa-sticky-note"></i> {{ log['name'] }}</a>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        {% endif %}
    </div>    
</div>
{% endblock %}
