{% extends "django_pev/base.html" %}
{% block content %}
<div class="row">
    <div class="card mb-4 mt-4">
        <div class="card-body">
            <div class="d-flex justify-content-between">
                <div>
                    <h4 class="card-title mb-0">Live Queries</h4>
                </div>
            </div>

            <div class="d-flex justify-content-between mt-4">
                <div>
                    <ul>
                        <li>
                            <b> Total queries: </b> {{ queries| length}}
                        </li>
                    </ul>
                </div>
            </div>

            <table  class="table">
                <thead>
                    <tr>
                    <th scope="col">PID</th>
                    <th scope="col">Database</th>
                    <th scope="col">User</th>
                    <th scope="col">Backend Type</th>
                    <th scope="col">State</th>
                    <th scope="col">Source</th>
                    <th scope="col">Duration</th>
                    <th scope="col">Waiting</th>
                    <th scope="col">Query</th>
                    <th scope="col">Started At</th>
                    <th scope="col">Duration ms</th>
                    </tr>
                </thead>
                <tbody>
                    {% for row in queries %}
                    <tr id="#{{row.name}}">
                        <td>{{ row.pid }}
                            {% if row.is_long_running%}
                            <span class="badge text-bg-warning">Long</span>
                            {% endif %}
                        </td>
                        <td>{{ row.database}}</td>
                        <td>{{ row.user}}</td>
                        <td>{{ row.backend_type}}</td>
                        <td>{{ row.state}}</td>
                        <td>{{ row.source}}</td>
                        <td>{{ row.duration}}</td>
                        <td>{{ row.waiting}}</td>
                        <td>{{ row.query }}</td>
                        <td>{{ row.started_at}}</td>
                        <td>{{ row.duration_ms}}</td>
                    </tr>
                    {% endfor%}
                </tbody>
            </table>

        </div>
        <div class="card-footer">
        </div>
    </div>
</div>
{% endblock %}