{% extends "admin/scheduler/scheduler_base.html" %}

{% load static scheduler_tags %}

{% block title %}{{ job_status }} Jobs in {{ queue.name }} {{ block.super }}{% endblock %}

{% block extrastyle %}
    {{ block.super }}
    <link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}">
{% endblock %}


{% block breadcrumbs %}
    <div class="breadcrumbs">
        <a href="{% url 'admin:index' %}">Home</a> &rsaquo;
        <a href="{% url 'queues_home' %}">Queues</a> &rsaquo;
        <a href="{% url 'queue_registry_jobs' queue.name 'queued' %}">{{ queue.name }}</a>
    </div>
{% endblock %}

{% block content_title %}<h1>{{ job_status }} jobs in {{ queue.name }}</h1>{% endblock %}

{% block content %}

    <div id="content-main">
        <ul class="object-tools">
            {% if job_status == 'Failed' %}
                <li><a href="{% url 'queue_requeue_all' queue.name registry_name %}" class="requeuelink">Requeue All</a>
                </li>
            {% endif %}
            <li><a href="{% url 'queue_clear' queue.name registry_name %}" class="deletelink">Empty Queue</a></li>
        </ul>
        <div class="module" id="changelist">
            <form id="changelist-form" action="{% url 'queue_confirm_action' queue.name %}" method="post">
                {% csrf_token %}
                <div class="actions">
                    <label>Actions:
                        <select name="action">
                            <option value="" selected="selected">---------</option>
                            <option value="delete">Delete</option>
                            <option value="stop">Stop</option>
                            {% if job_status == 'Failed' %}
                                <option value="requeue">Requeue</option>
                            {% endif %}
                        </select>
                    </label>
                    <button type="submit" class="button" title="Execute selected action" name="index" value="0">Go
                    </button>
                </div>
                <div class="results">
                    <table id="result_list">
                        <thead>
                        <tr>
                            <th scope="col" class="action-checkbox-column">
                                <div class="text">
                                    <span><input type="checkbox" id="action-toggle"
                                                 style="display: inline-block;"></span>
                                </div>
                                <div class="clear"></div>
                            </th>
                            <th>
                                <div class='text'>ID</div>
                            </th>
                            <th>
                                <div class='text'>Created</div>
                            </th>
                            <th>
                                <div class='text'><span>Scheduled</span></div>
                            </th>
                            <th>
                                <div class='text'><span>Enqueued</span></div>
                            </th>
                            <th>
                                <div class='text'><span>Ended</span></div>
                            </th>
                            <th>
                                <div class='text'><span>Status</span></div>
                            </th>
                            <th>
                                <div class='text'><span>Callable</span></div>
                            </th>
                            <th>
                                <div class='text'><span>Worker</span></div>
                            </th>
                            {% block extra_columns %}
                            {% endblock extra_columns %}
                        </tr>
                        </thead>
                        <tbody>
                        {% for job in jobs %}
                            <tr class="{% cycle 'row1' 'row2' %}">
                                <td class="action-checkbox">
                                    <input class="action-select"
                                           name="_selected_action" type="checkbox"
                                           value="{{ job.id }}">
                                </td>
                                <th>
                                    <a href="{% url 'job_details' job.id %}">
                                        {{ job.id }}
                                    </a>
                                </th>
                                <td>
                                    {{ job.created_at|date:"Y-m-d, H:i:s" }}
                                </td>
                                <td>
                                    {{ job|job_scheduled_time:queue|date:"Y-m-d, H:i:s" }}
                                </td>
                                <td>
                                    {{ job.enqueued_at|date:"Y-m-d, H:i:s" }}
                                </td>
                                <td>
                                    {{ job.ended_at|date:"Y-m-d, H:i:s" }}
                                </td>
                                <td>{{ job.get_status }}</td>
                                <td>{{ job|show_func_name }}</td>
                                <td>{{ job.worker_name|default:'-' }}</td>
                                {% block extra_columns_values %}
                                {% endblock extra_columns_values %}
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <p class="paginator">
                    {% for p in page_range %}
                        {% if p == page %}
                            <span class="this-page">{{ p }}</span>
                        {% elif forloop.last %}
                            <a href="?page={{ p }}" class="end">{{ p }}</a>
                        {% else %}
                            <a href="?page={{ p }}">{{ p }}</a>
                        {% endif %}
                    {% endfor %}
                    {{ num_jobs }} jobs
                </p>
            </form>
        </div>
    </div>

{% endblock %}
