{# Source code of the Ubuntu-it website
 # Copyright (C) 2018  Pietro Albini <pietroalbini@ubuntu.com>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published
 # by the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; witout even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU Affero General Public License for more details.
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #}

{% macro render_actions(actions, own=False) %}
    <div class="table">
        <table>
            <tr>
                <th></th>
                {% if not own %}
                    <th>Nome utente</th>
                {% endif %}
                <th>Data e ora</th>
                {% if not own %}
                    <th>Indirizzo IP</th>
                {% endif %}
            </tr>
            {% for action in actions.actions %}
            <tr>
                <td>{{ action.message|safe }}</td>
                {% if not own %}
                    <td>{{ action.nickname }}</td>
                {% endif %}
                <td>{{ action["date"]|format_timestamp }}</td>
                {% if not own %}
                    <td>
                        {% if (g.auth_name == action.nickname and permission("auth.sessions.own")) or permission("auth.sessions.manage") %}
                            <a href="{{ url_for("auth.sessions_show", id=action.session) }}">
                                {{ action.ip }}
                            </a>
                        {% else %}
                            {{ action.ip }}
                        {% endif %}
                    </td>
                {% endif %}
            </tr>
            {% endfor %}
        </table>
    </div>
    <p class="text-center">
        {% if actions.current_page %}
            {% if actions.has_prev %}
                <a href="{{ url_for(request.endpoint, page=actions.current_page - 1) }}">
                    Pagina precedente
                </a>
                -
            {% endif %}
            <b>Pagina {{ actions.current_page }}</b>
            {% if actions.has_next %}
                -
                <a href="{{ url_for(request.endpoint, page=actions.current_page + 1) }}">
                    Pagina successiva
                </a>
            {% endif %}
        {% endif %}
    </p>
{% endmacro %}
