Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16642 | Rev 16845 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php

$routeOverview = $this->url('discovery-contacts/progress-by-day');
$routeDownload = $this->url('discovery-contacts/progress-by-day/download');


$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/fontawesome-free/css/all.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/daterangepicker/daterangepicker.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/daterangepicker/daterangepicker.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));


$this->inlineScript()->appendFile($this->basePath('plugins/chart.js/chart.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/chartjs-plugin-datalabels/chartjs-plugin-datalabels.js'));

/*
$this->headStyle()->captureStart();
echo <<<CSS


#tableUsers {
    display: flex;
    flex-flow: column;
    width: 100%;
}

#tableUsers thead {
    flex: 0 0 auto;
}

#tableUsers tbody {
    flex: 1 1 auto;
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
}

#tableUsers tr {
    width: 100%;
    display: table;
    table-layout: fixed;
}
CSS;
$this->headStyle()->captureEnd();*/

$this->inlineScript()->captureStart();
echo <<<JS
jQuery( document ).ready(function( $ ) {

    var startDate   = moment().format('YYYY-MM-DD'); 
    var endDate     = moment().format('YYYY-MM-DD'); 

    var ctxchartProgressByDay = document.getElementById("chartProgressByDay").getContext("2d");
    var chartProgressByDay = new Chart(ctxchartProgressByDay, {
        type: 'line',
        data: {
            labels: [],
            datasets: [
                {
                        label : 'LABEL_CONTACT_PROGRESS_BY_DAY',
                                backgroundColor: '#E69090',
                    borderColor: '#E69090',
                    borderWidth: 1,
                    fill: false,
                    data : []
                },
            ]
        },
        options: {
            tooltips: {
                mode: 'index',
                intersect: false
            },
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero:true
                    }
                }]
            }
        }
    });

    $.fn.reload = function() {
        NProgress.start();
        $.ajax({
            'dataType'  : 'json',
            'accept'    : 'application/json',
            'method'    : 'get',
            'url'       : '$routeOverview',
            'data'      :  {
                'startDate' : startDate,
                'endDate' : endDate
            },
        }).done(function(response) {
            if(response['success']) {

                chartProgressByDay.data.labels = response.data.graph.labels;
                chartProgressByDay.data.datasets[0].data = response.data.graph.values;
                chartProgressByDay.update()


                $('#tableUsers').html(
                    $('#tableTemplate').render(response.data.table)
                );

            }else{
                $.fn.showError(response);
            }
        }).fail(function( jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
        return false;
    }

    $('#filterdate').daterangepicker({
        maxDate: new Date(),
        locale: {
            format: 'DD/MM/YYYY',
            applyLabel: 'Aplicar',
            cancelLabel: 'Cancelar',
            daysOfWeek: ['Do', 'Lu','Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
            monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo',   
                'Junio',     
                'Agosto',   
                'Septiembre',   
                'Octubre',   
                'Noviembre',   
                'Diciembre'
            ],
        }
    });

    $('#filterdate').on('apply.daterangepicker', function(ev, picker) {
        startDate = picker.startDate.format('YYYY-MM-DD');
        endDate =picker.endDate.format('YYYY-MM-DD');
        $.fn.reload();
    });

    $('button.btn-download').click(function(e) {
        e.preventDefault();


        NProgress.start(); 
        $.ajax({
            'dataType'  : 'json',
            'method'    : 'get',
            'url'       : '$routeDownload',
            'data'      :  {
                'startDate' : startDate,
                'endDate' : endDate
            },
        }).done(function(response) {
            if(response['success']) {
                var anchor = window.document.createElement("a");
                anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + response['data']['content'] ;
                anchor.download = response['data']['basename'];
                document.body.appendChild(anchor);
                anchor.click();  // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
                document.body.removeChild(anchor);
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function( jqXHR, textStatus, errorThrown) {
            showError(textStatus);
        }).always(function() {
            NProgress.done();
        });


    });

    $.fn.reload();

});
JS;
$this->inlineScript()->captureEnd();
?>



<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12" id="row-list">
                <div class="card">
                    <div class="card-header">
                        <h2>LABEL_DAILY_PROGRESS_CHART</h2>
                        <div class="form-group">
                            <label>LABEL_DATE_RANGE</label>

                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="far fa-calendar"></i></span>
                                </div>
                                <input type="text" class="form-control float-right" name="filterdate" id="filterdate">
                            </div>
                            <!-- /.input group -->
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-lg-12 col-12 chart">
                                <canvas id="chartProgressByDay" style="min-height: 250px; height: 250px; max-height: 250px; max-width: 100%;"></canvas>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-12" id="row-table">
                                <div style="height: 300px;overflow: scroll;"> 
                                                <table id="tableUsers" style="width: 100%" class="table table-bordered table-hover">
                                        </table>
                            </div>
                        </div> 
                    </div>
                        <div class="card-footer clearfix">
                        <div class="text-right">
                            <button class="btn btn-primary btn-download">LABEL_DOWNLOAD</button>

                        </div>
                    </div>
                </div>
            </div>
        </div>
   </div>     
</section>



<script id="tableTemplate" type="text/x-jsrender">

        <thead>
            <tr>
                <th>LABEL_FIRST_NAME</th>
                <th>LABEL_LAST_NAME</th>
                <th>LABEL_EMAIL</th>
                {{for labels}}
                    <th>
                        {{:date}}
                    </th>
                {{/for}}
        </tr>
    </thead>
    <tbody>
        {{for users}}
            <tr>
                <td>{{:first_name}}</td>
                <td>{{:last_name}}</td>
                <td>{{:email}}</td>
                {{for values}}
                <td class="text-right">
                    {{:value}}
                </td>
                {{/for}}
            </tr>
        {{/for}}
    </tbody>
    

    
</script>

<!-- <section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12" id="row-list">
                <div class="card">
                    <div class="card-header">
                        <h2>LABEL_CONTACT_JOURNAL_PROGRESS</h2>
                        <div class="form-group">
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-lg-12 col-12 chart">
                                <table id="gridTable" class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th>LABEL_FIRST_NAME</th>
                                            <th>LABEL_LAST_NAME</th>
                                            <th>LABEL_EMAIL</th>
                                            <th>LABEL_ADDED</th>
                                            <th>LABEL_ADDED_DATE</th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</section> -->