{% extends "::base.html.twig" %}
{% block title %}Administration -  Webservice Access Log{% endblock %}

{% block navigation %}{% include 'SsoBackendBundle:layout:navigation.html.twig' %}{% endblock %}

{% block body %}
    <script>
        function copyValueToClipboard(value) {
            var aux = document.createElement("input");
            aux.setAttribute("value", value);
            document.body.appendChild(aux);
            aux.select();
            try {
                document.execCommand("copy");
                alert('Value copied to clipboard.');
            } catch (e) {
                alert('Error while copying value ' + value + ' to clipboard.');
            }
            document.body.removeChild(aux);
        }

        $(function () {
            $(".tt").tooltip();
        });
    </script>

    <div style="font-size: 20px;margin-bottom: 20px;" class="pull-right">
        <span class="label label-success label-as-badge">count: {{ pagination.getTotalItemCount }}</span>
    </div>

    <div style="margin-top: 15px;">
        {{ form_start(accessLogDeleteForm) }}
        {{ form_rest(accessLogDeleteForm) }}
        <button class="btn btn-xs btn-danger" type="submit">Delete log</button>
        {{ form_end(accessLogDeleteForm) }}
    </div>

    <table class="table table-striped table-bordered table-condensed">
        <thead>
        <tr>
            <th {% if pagination.isSorted('a.username') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'username', 'a.username') }}</th>
            <th {% if pagination.isSorted('a.token') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'token', 'a.token') }}</th>
            <th>Services</th>
            <th {% if pagination.isSorted('a.createdAt') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'createdAt', 'a.createdAt') }}</th>
            <th {% if pagination.isSorted('a.updatedAt') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'updatedAt', 'a.updatedAt') }}</th>
        </tr>
        </thead>
        <tbody>
        {% for entity in pagination %}
            <tr>
                <td>{{ entity.username }}<!-- ID {{ entity.id }} --></td>
                {% if entity.token %}
                    <td class="infinitely-tooltip">
                        <span class="cutstring">
                            <a class="tt" style="cursor: copy" data-toggle="tooltip" data-placement="top"
                               title="Token: {{ entity.token|e }}"
                               onclick="copyValueToClipboard('{{ entity.token }}'); return false;">{{ entity.token }}</a>
                        </span>
                    </td>
                {% else %}
                    <td></td>
                {% endif %}
                <td>
                    {% for service in entity.services %}
                        {{ service }}<br/>
                    {% endfor %}
                </td>
                <td>{% if entity.createdAt %}{{ entity.createdAt|date('Y-m-d H:i:s') }}{% endif %}</td>
                <td>{% if entity.updatedAt %}{{ entity.updatedAt|date('Y-m-d H:i:s') }}{% endif %}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <div class="navigation">
        {{ knp_pagination_render(pagination) }}
    </div>

    <style>
        th.sorted > a.desc:before {
            content: "\2191";
            padding-right: 3px;
            margin-top: -5px;
            font-size: 18px;
            color: #000;
            text-decoration: none;
            font-weight: bold;
        }

        th.sorted > a.asc:before {
            content: "\2193";
            padding-right: 3px;
            margin-top: -5px;
            font-size: 18px;
            color: #000;
            text-decoration: none;
            font-weight: bold;
        }
    </style>
{% endblock %}