{% extends 'admin.html' %}
{% from 'include/datatables.html' import datatables %}
{% from 'include/session.html' import browser, os %}
{% from 'include/modal_dialog.html' import modal_dialog, button_confirm, modal_confirm %}
{% set admin_nav_active="session" %}
{% block title %}
  {% trans %}Active Sessions{% endtrans %}
{% endblock %}
{% block content %}
  <p>
    {% trans %}This is a list of devices that are logged into this application. It may include authenticated and unauthenticated users. You may revoke any sessions that you do not recognize except your current session.{% endtrans %}
  </p>
  {% set filter_buttons = [
  (_('Authenticated'), 3, 1),
  (_('Anonymous'), 3, 0),
  ] %}
  {% call() datatables(_('Repository list'), filter_buttons=filter_buttons) %}
    <thead>
      <tr>
        <th scope="col">{% trans %}Device{% endtrans %}</th>
        <th scope="col">{% trans %}IP Address{% endtrans %}</th>
        <th scope="col">{% trans %}User{% endtrans %}</th>
        <th scope="col" data-visible="false">{% trans %}Authenticated{% endtrans %}</th>
        <th scope="col">{% trans %}Last accessed{% endtrans %}</th>
        <th scope="col">{% trans %}Signed in{% endtrans %}</th>
        <th scope="col">{% trans %}Expiration Time{% endtrans %}</th>
        <th scope="col" data-sortable="false">{% trans %}Actions{% endtrans %}</th>
      </tr>
    </thead>
    <tbody>
      {% for session in active_sessions %}
        <tr>
          <td>
            <span class="list-group-item-heading" title="{{ session.user_agent }}">
              <strong>{{ browser(session.user_agent) }}</strong>
              {% trans %}running on{% endtrans %}
              <strong>{{ os(session.user_agent)}}</strong>
              {% if session.current %}
                <span class="badge badge-success">{% trans %}current session{% endtrans %}</span>
              {% endif %}
              {% if session.login_persistent %}
                <span class="badge badge-info">{% trans %}persistent{% endtrans %}</span>
              {% endif %}
            </span>
          </td>
          <td>{{ session.ip_address }}</td>
          <td>
            {% if session.username %}{{ session.username }}{% endif %}
          </td>
          <td data-search="{{ 1 if session.username else 0 }}">{{ _('Yes') if session.username else _('No') }}</td>
          <td data-order="{{ session.access_time }}">
            <time datetime="{{ session.access_time }}">{{ session.access_time | lastupdated }}</time>
          </td>
          <td data-order="{{ session.login_time }}">
            <time datetime="{{ session.login_time }}">{{ session.login_time | lastupdated }}</time>
          </td>
          <td data-order="{{ session.expiration_time }}">
            <time class="js-datetime" datetime="{{ session.expiration_time }}">{{ session.expiration_time }}</time>
          </td>
          <td>
            {% if not session.current %}
              {{ button_confirm(label=_('Revoke'), target="#delete-session-modal", action="delete", number=session.number) }}
            {% endif %}
          </td>
        </tr>
      {% endfor %}
    </tbody>
  {% endcall %}
  {{ modal_confirm(
  id='delete-session-modal',
  title=_('Revoke Session'),
  message=_("Are you sure? The device will be signed out from the application."),
  fields=['action', 'number'],
  submit=_('Revoke')) }}
{% endblock %}
