{% extends "web/_base.html" %}
{% block title %}Work request{% endblock %}
{% block content %}
    <div class="btn-group-vertical float-end"
         role="toolbar"
         aria-label="Work request 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">Retry</button>
            </form>
        {% endif %}
    </div>
    {% 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>
            Artifacts:
            {% if artifacts %}
                <ul>
                    {% for artifact in artifacts %}
                        <li>
                            Id: <a href="{% url "artifacts:detail" artifact_id=artifact.id %}">{{ artifact.id }}</a>
                            (<a href="{% url "artifacts:detail" artifact_id=artifact.id %}?archive=tar.gz">download</a>)
                            Category: {{ artifact.category }}
                        </li>
                    {% endfor %}
                </ul>
            {% elif work_request.status == "completed" %}
                expired
            {% endif %}
        </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 %}
