{% extends "base.html" %}
{% block title %}RB{{ experiment.reference_number|default:" not found" }}{% endblock %}
{% load colour_table_rows %}
{% load naturaltime from humanize %}

{% block body %}
    {% if experiment %}
        <div class="row">
            <div class="col-md-12 text-center">
                <h2>RB{{ experiment.reference_number }}</h2>
            </div>
        </div>
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="panel panel-primary panel-small panel-2-column">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div>
                                    <strong>Title:</strong> {{ experiment_details.title }}
                                </div>
                                <div>
                                    <strong>Principal Investigator:</strong> {{ experiment_details.pi }}
                                </div>
                                <div>
                                    <strong>Instrument:</strong>
                                    {% if experiment_details.instrument %}
                                        <a href="{% url 'runs:list' instrument=experiment_details.instrument %}">
                                            {{ experiment_details.instrument }}
                                        </a>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div>
                                    <strong>Start Date:</strong> {{ experiment_details.start_date }}
                                </div>
                                <div>
                                    <strong>End Date:</strong> {{ experiment_details.end_date }}
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="file-path">
                                    <strong>Data:</strong>
                                    {% if data %}
                                        {% for location in data %}
                                            {{ location.file_path }}<br/>
                                        {% endfor %}
                                    {% else %}
                                        <em>No experiment data found</em>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="file-path">
                                    <strong>Reduced:</strong>
                                    {% if reduced_data %}
                                        {% for location in reduced_data %}
                                            {{ location.file_path }}<br/>
                                        {% endfor %}
                                    {% else %}
                                        <em>No reduced data found</em>
                                    {% endif %}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                {% if runs_with_started_by %}
                    <h3>Reduction Jobs ({{ run_count }})</h3>
                    <table class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>Job Number</th>
                                <th>Status</th>
                                <th>Last Updated</th>
                                <th>Submitted By</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for job, started_by in runs_with_started_by %}
                                <tr>
                                    <td>
                                        <a href="{% url 'runs:summary' instrument_name=job.instrument.name run_number=job.run_number run_version=job.run_version %}">{{ job.title }}</a>
                                    </td>
                                    <td class="text-{% colour_table_row job.status.value_verbose %}">
                                        <strong>{{ job.status.value_verbose }}</strong></td>
                                    <td title="{{ job.last_updated|date:'SHORT_DATETIME_FORMAT' }}">{{ job.last_updated|naturaltime }}</td>
                                    <td>
                                        {% if started_by %}
                                            {{ started_by }}
                                        {% else %}
                                            Unknown
                                        {% endif %}
                                    </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                {% else %}
                    <div class="text-center"><em>No runs found</em></div>
                {% endif %}
            </div>
        </div>
    {% else %}
        <div class="text-center col-md-6 col-md-offset-3 well well-small">
            Experiment not found.
        </div>
    {% endif %}
{% endblock %}