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

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

{% block dagster_breadcrumbs %}
&rsaquo; <a href="{% url 'admin:django_dagster_dagsterjob_changelist' %}">{% trans 'Jobs' %}</a>
&rsaquo; {{ job.name }}
{% endblock %}

{% block dagster_content %}
<div class="submit-row">
    {% if can_trigger %}
    <form method="get" action="{% url 'admin:django_dagster_dagsterjob_trigger' job.name %}" style="display:inline;">
        <input type="submit" value="{% trans 'Trigger New Run' %}">
    </form>
    {% endif %}
    <form method="get" action="{% url 'admin:django_dagster_dagsterrun_changelist' %}" style="display:inline;">
        <input type="hidden" name="job" value="{{ job.name }}">
        <input type="submit" value="{% trans 'View Runs' %}">
    </form>
    {% if dagster_job_ui_url %}
    <form method="get" action="{{ dagster_job_ui_url }}" target="_blank" style="display:inline;">
        <input type="submit" value="{% trans 'View in Dagster UI ↗' %}">
    </form>
    {% endif %}
</div>

<fieldset class="module aligned">
    <h2>{% trans 'Job Details' %}</h2>
    <div class="form-row">
        <div>
            <label>{% trans 'Name:' %}</label>
            <div class="readonly">{{ job.name }}{% if dagster_job_ui_url %} <a href="{{ dagster_job_ui_url }}" target="_blank" rel="noopener" title="{% trans 'View in Dagster UI' %}" style="opacity:.5;text-decoration:none;font-size:11px;">&#x2197;</a>{% endif %}</div>
        </div>
    </div>
    <div class="form-row">
        <div>
            <label>{% trans 'Description:' %}</label>
            <div class="readonly">{{ job.description|default:"—" }}</div>
        </div>
    </div>
    <div class="form-row">
        <div>
            <label>{% trans 'Repository:' %}</label>
            <div class="readonly">{{ job.repository }}{% if dagster_ui_locations_url %} <a href="{{ dagster_ui_locations_url }}" target="_blank" rel="noopener" title="{% trans 'Code locations in Dagster UI' %}" style="opacity:.5;text-decoration:none;font-size:11px;">&#x2197;</a>{% endif %}</div>
        </div>
    </div>
    <div class="form-row">
        <div>
            <label>{% trans 'Location:' %}</label>
            <div class="readonly">{{ job.location }}{% if dagster_location_ui_url %} <a href="{{ dagster_location_ui_url }}" target="_blank" rel="noopener" title="{% trans 'View code location in Dagster UI' %}" style="opacity:.5;text-decoration:none;font-size:11px;">&#x2197;</a>{% endif %}</div>
        </div>
    </div>
</fieldset>

{% if recent_runs %}
<div class="inline-related tabular">
<fieldset class="module">
    <h2>{% trans 'Recent Runs' %}</h2>
    <table>
        <thead>
            <tr>
                <th>{% trans 'Run ID' %}</th>
                <th>{% trans 'Status' %}</th>
                <th>{% trans 'Started' %}</th>
                <th>{% trans 'Ended' %}</th>
                {% if dagster_url %}
                <th>{% trans 'Dagster UI' %}</th>
                {% endif %}
            </tr>
        </thead>
        <tbody>
            {% for run in recent_runs %}
            <tr>
                <td><a href="{% url 'admin:django_dagster_dagsterrun_change' run.runId %}">{{ run.runId }}</a></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>
</fieldset>
</div>
{% endif %}

{% endblock %}
