{% extends "layouts/content.html" %}
{% load i18n %}


{% block content %}
<h2>Hi {% firstof user.first_name user.username %}</h2>
<div class="row">
  <div class="col-md-6">
    <h4 class="modal-header">Personal information</h4>
    <dl class="dl-horizontal">
      <dt>Full name</dt>
      <dd>{{ user.get_full_name|default:"??" }}</dd>
      <dt>Username</dt>
      <dd>{{ user.username }}</dd>
      <dt>Email</dt>
      <dd>{{ user.email|default:"??" }}</dd>
      <dt>Joined</dt>
      <dd><span title="{{ user.date_joined }}">
          {{user.date_joined|timesince }} ago</span></dd>
      <dt>Password</dt>
      <dd><a href="{% url 'password_change' %}"><span class="glyphicon glyphicon-lock"></span> Update</a></dd>
      <dt>IRC settings</dt>
      <dd>Server: {{ user.extendeduser.irc_server|default:"None" }}; Handle: {{ user.extendeduser.irc_handle|default:"None" }};<a data-toggle="modal" href="#irc_modal"> Update</a></dd>
    </dl>
  </div>

  <!-- Modal HTML -->
  <div id="irc_modal" class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Update IRC settings</h4>
        </div>
        <form id="irc_form" method="post" action="{% url 'lava.update_irc_settings' %}">
	  {% csrf_token %}
        <div class="modal-body well">
	  <div id="irc_errors" class="errorlist" style="color: red;"></div>
	    {{ irc_form.as_p }}
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <input class="btn btn-primary" type="submit" value="Save" />
        </div>
        </form>

      </div>
    </div>
  </div>

  <div class="col-md-6">
    <h4 class="modal-header">Groups</h4>
  {% with groups=user.groups.all %}
    {% if groups %}
    <p>You are member of the following LAVA groups:</p>
    <div class="panel-group" id="accordion">
    {% for group in groups %}
      {% with user_set=group.user_set.all %}
        {% with users_count=user_set|length %}
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4 class="panel-title">
            {% if users_count > 1 %}
              <a data-toggle="collapse" data-parent="#accordion" href="#collapse-{{ forloop.counter }}">{{ group.name }} <span class="badge pull-right">{{ users_count|add:"-1" }}</span></a>
            {% else %}
              {{ group.name }} <span class="badge pull-right">0</span>
            {% endif %}
          </h4>
        </div>
        {% if users_count > 1 %}
        <div id="collapse-{{ forloop.counter }}" class="panel-collapse collapse">
          <div class="panel-body">
            <ul>
            {% for group_user in user_set|dictsort:"first_name"|dictsort:"last_name" %}
              {% if group_user != user %}<li>{{ group_user.get_full_name|default:group_user.username }}</li>{% endif %}
            {% endfor %}
            </ul>
          </div>
        </div>
        {% endif %}
      </div>
        {% endwith %}
      {% endwith %}
    {% endfor %}
    </div>
    {% else %}
    <p><i>You are not member of any group.</i></p>
    {% endif %}
  {% endwith %}
    </ul>
  </div>
</div>
<div class="row">
  <div class="col-md-6">
    <h4 class="modal-header">Personal reports</h4>
    <ul class="nav nav-pills nav-stacked">
      <li>
        <a href="{% url 'lava.scheduler.myjobs' %}"><span class="glyphicon glyphicon-tasks pull-right"></span> Your jobs</a>
      </li>
      <li>
        <a href="{% url 'lava.scheduler.mydevice_list' %}"><span class="glyphicon glyphicon-phone pull-right"></span> Your devices</a>
      </li>
      <li><a href="{% url 'lava.scheduler.mydevices_health_history_log' %}"><span
              class="glyphicon glyphicon-heart pull-right"></span> Your devices health</a></li>
    </div>
  </div>
</div>

{% endblock %}
