{% extends "list_requests.html" %}
{% from "macros.html" import clipboard_button %}

{% block content %}
<div class="row">
  <div class="col-md-10 col-md-offset-1">
    <table class="table">
      <tr>
        <th>Division</th>
        <th>Permissions</th>
      </tr>
      {% for grouper, grouped in current_user.permissions|groupby('division.name') %}
      <tr>
        <td>{{ grouper }}</td>
        {% with grouped_permissions = grouped|map(attribute='permission')|groupby('value') %}
        <td>{{ grouped_permissions|map('last')|map('first')|map(attribute='description')|join(', ') }}</td>
        {% endwith %}
      </tr>
      {% endfor %}
    </table>
  </div>
  <div class="col-md-10 col-md-offset-1">
    <table id="apikeys" class="table table-condensed">
        <tr>
          <th>Key</th>
          <th>Created</th>
          <th>Remove</th>
        </tr>
        {% for key in current_user.api_keys %}
        <tr>
          <td class="key-button">
            {{ clipboard_button(key.hex_key, "bottom", "") }}
          </td>
          <td>{{ key.timestamp.strftime('%d %b %Y @ %H:%M') }}</td>
          <td>
            <form class="" method="post">
              {{ key_form.csrf_token }}
              {{ key_form.action(value='delete') }}
              {{ key_form.key_id(value=key.id) }}
              <button type="submit" class="close">&times;</button>
            </form>
          </td>
        </tr>
        {% endfor %}
      <tr>
        <td colspan="2">
        </td>
        <td class="">
          <form class="pull-right" method="post">
            {{ key_form.csrf_token }}
            {{ key_form.action(value='add') }}
            <button type="submit" class="btn btn-sm btn-info" id="createKey" data-toggle="tooltip" data-placement="bottom" title="This creates a key for this app's API, not the EVE API.">Create API Key</button>
          </form>
        </td>
      </tr>
    </table>
  </div>
</div>
{{ super() }}
{% endblock content %}
