{% extends "base.html" %}
{% block title %}Run queue{% endblock %}
{% load colour_table_row %}
{% load naturaltime from humanize %}

{% block body %}
    <div class="row">
        <div class="col-md-12 text-center">
            <h2>Run Queue</h2>
        </div>
    </div>
    {% if queue %}
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>Run Number</th>
                    <th>Instrument</th>
                    <th>Status</th>
                    <th>Submitted</th>
                    <th>Submitted By</th>
                </tr>
            </thead>
            <tbody>
                {% for job, started_by in queue %}
                    <tr class="{% colour_table_row job.status.value_verbose %}">
                        <td>
                            {% if not job.batch_run %}
                            <a class="run-link" href="{% url 'runs:summary' instrument_name=job.instrument.name run_number=job.run_number run_version=job.run_version %}">{{ job.title }}</a>
                            {% else %}
                            <a class="run-link" href="{% url 'runs:batch_summary' instrument_name=job.instrument.name pk=job.pk run_version=job.run_version %}">{{ job.title }}</a>
                            {% endif %}
                        </td>
                        <td>{{ job.instrument.name }}</td>
                        <td id="status-{{ job.run_numbers.first }}-{{ job.run_numbers.last }}"><strong>{{ job.status.value_verbose }}</strong></td>
                        <td title="{{ job.created|date:'SHORT_DATETIME_FORMAT' }}">{{ job.created|naturaltime }}</td>
                        <td> {{ started_by }} </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <div class="row">
            <div class="col-md-12 text-center">
                <h3>No pending reduction jobs.</h3>
            </div>
        </div>
    {% endif %}
{% endblock %}
