{% import 'linecharts.html' as linecharts %}

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Pypi statistics</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.1/Chart.bundle.js"></script>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        {% if form != none %}
        <link rel="stylesheet" type="text/css" href="{{ form.rooturl }}/style.css">
        <link rel="icon" href="{{ form.rooturl }}/favicon.png" />
        {% endif %}
    </head>
    <body>
        {% if errors %}
        <ul class="errors">
          {% for message in errors|sort %}
          <li>{{ message }}</li>
          {% endfor %}
        </ul>
        {% endif %}
        {% if form != none %}
            <form action="{{ form.rooturl }}" method="get">
                <span class="tooltip">Packages <span class="tooltiptext">Comma separated list of packages to monitor.</span></span>: <input type="text" name="pkg" value="{{ form.pkg }}">
                <span class="tooltip">Users <span class="tooltiptext">Comma separated list of users to monitor.</span></span>: <input type="text" name="user" value="{{ form.user }}">
                <span class="tooltip">Cells <span class="tooltiptext">Comma separated list of cells to display.</span></span>: <input type="text" name="col" value="{{ form.col }}">
                <input type="submit" value="Submit">
            </form> 
        {% endif %}


        {% if packages %}
        {{ linecharts.plot(packages.values()) }}

        <table class="badges">
            <thead><tr>
                {% for cell in config['cells'] -%}
                <td>
                  {% if cell in cells %}
                  {{ cells[cell].title }}
                  {% else %}
                  {{ cell }}
                  {% endif %}
                </td>
                {%- endfor %}
            </tr></thead>
            <tbody>
            {% for package in packages|sort -%}
                <tr style="background-color: {{ package |color(0.1, 0.8) }};">
                    {% for cell in config['cells'] -%}
                    <td>
                      {% if config['packages'][package][cell]['cell'] in cells %}
                        {{ cells[config['packages'][package][cell]['cell']](cell, package) }}
                        {% else %}
                        {{ cells["error"](cell, package) }}
                        {% endif %}
                    </td>
                    {%- endfor %}
                </tr>
            {%- endfor %}
            </tbody>
        </table>
        {% endif %}

        {% for package in packages|sort %}
            {{ linecharts.plot([packages[package]]) }}
        {% endfor %}

        <div class="footer">
          Generated using <a href="//framagit.org/spalax/pypimonitor">PypiMonitor</a> version {{ version }}.
        </div>
    </body>
</html>
