{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% load leaflet_tags %}

{% block meta %}
{% leaflet_js %}
{% leaflet_css %}
{% endblock %}

{% block title %}Planned Session{% endblock %}

{% block main %}

{% if user.is_authenticated and psdict.id.1|is_session_manager:user %}
<p>
  <a href="/rowers/sessions/{{ psdict.id.1 }}/edit/user/{{ rower.user.id }}">
    Edit Session</a>
		/
	<a href="/rowers/sessions/{{ psdict.id.1 }}/maketemplate/?next={{ request.path|urlencode }}">Save to template</a>
</p>
{% endif %}
<h1>Session {{ psdict.name.1 }}</h1>

<ul class="main-content">
  <li class="grid_2">
    <table class="listtable shortpadded" width="95%">
      {% for attr in attrs %}
      {% for key,value in psdict.items %}
      {% if key == attr %}
      <tr>
        {% if key == 'comment' %}
        <td><b>{{ value.0 }}</b></td><td class="wrapwords">{{ value.1|linebreaks|urlshorten:"50" }}</td>
        {% else %}
        <td><b>{{ value.0 }}</b></td><td class="wrapwords">{{ value.1 }}</td>
        {% endif %}
      </tr>
      {% endif %}
      {% endfor %}
      {% endfor %}
    </table>
  </li>
  <li class="grid_2">
    {% if plannedsession.sessiontype == 'test' or plannedsession.sessiontype == 'coursetest' %}
    <h2>Ranking</h2>
    <table id="rankingtable" class="listtable shortpadded tablesorter" width="80%">
      <thead>
        <tr>
          <th>Nr</th>
          <th>Name</th>
          <th>Distance</th>
          <th>Time</th>
          <th>Date</th>
          <th>Type</th>
        </tr>
      </thead>
      <tbody>
        {% for result in ranking %}
        {% if result|lookup:'coursecompleted' %}
        <tr>
          <td>{{ forloop.counter }}</td>
          <td>{{ result|lookup:'name' }}</td>
          <td>{{ result|lookup:'distance' }}</td>
          <td>{{ result|lookup:'time'|deltatimeprint }}</td>
          <td>{{ result|lookup:'date'|date:"Y-m-d" }}</td>
          <td>{{ result|lookup:'type' }}</td>
        </tr>
        {% endif %}
        {% endfor %}
      </tbody>
    </table>
    {% endif %}
    <h1>Workouts attached</h1>
    <table class="listtable shortpadded" width="80%">
      <thead>
        <tr>
          <th>Date</th>
          <th>Name</th>
          <th>Distance</th>
          <th>Duration</th>
        </tr>
    </thead>
      <tbody>
        {% for workout in workouts %}
        <tr>
          <td> {{ workout.date|date:"Y-m-d" }} </td>
          <td>
            <a href="{% url 'workout_view' id=workout.id|encode %}">
              {{ workout.name }}
            </a>
          </td>
          <td> {{ workout.distance }}m</td>
          <td> {{ workout.duration |durationprint:"%H:%M:%S.%f" }} </td>
          <td>
            <a href="/rowers/sessions/{{ psdict.id.1 }}/detach/{{ workout.id|encode }}/">Detach</a>
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    <p>
      <a href="/rowers/sessions/manage/session/{{ psdict.id.1 }}/">
	Add, remove or change workouts for this session</a>
    </p>
  </li>
  <li class="grid_2">
    <h2>{{ rower.user.first_name }} {{ rower.user.last_name }}</h2>
    <p>Status: {{ status }}</p>
    <p>Percentage complete: {{ ratio }} </p>
  </li>
  <li class="grid_2">
    <h2>Stats</h2>
    <table class="listtable shortpadded" width="100%">
      <thead>
        <tr>
          <th>Name</th>
          <th>Minutes</th>
          <th>Meters</th>
          <th>rScore</th>
          <th>TRIMP</th>
          <th>Complete Date</th>
          <th>Status</th>
        </tr>
      </thead>
      <tbody>
        {% for id, value in results.items %}
        <tr>
          <td>{{ value|lookup:'first_name' }} {{ value|lookup:'last_name' }}</td>
          <td>{{ value|lookup:'duration' }}</td>
          <td>{{ value|lookup:'distance' }}</td>
          <td>{{ value|lookup:'rscore' }}</td>
          <td>{{ value|lookup:'trimp' }}</td>
          <td>{{ value|lookup:'completedate' }}</td>
          <td>{{ value|lookup:'status' }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    <p>
      <a href="/rowers/sessions/{{ psdict.id.1 }}/compare"
         title="Compare the workouts of all athletes who did this session">Compare Workouts</a>
    </p>
  </li>
  <li class="grid_2">
    <div id="comments">
      <h2>Comments ({{ comments|length }})</h2>
      {% for c in comments %}
      <p>
        <em>{{ c.user.first_name }} {{ c.user.last_name }}</em> - {{ c.created }}</br>
        <q>{{ c.comment }}</q>
      </p>
      {% endfor %}
      <p>
        <a href="/rowers/sessions/{{ psdict.id.1 }}/comments/">Add a comment</a>
      </p>
    </div>
  </li>
  {% if coursescript %}
  <li class="grid_2">
    <h2>Course</h2>
    {{ coursediv|safe }}

    {{ coursescript|safe }}
  </li>
  {% endif %}

</ul>


{% endblock %}

{% block sidebar %}
{% include 'menu_plan.html' %}
{% endblock %}

{% block scripts %}
<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.tablesorter.min.js"></script>

<script type="text/javascript" src="/static/admin/js/jquery.tablesorter.widgets.js"></script>
<script>
  $( document ).ready(function() {
  $("#rankingtable").tablesorter();
  });
</script>

{% endblock %}
