{% extends "stg_detail.html" %}

{% block title %}{{ title }}{% endblock %}

{% block details %}

<h1><a href="{{ obj.get_absolute_url }}">StagingBatch {{ obj.id }}</a></h1>

<h2 class="batch_status_{{ obj.status }}">Status: {{ obj.status|capfirst }}</h2>

<ul>
    {% if obj.start %}
    <li>Started: {{ obj.hr_start }}</li>
    {% else %}
    {% load admin_urls %}
    <li><a href="{% url 'djhcup_staging.views.run_batch' obj_id=obj.id obj_type='StagingBatch' %}">Run this batch</a></li>
    {% endif %}
    {% if obj.complete %}
        <li>Completed: {{ obj.hr_complete }}</li>
        <li>Actual runtime {{ obj.hr_runtime|floatformat:1 }} hours</li>
    {% endif %}
    <li>Enqueued in batch: {{ enqueued|length }}</li>
    <li><a href="{% url 'admin:djhcup_staging_stagingbatch_change' obj.pk %}">Edit this StagingBatch in the Django admin&rarr;</a></li>
</ul>

{% if enqueued|length > 0 %}
    <h2>Batch Contents</h2>
    <table class="batch_items">
    <tr>
        <th class="txt_col">Item</th>
        <th class="txt_col">Status</th>
        <th class="txt_col">Input: Primary</th>
        <th class="txt_col">Input: Charges</th>
        <th class="txt_col">Input: PR</th>
        <th class="txt_col">Input: UFlags</th>
        <th class="txt_col">Input: Days To Event</th>
        <th class="txt_col">Input: AHA Link</th>
        <th class="txt_col">Input: Severity</th>
        <th class="txt_col">Input: DX/PR Groups</th>
    </tr>
    {% for e in enqueued %}
        <tr class="status_{{ e.status }}">
            <td class="txt_col">StagingQueue #{{ e.pk }}: {{ e.category }}</td>
            <td class="txt_col">{{ e.status }}{% if e.message %}<br
                />{{ e.message }}{% endif %}{% if e.start %}<br
                />Started {{ e.hr_start }}{% if e.complete %}<br
                />Completed {{ e.hr_complete }}
                {% endif %}{% endif %}{% if st.stg_output %}{% with st.stg_output as t %}<br
                /><a href="{{ t.get_absolute_url }}">{{ t.name }} (StagingTable #{{ t.pk }})</a>{% endwith %}{% endif %}
                </td>
            <td class="txt_col">{% if e.stg_input %}<a href="{{ e.stg_input.get_absolute_url }}">{{ e.stg_input }}</a>{% else %}None{% endif %}</td>
            <td class="txt_col">{% if e.charges_input %}<a href="{{ e.charges_input.get_absolute_url }}">{{ e.charges_input }}</a>{% else %}None{% endif %}</td>
            <td class="txt_col">{% if e.pr_input %}<a href="{{ e.pr_input.get_absolute_url }}">{{ e.pr_input }}</a>{% else %}None{% endif %}</td>
            <td class="txt_col">{% if e.uflag_input %}<a href="{{ e.uflag_input.get_absolute_url }}">{{ e.uflag_input }}</a>{% else %}None{% endif %}</td>
            <td class="txt_col">{% if e.dte_input %}<a href="{{ e.dte_input.get_absolute_url }}">{{ e.dte_input }}</a>{% else %}None{% endif %}</td>
            <td class="txt_col">{% if e.aha_input %}<a href="{{ e.aha_input.get_absolute_url }}">{{ e.aha_input }}</a>{% else %}None{% endif %}</td>
            <td class="txt_col">{% if e.severity_input %}<a href="{{ e.severity_input.get_absolute_url }}">{{ e.severity_input }}</a>{% else %}None{% endif %}</td>
            <td class="txt_col">{% if e.dx_pr_grps %}<a href="{{ e.dx_pr_grps.get_absolute_url }}">{{ e.dx_pr_grps }}</a>{% else %}None{% endif %}</td>

        </tr>
    {% endfor %}
    </table>
{% endif %}

{% endblock %}
