{% extends "bootstrap/base.html" %}

{% import "bootstrap/wtf.html" as wtf %}
{% import "bootstrap/fixes.html" as fixes %}
{% import "bootstrap/utils.html" as util %}

{% block scripts %}
    {{ super() }}

    <script type="text/javascript">
        // Initializes popover
        $('.warning-filter').on('click', function () {
            $(this).toggleClass("btn-primary");
            $(this).toggleClass("btn-default");
            const cls = $(this).data('target');
            $('.' + cls).toggle();
        });
    </script>
{% endblock %}

{% block title %}{{ network }} Errors and Warnings{% endblock %}

{% block content %}
    <div class="container hidden-print">
        {{ util.flashed_messages(dismissible=True, container=False) }}

        <ol class="breadcrumb">
            <li><a href="{{ url_for('ui.home') }}">Catalog</a></li>
            <li><a href="{{ url_for('ui.view_networks') }}">Networks</a></li>
            <li><a href="{{ url_for('ui.view_network', network_id=network.id) }}">{{ network }}</a></li>
            <li class="active">Errors and Warnings</li>
        </ol>


        <div class="page-header">
            <h1>{{ graph }} Warnings ({{ graph.warnings|length }})</h1>
        </div>

        <div class="panel panel-default ">
            <div class="panel-body">
                <ul class="list-inline">
                    {% for warning_type, count in error_count.items()|sort %}
                        <li class="list-inline-item">
                            <a class="btn btn-primary warning-filter" data-target="{{ warning_type }}">
                                {{ warning_type }} ({{ count }})
                            </a>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>

    <table class="table table-hover table-responsive table-striped">
        <thead>
        <tr>
            <th>Line</th>
            <th>BEL</th>
            <th>Message</th>
            {% if current_user.is_beta_tester %}
                <th>Annotations</th>
            {% endif %}
        </tr>
        </thead>
        <tbody id="myTable">
        {% for number, line, exc, context in graph.warnings %}
            <tr class="{{ exc.__class__.__name__ }}">
                <td>{{ number }}</td>
                <td><code>{{ line }}</code></td>
                <td>{{ exc }}</td>
                {% if current_user.is_beta_tester %}
                    <td>
                        <dl class="dl-horizontal">
                            {% for k,v in context['annotations'].items()|sort %}
                                <dt>{{ k }}</dt>

                                <dd>
                                    {% if v is string %}
                                        {{ v }}
                                    {% else %}
                                        <ul>
                                            {% for vi in v %}
                                                <li>{{ vi }}</li>
                                            {% endfor %}
                                        </ul>
                                    {% endif %}
                                </dd>
                            {% endfor %}
                        </dl>
                    </td>
                {% endif %}
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}