{% extends "web/_base_rightbar.html" %}
{% block title %}Work request{% endblock %}
{% block quick-actions %}
    {% if user.is_authenticated and work_request.can_retry %}
        <form method="post"
              action="{% url 'work_requests:retry' pk=work_request.id %}"
              id="form-retry">
            {% csrf_token %}
            <button type="submit"
                    class="btn btn-primary bi bi-arrow-repeat"
                    title="Retry"></button>
        </form>
    {% endif %}
{% endblock %}
{% block content-right %}
    <h5>Output</h5>
    {% if artifacts %}
        <div id="output-artifacts">{% include "web/_artifact-list.html" with artifacts=artifacts only %}</div>
    {% else %}
        No artifacts produced
    {% endif %}
{% endblock %}
{% block content %}
    {% if work_request.is_part_of_workflow %}
        <h1>Workflow information</h1>
        <ul>
            {% with work_request_root=work_request.get_workflow_root %}
                {% if work_request_root != work_request %}
                    <li>
                        Root: <a href="{% url "work_requests:detail" pk=work_request_root.id %}">{{ work_request_root.workflow_display_name }}</a>
                    </li>
                {% endif %}
            {% endwith %}
            {% if work_request.parent %}
                <li>
                    Parent: <a href="{% url "work_requests:detail" pk=work_request.parent.id %}">{{ work_request.parent.workflow_display_name }}</a>
                </li>
            {% endif %}
            {% if work_request.children.all %}
                <li>{% include "web/_work_request-descendants.html" %}</li>
            {% endif %}
        </ul>
    {% endif %}
    <h1>Work request information</h1>
    {% if specialized_view_path %}
        <p>
            <a href="{{ specialized_view_path }}">{{ work_request.task_name }} view</a>
        </p>
    {% endif %}
    <ul id="work-request-information">
        <li>Id: {{ work_request.id }}</li>
        <li>
            Status:
            {% include "web/_work_request-status.html" with status=work_request.status only %}
        </li>
        <li>
            Result:
            {% include "web/_work_request-result.html" with result=work_request.result only %}
        </li>
        {% if work_request.superseded %}
            <li id="link-superseded">
                Superseded by: <a href="{% url "work_requests:detail" pk=work_request.superseded.id %}">{{ work_request.superseded }}</a>
            </li>
        {% endif %}
        {% if work_request.supersedes %}
            <li id="link-supersedes">
                Supersedes: <a href="{% url "work_requests:detail" pk=work_request.supersedes.id %}">{{ work_request.supersedes }}</a>
            </li>
        {% endif %}
        <li>
            Worker:
            {% if work_request.worker %}
                {{ work_request.worker.name }}
            {% else %}
                N/A
            {% endif %}
        </li>
        <li>Workspace: {{ work_request.workspace.name }}</li>
        <li>Task type: {{ work_request.task_type }}</li>
        <li>Task name: {{ work_request.task_name }}</li>
        <li>Created by: {{ work_request.created_by }}</li>
        <li>Created at: {{ work_request.created_at }}</li>
        <li>Started at: {{ work_request.started_at|default_if_none:"N/A" }}</li>
        <li>
            Duration:
            {% if work_request.duration != None %}
                {{ work_request.duration|floatformat:0 }} seconds
            {% else %}
                N/A
            {% endif %}
        </li>
        <li>
            Task data:
            <pre><code>{{ task_data }}</code></pre>
        </li>
        {% if validation_error %}
            <li>
                Validation error:
                <pre><code>{{ validation_error }}</code></pre>
            </li>
        {% endif %}
    </ul>
{% endblock %}
