{% extends "administration/base.html" %}

{% load i18n %}
{% load humanize %}
{% load passbook_utils %}

{% block content %}
<section class="pf-c-page__main-section pf-m-light">
    <div class="pf-c-content">
        <h1>
            <i class="pf-icon pf-icon-automation"></i>
            {% trans 'System Tasks' %}
        </h1>
        <p>{% trans "Long-running operations which passbook executes in the background." %}</p>
    </div>
</section>
<section class="pf-c-page__main-section pf-m-no-padding-mobile">
    <div class="pf-c-card">
        <table class="pf-c-table pf-m-compact pf-m-grid-xl" role="grid">
            <thead>
                <tr role="row">
                    <th role="columnheader" scope="col">{% trans 'Identifier' %}</th>
                    <th role="columnheader" scope="col">{% trans 'Description' %}</th>
                    <th role="columnheader" scope="col">{% trans 'Last Status' %}</th>
                    <th role="columnheader" scope="col">{% trans 'Status' %}</th>
                    <th role="columnheader" scope="col">{% trans 'Messages' %}</th>
                    <th role="cell"></th>
                </tr>
            </thead>
            <tbody role="rowgroup">
                {% for task in object_list %}
                <tr role="row">
                    <th role="columnheader">
                        <pre>{{ task.task_name }}</pre>
                    </th>
                    <td role="cell">
                        <span>
                            {{ task.task_description }}
                        </span>
                    </td>
                    <td role="cell">
                        <span>
                            {{ task.finish_timestamp|naturaltime }}
                        </span>
                    </td>
                    <td role="cell">
                        <span>
                            {% if task.result.status == task_successful %}
                            <i class="fas fa-check pf-m-success"></i> {% trans 'Successful' %}
                            {% elif task.result.status == task_warning %}
                            <i class="fas fa-exclamation-triangle pf-m-warning"></i> {% trans 'Warning' %}
                            {% elif task.result.status == task_error %}
                            <i class="fas fa-times pf-m-danger"></i> {% trans 'Error' %}
                            {% else %}
                            <i class="fas fa-question-circle"></i> {% trans 'Unknown' %}
                            {% endif %}
                        </span>
                    </td>
                    <td>
                        {% for message in task.result.messages %}
                        <div>
                            {{ message }}
                        </div>
                        {% endfor %}
                    </td>
                    <td>
                        <button is="action-button" class="pf-c-button pf-m-primary" url="{% url 'passbook_api:admin_system_tasks-retry' pk=task.task_name %}">
                            {% trans 'Retry Task' %}
                        </button>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</section>
{% endblock %}