{% extends "layout.html" %}
{% block content %}
{% if data['result_list']|count %}
<script type="text/javascript">
    $(function() {

        $('#testresult').puidatatable({
            caption: 'Test Result',
            paginator: {
                rows: 20
            },
            columns: [
                {field:'testid', headerText: 'id', headerStyle: 'width: 60px;', sortable: false},
                {field:'testname', headerText: 'Test name', headerStyle: 'width: 50%;', sortable: false},
                {field:'browserid', headerText: 'Browser id', sortable: false},
                {field:'result', headerText: 'Result', sortable: false},
                {field:'screenshot', headerText: 'Screenshot', sortable: false},
                {field: 'report', headerText: 'Report', sortable: false},
            ],
            datasource: [
                {% for result in data['result_list'] %}
                    {
                        'testid': {% if result.test.test_id %} '{{ result.test.test_id }}' {% else %} 'N/A' {% endif %},
                        'testname': '{{ result.title }}',
                        'browserid': '{{ result.browser_id }}',
                        'result': '<div class="text-center"><span class="label label-{% if result.result %}success{% else %}danger{% endif %}"> {% if result.result %} <i class="fa fa-check"></i> {% else %} <i class="fa fa-exclamation"></i> {% endif %}</span></div>',
                        'screenshot': '<div id="{{ result.id }}">' +
                                    {% if result.screenshot_path != '' %}
                                            '<a class="unlink" href="{{ url_for('testbatch.test_batch_report_file', filename = result.screenshot_path) }}" target="_blank" >' +
                                                'View screenshot' +
                                            '</a>' +
                                    {% else %}
                                        '<p class="text-center"> N/A </p>' +
                                    {% endif %}
                                        '</div>',
                        'report': '<div>' +
                                    {% if not test_batch_is_running %}
                                        '<a class="unlink" href="{{ url_for('testbatch.report', object_type = 'test_result', object_id = result.id) }}" target="_blank" >' +
                                            'Report' +
                                        '</a>' +
                                    {% else %}
                                        '<p class="text-center"> N/A </p>' +
                                    {% endif %}
                                '</div>'
                    },
                {% endfor %}
            ]
        });
    });
</script>
{% endif %}
<div>
    <h1>Test Result for Test Batch id: {{ testbatch_id }}</h1>
</div>
{% if data['result_list']|count %}
    <div id="testresult"></div>
{% else %}
    <div>
        <h1 class="text-center"> No test result in this test batch</h1>
    </div>
{% endif %}
{% endblock %}
