{% extends "base.html" %}
{% load projecttags %}

{% block title %}
    {{ block.super }} - Dashboard
{% endblock %}

{%block navigation_home %}hidden{% endblock %}

{% block content %}
<div class="page-header">
    <h1>Dashboard</h1>
    <h6>{{ username }}</h6>
</div>

<section>
    <h3>Open Assignments</h3>
    {% if not courses %}
        Seems like you don't have any courses configured. You should <a href="{% url 'courses' %}">change that</a>.
    {% else %}
        {% if assignments %}
            <table class="table">
                <thead>
                    <tr>
                        <th>Course</th>
                        <th>Assignment</th>
                        <th>Start</th>
                        <th>Deadline</th>
                        <th>Time Left</th>
                        <th>Action</th>
                    </tr>
                </thead>

                <tbody>
                    {% for assignment in assignments %}
                        <tr>
                            <td><a href="{{ assignment.course.homepage }}">{{ assignment.course }}</a></td>
                            <td><a href="{{ assignment.download }}">{{ assignment }}</a>
    			{% if assignment.attachment_test_validity and assignment.validity_script_download %}
    				<br/><a href="{% url 'download' assignment.pk 'validity_testscript' %}">(Validation script)</a>
    			{% endif %}
    			</td>
                            <td>{{ assignment.publish_at }}</td>
                            <td>{% if assignment.soft_deadline %}{{ assignment.soft_deadline }}{%else %}{{ assignment.hard_deadline }}{% endif %}</td>
                            <td>{% if assignment.soft_deadline %}{{ assignment.soft_deadline|timeuntil }}{%else %}{{ assignment.hard_deadline|timeuntil }}{% endif %}</td>
                            <td><a href="{% url 'new' assignment.pk %}" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> New Submission</a></td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% else %}
            Nothing at the moment.
        {% endif %}
    {% endif %}
</section>

<section>
    <h3>Active Submissions</h3>
    <table class="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Course</th>
                <th>Assignment</th>
                <th>Submitted by</th>
                <th>Authors</th>
                <th>Status</th>
                <th>Action</th>
            </tr>
        </thead>

        <tbody>
            {% for submission in authored %} 
                <tr {% if submission.passed or submission.failed %}style="font-style: italic"{%endif%}>
                    <td>{{ submission.pk }}</td>
                    <td><a href="{{ submission.assignment.course.homepage }}">{{ submission.assignment.course }}</a></td>
                    <td><a href="{{ submission.assignment.download }}">{{ submission.assignment }}</a></td>
                    <td>{{ submission.submitter.get_full_name }}</td>
                    <td>{{ submission.authors.all|join:"<br/>" }}</td>
                    <td>
                        <span class="{{ submission|state_label_css }}">{{ submission.state_for_students }}</span>
                    </td>
                    <td style="white-space: nowrap;">
                        <a href="{% url 'details' submission.pk %}" class="btn btn-default"><span class="glyphicon glyphicon-th-list"></span> Details</a>
                        {% if submission.can_reupload or submission.can_withdraw %}
                        {% endif %}
                        {% if submission.can_reupload %}
                            <p></p>
                            <a href="{% url 'update' submission.pk %}" class="btn btn-default"><span class="glyphicon glyphicon-upload"></span> Re-upload</a>
                        {% endif %}
                        {% if submission.can_withdraw %}
                            <p></p>
                            <a href="{% url 'withdraw' submission.pk %}" class="btn btn-default"><span class="glyphicon glyphicon-trash"></span> Withdraw</a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
</section>

<section>
    <h3>Archive</h3>
    <table class="table table-condensed">
        <thead>
            <tr>
                <th>ID</th>
                <th>Course</th>
                <th>Assignment</th>
                <th>Created</th>
                <th>Authors</th>
                <th>Status</th>
                <th></th>
            </tr>
        </thead>

        <tbody>
            {% for submission in archived %}
                <tr>
                    <td>{{ submission.pk }}</td>
                    <td><a href="{{ submission.assignment.course.homepage }}">{{ submission.assignment.course }}</a></td>
                    <td><a href="{{ submission.assignment.download }}">{{ submission.assignment }}</a></td>
                    <td>{{ submission.created }}</td>
                    <td>{{ submission.authors.all|join:"<br/>" }}</td>
                    <td>{{ submission.state_for_students }}</td>
                    <td><a href="{% url 'details' submission.pk %}">Details</a></td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
</section>

<section>
    <h3>Test Machines</h3>
    <ul class="list">
    {% for machine in machines %}
        <li><a href="{% url 'machine' machine.pk %}">Test machine {{ machine.pk }}</a></li>
    {% endfor %}
</ul>
</section>


{% endblock %}
