{% extends '@CadolesCore/base.html.twig' %}

{% block pagewrapper %}
    <h1 class="page-header">Statistiques {{ group.label }}</h1>
    <a class="btn btn-default" href={{ path('cadoles_core_'~access~'_group') }}>Fermer</a>
    <br><br>

    <div class="panel panel-primary">
        <div class="panel-heading">
            <i class="fa fa-table fa-fw"></i> Compteur de visites journalière
        </div>

        <div class="panel-body">
        <div id="groupcptvisite"></div>
        </div>
    </div>

    <div class="row">
        <div class="col col-md-6">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <i class="fa fa-table fa-fw"></i> Evolution du nombre de message dans les tchat
                </div>

                <div class="panel-body">
                <div id="groupcptmessage"></div>
                </div>
            </div>
        </div>

        <div class="col col-md-6">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <i class="fa fa-table fa-fw"></i> Evolution du nombre d'articles de blog
                </div>

                <div class="panel-body">
                <div id="groupcptblogarticle"></div>
                </div>
            </div>
        </div>

        <div class="col col-md-6">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <i class="fa fa-table fa-fw"></i> Evolution du nombre de tâches
                </div>

                <div class="panel-body">
                <div id="groupcptprojecttask"></div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block localjavascript %}
    $(document).ready(function() {
        groupcptvisite();
        groupcptmessage();
        groupcptblogarticle();
        groupcptprojecttask();

        $(window).resize(function() {
            window.groupcptvisite.redraw();
            window.groupcptmessage.redraw();
            window.groupcptblogarticle.redraw();
            window.groupcptprojecttask.redraw();
        });        
    });

    function groupcptvisite() {
        window.groupcptvisite = Morris.Area({
            element: 'groupcptvisite',
            data: [
                {% set before = 0 %}
                {% for date, cpt in groupcptvisite.value %}
                    {% set now = cpt - before %}
                    {% set before = cpt %}
                    { x: '{{ date }}', a: {{ now }} }{% if not loop.last %},{%endif%}
                {% endfor %}
            ],
            xkey: 'x',
            ykeys: ['a'],
            labels: ['Nombre de visites']
        });       
    }

    function groupcptmessage() {
        window.groupcptmessage = Morris.Area({
            element: 'groupcptmessage',
            data: [
                {% for date, cpt in groupcptmessage.value %}
                    { x: '{{ date }}', a: {{ cpt }} }{% if not loop.last %},{%endif%}
                {% endfor %}
            ],
            xkey: 'x',
            ykeys: ['a'],
            labels: ['Nombre total de messages tchat']
        });       
    }

    function groupcptblogarticle() {
        window.groupcptblogarticle = Morris.Area({
            element: 'groupcptblogarticle',
            data: [
                {% for date, cpt in groupcptblogarticle.value %}
                    { x: '{{ date }}', a: {{ cpt }} }{% if not loop.last %},{%endif%}
                {% endfor %}
            ],
            xkey: 'x',
            ykeys: ['a'],
            labels: ["Nombre total d'articles de blog"]
        });       
    }

    function groupcptprojecttask() {
        window.groupcptprojecttask = Morris.Area({
            element: 'groupcptprojecttask',
            data: [
                {% for date, cpt in groupcptprojecttask.value %}
                    { x: '{{ date }}', a: {{ cpt }} }{% if not loop.last %},{%endif%}
                {% endfor %}
            ],
            xkey: 'x',
            ykeys: ['a'],
            labels: ["Nombre total de tâches"]
        });       
    }
{% endblock %}
