{% extends "web/_base.html" %}
{% load debusine %}
{% block title %}List of tokens{% endblock %}
{% block content %}
    <h1>List of tokens</h1>
    <p>
        Here you can generate and maintain the API tokens that are needed to
        <a href="https://freexian-team.pages.debian.net/debusine/howtos/set-up-debusine-client.html">set up debusine-client</a>
        to access this instance of Debusine.
    </p>
    <p>
        Here is an example <tt>~/.config/debusine/client/config.ini</tt> file you can use:
    </p>
    <pre id="example-config">
    [General]
    default-server = {{DEBUSINE_FQDN}}

    [server:{{DEBUSINE_FQDN}}]
    api-url = https://{{DEBUSINE_FQDN}}/api
    scope = {% if only_one_scope %}{{scopes.0}}{% else %}one-of-the-scopes-listed-below{% endif %}
    token = generated-token-goes-here
    </pre>
    {% if not only_one_scope %}
        <h2>Scopes</h2>
        <ul id="scope-list">
            {% for scope in scopes %}
                <li>
                    {% withscope scope %}
                        <a href="{% url 'scopes:detail' %}">{{ scope }}</a>
                    {% endwithscope %}
                </li>
            {% endfor %}
        </ul>
    {% endif %}
    <h2>Tokens</h2>
    {% if token_list %}
        <table class="table table-sm">
            <thead>
                <tr>
                    <th>Enabled</th>
                    <th>Created at</th>
                    <th>Comment</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for token in token_list %}
                    <tr>
                        <td>{% include "web/_check_icon.html" with value=token.enabled only %}</td>
                        <td>{{ token.created_at }}</td>
                        <td>{{ token.comment }}</td>
                        <td>
                            <a href="{% url "user:token-delete" pk=token.pk username=person.username %}">Delete</a>&nbsp;|&nbsp;<a href="{% url "user:token-edit" pk=token.pk username=person.username %}">Edit</a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="5">
                        <a class="btn btn-primary btn-sm"
                           type="button"
                           href="{% url "user:token-create" username=person.username %}">Create another token</a>
                    </td>
                </tr>
            </tfoot>
        </table>
    {% else %}
        <p>
            You do not currently have any tokens:
            <a href="{% url "user:token-create" username=person.username %}">create a new token</a>
            to be able to use debusine-client.
        </p>
    {% endif %}
{% endblock %}
