{% extends "admin_extra_buttons/action_page.html" %}
{% load power_query %}
{% block action-content %}
    <h2>Dataset is: {{ type }}</h2>
    <div class="scrollresults">
        {% if result %}
        {% if result.fields %}
            <table>
                <tr>{% for field in result.fields %}
                    <th>{{ field }}</th>{% endfor %}</tr>
                {% for obj in result.data %}
                    <tr>
                        {% for field in result.fields %}
                            <td>{{ obj|field:field }}</td>{% endfor %}
                    </tr>{% endfor %}
            </table>
        {% elif type == "list" %}
            <table>
                <tr>
                    <th>Records</th>
                </tr>
                {% for row in result %}
                    <tr><td>{{ row }}</td></tr>{% endfor %}
            </table>
        {% elif type == "tuple" %}
            <table>
                <tr>
                    <th>Records</th>
                </tr>
                {% for row in result %}
                    <tr>
                        <td>{{row}}</td>
                    </tr>
                {% endfor %}
            </table>
        {% else %}
            {{ result }}
        {% endif %}
    {% elif queryset %}
        <table>
            <tr>
                <th>id</th>
                <th>record</th>
            </tr>
            {% for row in queryset %}
                <tr><td>{{ row.pk }}</td><td>{{ row }}</td></tr>{% endfor %}
        </table>
    {% elif dataset %}
        <table>
            <tr>{% for fname in dataset.headers %}
                <th>{{ fname }}</th>{% endfor %}</tr>
            {% for row in dataset %}
                <tr>
                    {% for col in row %}
                        <td>{{ col }}</td>{% endfor %}
                </tr>{% endfor %}
        </table>
<style>
div.scrollresults {
  overflow: auto;
  white-space: nowrap;
}
</style>
    {% endif %}
    </div>
{% endblock action-content %}
