{% load helpers %}
{% load custom_links %}
{% load form_helpers %}
{% load ajax_table %}
{% load render_table from django_tables2 %}
{% load log_levels %}
{% load plugins %}
{% load static %}

<div class="panel panel-default">
    <div class="panel-heading">
        <strong>Summary of Results</strong>
    </div>
    <table class="table table-hover panel-body">
        {% if result.job_model is not None %}
            <tr>
                <td>Job Description</td>
                <td>{{ result.job_model.description | render_markdown }}</td>
            </tr>
        {% endif %}
        <tr>
            <td>Status</td>
            <td><span id="pending-result-label">{% include 'extras/inc/job_label.html' with result=result %}</span></td>
        </tr>
        <tr>
            <td>Started at</td>
            <td>{{ result.date_created }}</td>
        </tr>
        <tr>
            <td>User</td>
            <td>{{ result.user }}</td>
        </tr>
        <tr>
            <td>Duration</td>
            <td id="pending-result-loader">
            {% if result.date_done %}
                {{ result.duration }}
            {% else %}
                <img src="{% static 'img/ajax-loader.gif' %}">
            {% endif %}
            </td>
        </tr>
        <tr>
            <td>Return Value</td>
            <td id="pending-result-loader">
            {% if result.date_done %}
                {{ result.result | placeholder }}
            {% else %}
                <img src="{% static 'img/ajax-loader.gif' %}">
            {% endif %}
            </td>
        </tr>
        {% if result.files.exists %}
            <tr>
                <td>File Output(s)</td>
                <td>
                    <ul>
                        {% for file_proxy in result.files.all %}
                            {% if file_proxy.file %}
                                <li>
                                    <a
                                    {% if settings.JOB_FILE_IO_STORAGE == "db_file_storage.storage.DatabaseFileStorage" %}
                                        href="{% url "db_file_storage.download_file" %}?name={{ file_proxy.file }}"
                                    {% else %}
                                        href="{{ file_proxy.file.url }}"
                                    {% endif %}
                                        download="{{ file_proxy.name }}">
                                        {{ file_proxy.name }}
                                    </a>
                                </li>
                            {% endif %}
                        {% endfor %}
                    </ul>
                </td>
            </tr>
        {% endif %}
    </table>
</div>


<div class="panel panel-default">
    <div class="panel-heading">
        <strong>Logs</strong>
        <div class="pull-right noprint">
            <input class="form-control" id="log-filter" type="text" placeholder="Filter log level or message" title="Filter log level or message" style="height: 23px" />
        </div>
    </div>
    {% ajax_table "log_table" "extras:jobresult_log-table" pk=result.pk %}
</div>

