
{% load common_filters %}
<html>
    <head>
        <style>
            body {
                font-family: 'Arial';
            }
            h2, p {
                text-align: center;
            }
            table {
                border-collapse: collapse;
                border-spacing: 0;
            }
            td {
                border: solid #ddd 1px;
                padding: 5px;
            }
            .download {
                position: absolute;
                top: 10px;
                right: 20px;
            }
            .back {
                position: absolute;
                top: 10px;
                left: 20px;
            }
        </style>
    </head>
    <body>

    <div class="download">
        Download as CSV
        <a href="{% url 'omero_table' data.id 'csv' %}?limit={{ meta.rowCount }}">Whole Table</a> |
        <a href="{% url 'omero_table' data.id 'csv' %}?limit={{ meta.limit }}&offset={{ meta.offset }}&query={{ meta.query|urlencode }}">This View</a>
    </div>
    {% if meta.query != '*' %}
        <div class="back">
            <a href="{{ meta.url }}">< Remove query</a>
        </div>
    {% endif %}
    <h2>{{ data.name }}</h2>
    {% if example_column %}
        <p>
            To filter rows you can use a query based on named columns.
            For example, to filter for rows where <b>{{ example_column }}</b>
            is greater than <b>{{ example_min_value }}</b> add 
            <a href="{{ meta.url }}?query={{ example_column }}>{{ example_min_value }}">
                ?query={{ example_column }}>{{ example_min_value }}
            </a> to the URL. <br>
            For a more complex example, try
            <a href="{{ meta.url }}?query=({{ example_column }}>{{ example_min_value }})%26({{ example_column }}<{{ example_max_value }})">
                ?query=({{ example_column }}>{{ example_min_value }})&({{ example_column }}<{{ example_max_value }})
            </a>
        </p>
    {% endif %}
    <p>
        {% if meta.query == '*' %}
            Table rows: <b>{{ meta.rowCount }}</b>.
        {% else %}
            Query "<b>{{ meta.query }}</b>" returned
            <b>{{ meta.totalCount }}</b>/<b>{{ meta.rowCount }}</b> rows.
        {% endif %}

        <!-- Only show pagination if needed -->
        <br>
        {% if meta.prev or meta.next %}
            {% if meta.page %}
                Showing page <b>{{ meta.page }}</b> (<b>{{ data.rows | length }}</b> rows).
            {% else %}
                Pagination offset: <b>{{ meta.offset }}</b> limit: <b>{{ meta.limit }}</b>.
            {% endif %}
            {% if meta.prev %}
                <a href="{{ meta.prev }}">Prev</a>
            {% else %}
                Prev
            {% endif %}
            |
            {% if meta.next %}
                <a href="{{ meta.next }}">Next</a>
            {% else %}
                Next
            {% endif %}
        {% endif %}
    </p>
    <table>
        <tr>
        {% for col, col_type in data.columns|zip:data.column_types  %}
            <th title="{{col_type}}">{{ col }}</th>
        {% endfor %}
        </tr>

        {% for row in data.rows %}
        <tr>
            {% for col in row %}
                {% if image_column_index == forloop.counter0 %}
                <td><a target="_blank" href="{% url 'webindex' %}?show=image-{{ col }}">{{ col }}</a></td>
                {% elif well_column_index == forloop.counter0 %}
                <td><a target="_blank" href="{% url 'webindex' %}?show=well-{{ col }}">{{ col }}</a></td>
                {% else %}
                <td>{{ col }}</td>
                {% endif %}
            {% endfor %}
        </tr>
        {% endfor %}
    </body>
</html>
