{% extends "base.html" %}
{% load filters %}
{% block title %} | Grouping overview{% endblock %}

{% block main %}
        <div class="page-header">
            <div class="container">
                <div class="row">
                    <div class="col-sm-6">
                        <h1 class="smaller"><a href="{% url 'admin:project_overview' grouping.project.id %}">{{grouping.project.name}}</a></h1>
                        <a href="{% url 'admin:project_overview' grouping.project.id %}"><span class="glyphicon glyphicon-arrow-left"></span> Project home page</a>
                    </div>
                    <ul class="header-nav">
                        <li><a href="{% url 'admin:category_list' grouping.project.id %}">Categories <span class="badge">{{ grouping.project.categories.count }}</span></a></li>
                        <li class="active"><a href="{% url 'admin:grouping_list' grouping.project.id %}">Data groupings <span class="badge">{{ grouping.project.groupings.count }}</span></a></li>
                        <li><a href="{% url 'admin:usergroup_list' grouping.project.id %}">User groups <span class="badge">{{ grouping.project.usergroups.count }}</span></a></li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
            {% include 'snippets/messages.html' %}

            <div class="row">
                <div class="col-sm-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h6 class="item-info">Data grouping</h6>
                            <h3>{{ grouping.name }}</h3>
                            {% if grouping.description %}<p>{{ grouping.description|linebreaksbr }}</p>{% endif %}
                        </div>
                        <div class="list-group">
                            <a href="{% url 'admin:grouping_overview' grouping.project.id grouping.id %}" class="list-group-item active">Filters</a>
                            <a href="{% url 'admin:grouping_permissions' grouping.project.id grouping.id %}" class="list-group-item">Permissions</a>
                            <a href="{% url 'admin:grouping_settings' grouping.project.id grouping.id %}" class="list-group-item">Settings</a>
                        </div>
                    </div>
                </div>
                <div class="col-sm-8">
                    <h3 class="header">
                        Filters
                        {% if grouping.rules.all %}
                            <a href="{% url 'admin:rule_create' grouping.project.id grouping.id %}" class="btn btn-success btn-sm pull-right"><span class="glyphicon glyphicon-plus"></span> Create new filter</a>
                        {% endif %}
                    </h3>
                    {% for filter in grouping.rules.all %}
                    {% if forloop.first %}
                    <ul class="list-unstyled overview-list">
                    {% endif %}

                    <li>

                        <h4><a href="{% url 'admin:rule_settings' grouping.project.id grouping.id filter.id %}">Contributions of type <strong>{{ filter.category.name }}</strong></a>{% if filter.constraints or filter.min_date or filter.max_date %} where {% endif %}</h4>
                        <ul>
                            {% filters filter %}
                        </ul>
                    </li>

                    {% if forloop.last %}
                    </ul>
                    {% endif %}
                    {% empty %}
                        <div class="well empty-list">
                            <p class="lead">We couldn't find any filters for this data grouping.</p>
                            <p>You need to create at least one filter to define the subset of contributions of this project that will be available in this grouping.</p>
                            <p>You can define an arbitrary number of filters; in that case a contribution must match at least one of the filters to be available in this grouping.</p>
                            {% if grouping.project.categories.all %}
                                <a href="{% url 'admin:rule_create' grouping.project.id grouping.id %}" class="btn btn-success btn-lg">Create new filter</a>
                            {% endif %}
                        </div>
                        {% if not grouping.project.categories.all %}
                        <div class="alert alert-info">
                            <p>However, before you can add a filter to the data grouping, you need to create at least one category.</p>
                            <p><a href="{% url 'admin:category_create' grouping.project.id %}" class="btn btn-success">Create new category</a></p>
                        </div>
                        {% endif %}
                    {% endfor %}
                </div>
            </div>
        </div>
{% endblock %}

{% block libraries %}

{% endblock %}
