{% extends "django_dagster/base.html" %}
{% load i18n %}

{% block content_title %}<h1>{{ title }}</h1>{% endblock %}

{% block dagster_breadcrumbs %}
&rsaquo; {% trans 'Runs' %}
{% endblock %}

{% block dagster_content %}
<div id="changelist" class="filtered">
<div class="changelist-form-container">

    <search id="changelist-filter">
        <h2>{% trans 'Filter' %}</h2>
        <details data-filter-title="{% trans 'job' %}" open>
            <summary>
                {% trans 'By job' %}
            </summary>
            <ul>
                <li{% if not current_job %} class="selected"{% endif %}>
                    <a href="?{% if current_status %}status={{ current_status }}{% endif %}">{% trans 'All' %}</a>
                </li>
                {% if jobs %}
                    {% for job in jobs %}
                    <li{% if job.name == current_job %} class="selected"{% endif %}>
                        <a href="?job={{ job.name }}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{{ job.name }}</a>
                    </li>
                    {% endfor %}
                {% endif %}
            </ul>
        </details>
        <details data-filter-title="{% trans 'status' %}" open>
            <summary>
                {% trans 'By status' %}
            </summary>
            <ul>
                <li{% if not current_status %} class="selected"{% endif %}>
                    <a href="?{% if current_job %}job={{ current_job }}{% endif %}">{% trans 'All' %}</a>
                </li>
                {% for s in statuses %}
                <li{% if s == current_status %} class="selected"{% endif %}>
                    <a href="?status={{ s }}{% if current_job %}&amp;job={{ current_job }}{% endif %}">{{ s }}</a>
                </li>
                {% endfor %}
            </ul>
        </details>
    </search>

    <div>
{% if runs is not None %}
    {% if runs %}
    <div class="results">
    <table id="result_list">
        <thead>
            <tr>
                {% if current_sort == 'run_id' %}
                <th scope="col" class="sorted ascending column-runId">
                    <div class="sortoptions">
                        <a href="?o=-run_id{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle ascending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=-run_id{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Run ID' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% elif current_sort == '-run_id' %}
                <th scope="col" class="sorted descending column-runId">
                    <div class="sortoptions">
                        <a href="?o=run_id{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle descending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=run_id{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Run ID' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% else %}
                <th scope="col" class="sortable column-runId">
                    <div class="text"><a role="button" href="?o=run_id{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Run ID' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% endif %}

                {% if current_sort == 'job' %}
                <th scope="col" class="sorted ascending column-jobName">
                    <div class="sortoptions">
                        <a href="?o=-job{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle ascending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=-job{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Job' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% elif current_sort == '-job' %}
                <th scope="col" class="sorted descending column-jobName">
                    <div class="sortoptions">
                        <a href="?o=job{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle descending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=job{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Job' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% else %}
                <th scope="col" class="sortable column-jobName">
                    <div class="text"><a role="button" href="?o=job{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Job' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% endif %}

                {% if current_sort == 'status' %}
                <th scope="col" class="sorted ascending column-status">
                    <div class="sortoptions">
                        <a href="?o=-status{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle ascending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=-status{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Status' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% elif current_sort == '-status' %}
                <th scope="col" class="sorted descending column-status">
                    <div class="sortoptions">
                        <a href="?o=status{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle descending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=status{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Status' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% else %}
                <th scope="col" class="sortable column-status">
                    <div class="text"><a role="button" href="?o=status{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Status' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% endif %}

                {% if current_sort == 'started' %}
                <th scope="col" class="sorted ascending column-startTime">
                    <div class="sortoptions">
                        <a href="?o=-started{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle ascending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=-started{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Started' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% elif current_sort == '-started' %}
                <th scope="col" class="sorted descending column-startTime">
                    <div class="sortoptions">
                        <a href="?o=started{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle descending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=started{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Started' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% else %}
                <th scope="col" class="sortable column-startTime">
                    <div class="text"><a role="button" href="?o=started{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Started' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% endif %}

                {% if current_sort == 'ended' %}
                <th scope="col" class="sorted ascending column-endTime">
                    <div class="sortoptions">
                        <a href="?o=-ended{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle ascending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=-ended{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Ended' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% elif current_sort == '-ended' %}
                <th scope="col" class="sorted descending column-endTime">
                    <div class="sortoptions">
                        <a href="?o=ended{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}" class="toggle descending" role="button" title="{% trans 'Toggle sorting' %}"></a>
                    </div>
                    <div class="text"><a role="button" href="?o=ended{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Ended' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% else %}
                <th scope="col" class="sortable column-endTime">
                    <div class="text"><a role="button" href="?o=ended{% if current_job %}&amp;job={{ current_job }}{% endif %}{% if current_status %}&amp;status={{ current_status }}{% endif %}">{% trans 'Ended' %}</a></div>
                    <div class="clear"></div>
                </th>
                {% endif %}

                {% if dagster_url %}
                <th scope="col"><div class="text">{% trans 'Dagster UI' %}</div></th>
                {% endif %}
            </tr>
        </thead>
        <tbody>
            {% for run in runs %}
            <tr>
                <th scope="row">
                    <a href="{% url 'admin:django_dagster_dagsterrun_change' run.runId %}">{{ run.runId }}</a>
                </th>
                <td>{{ run.jobName }}</td>
                <td><span class="status-badge status-{{ run.status }}">{{ run.status }}</span></td>
                <td>{{ run.startTime|default:"—" }}</td>
                <td>{{ run.endTime|default:"—" }}</td>
                {% if dagster_url %}
                <td>{% if run.dagster_ui_url %}<a href="{{ run.dagster_ui_url }}" target="_blank" rel="noopener" title="{% trans 'View in Dagster UI' %}">&#x2197;</a>{% endif %}</td>
                {% endif %}
            </tr>
            {% endfor %}
        </tbody>
    </table>
    </div>
    {% else %}
    <p>{% trans 'No runs found' %}{% if current_job %} {% trans 'for job' %} "{{ current_job }}"{% endif %}{% if current_status %} {% trans 'with status' %} "{{ current_status }}"{% endif %}.</p>
    {% endif %}
{% endif %}
    </div>

</div>
</div>
{% endblock %}
