. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AnonSec Shell
AnonSec Shell
Server IP : 52.223.31.75  /  Your IP : 172.31.32.98   [ Reverse IP ]
Web Server : Apache/2.4.66 () OpenSSL/1.0.2k-fips PHP/7.4.33
System : Linux ip-172-31-14-81.eu-central-1.compute.internal 4.14.281-212.502.amzn2.x86_64 #1 SMP Thu May 26 09:52:17 UTC 2022 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
Domains : 4 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/ripara.co/admin/js/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /var/www/ripara.co/admin/js/controllers/UAP.js
materialAdmin
    
    //=================================================
    // Controller Gruppi
    //=================================================

    .controller('UAPCtrl', function($filter, $sce, $log, $state, $scope, $rootScope, ngTableParams, tableService, APIService, animationService, growlService) {
        // ACL
        if($scope.thisPagesNames.indexOf($state.current.nomePagina) < 0){
            // OuttaHere!
            $state.go("home");
            growlService.growl($scope.outtaHere, 'danger');
        }
        

        $scope.$on('$locationChangeSuccess', function(e, newUrl, oldUrl) {
            // Prevent $urlRouter's default handler from firing
            e.preventDefault();

              if ($rootScope.UAP) {
  
                 $scope.ripristinaUltimaRicerca();


              } 

           
        });


        $scope.$on("$destroy", function(){

            //TODO: rilascio le risorse annullo chiamate api getuap

        });

        this.animationService = animationService;

        this.grafico = 1;

        //LOCAL STORAGE
        if (typeof(Storage) !== "undefined") {
            
            // Retrieve
            var colonneUAP = localStorage.getItem("colonneUAP");
            if(colonneUAP){
                $scope.activeFields = JSON.parse(colonneUAP);
            }else{
                $scope.activeFields = [];
            }

        } else {
            animationService.setAnimationJam("bounceInDown", "alert-red", false, "Attenzione, vostro browser non supporta il Web Storage!<br>I campi delle colonne prescelte non verranno memorizzati!");// Sorry! No Web Storage support..
        }

        scoping = $scope;



        $scope.aggiornaUltimaRicerca = function(StartTime, EndTime, dati, filtri){


            var daSalvare ={  'StartTime':StartTime,
                                  'EndTime':EndTime,
                                  'dati': dati,
                                  'filtri':filtri
                                };
            $rootScope.UAP = daSalvare;
        
        }

        $scope.ripristinaUltimaRicerca = function(){

             var dati = $rootScope.UAP;
                if(dati){
                    var parsedDati=dati;

                    //aggiungo i filtri
                     if(parsedDati.filtri && parsedDati.filtri.length>0){
                        for(k in parsedDati.filtri){
                            scoping.filtriAdded.push(parsedDati.filtri[k]);
                       }
                    }

                    // creo elenco campi
                    if(!scoping.elencoCampi || scoping.elencoCampi.length < 1)
                    for (x in parsedDati.dati[0]){
                        if(x!="$$hashKey")
                        scoping.elencoCampi.push(x);
                    }
                    //controllo numero campi
                    while(scoping.elencoCampi.length > scoping.activeFields.length){
                        scoping.activeFields.push(false);
                    }
                    
                    scoping.ricercaEffettuata = true;
                     //imposto le date
                    scoping.dtPopup = parsedDati.StartTime;
                    scoping.dtPopup2 = parsedDati.EndTime;
                    scoping.uctrl.data = parsedDati.dati;
                
                    data = parsedDati.dati;
                    scoping.uctrl.tableSource = new ngTableParams({
                        page: 1,            // show first page
                        count: 100
                    }, 
                    {
                        total: data.length,// $scope.data.length, // length of data
                        getData: function($defer, params) {
                            
                            //controllo se esisteno paramentri che si chiamamo orderby, all'onclick ordino per quel campo
                            if(params.sorting()['orderBy'] != undefined){
                                
                                //aggiungo la substr perchè il primo carattere viene messo random, altrimenti ordinerebbe sempre DESC visto che se è ordinata per una qualsiasi colonna non fa più ordinare per la stessa
                                var orderedData = $filter('orderBy')(data, $scope.rawProperty(params.sorting()['orderBy'].substr(1)), $scope.uctrl.isSortBy);
                                scoping.uctrl.isSortBy = !scoping.uctrl.isSortBy;
                                
                                //ok ma non funziona con le key con spazi o punti
                                //var orderedData = $filter('orderBy')(data, params.sorting()['orderBy']);

                               
                            }else{
                                var orderedData = data;
                            }
                            //verifico se sono definiti filtri
                            //orderedData = $filter('filterFailed')(orderedData, $scope.showOnlyFailed);
                            if(params.sorting()['filter'] != undefined){

                                var chiave = params.sorting()['filter'].key;
                                var value = params.sorting()['filter'].value;
                                var operatore = params.sorting()['filter'].operatore;
                                
                                if(value != ""){

                                    switch(operatore){
                                            case "!=":
                                                var tmpSrc = {};
                                                tmpSrc[chiave] = "!"+value;
                                                orderedData = $filter('filter')(orderedData,tmpSrc);
                                            break;
                                            
                                            case ">":
                                                var tmpData = [];
                                                orderedData.forEach(function(infoArray, index){
                                                        if(value && infoArray[chiave] > value){
                                                            tmpData.push(infoArray[chiave]);
                                                        }
                                                    }); 
                                                orderedData =[];
                                                orderedData = tmpData;
                                            break;
                                            case "<":
                                                var tmpData = [];
                                                orderedData.forEach(function(infoArray, index){
                                                        if(value && infoArray[chiave] < value){
                                                            tmpData.push(infoArray[chiave]);
                                                        }
                                                    });             
                                                orderedData =[];
                                                orderedData = tmpData;
                                            break;
                                            default://case "=":
                                                var tmpSrc = {};
                                                tmpSrc[chiave] = value;
                                                orderedData = $filter('filter')(orderedData,tmpSrc);

                                            break;

                                        }

                                }else{//fine if
                                    var tmpSrc = {};
                                    tmpSrc[chiave] = value;
                                    orderedData = $filter('filter')(orderedData,tmpSrc);
                                }
                            }

                            /*
                            app.filter('startsWithA', function () {
                              // function to invoke by Angular each time
                              // Angular passes in the `items` which is our Array
                              return function (items) {
                                // Create a new Array
                                var filtered = [];
                                // loop through existing Array
                                for (var i = 0; i < items.length; i++) {
                                  var item = items[i];
                                  // check if the individual Array element begins with `a` or not
                                  if (/a/i.test(item.name.substring(0, 1))) {
                                    // push it into the Array if it does!
                                    filtered.push(item);
                                  }
                                }
                                // boom, return the Array after iteration's complete
                                return filtered;
                              };
                            });
                            */

                            params.total(orderedData.length); // set total for recalc pagination
                            
                            $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                            
                            
                        }
                    }
                    );

                }

        }


        $scope.aggiornaActiveFields = function(){
            if (typeof(Storage) !== "undefined") {
                try{
                    localStorage.setItem("colonneUAP", JSON.stringify($scope.activeFields));
                }catch(e){
                    console.log('Troppi dati per il local storage__',e);
                }
            } 
        }


        //FINE LOCAL STORAGE
        $scope.mostraNelGrafico =[];

        $scope.today = function() {
            $scope.dt = new Date();
        };
        $scope.today();


        $scope.toggleMin = function() {
            $scope.minDate = $scope.minDate ? null : new Date();
        };
        $scope.toggleMin();

        $scope.open = function($event, opened) {
            $event.preventDefault();
            $event.stopPropagation();

            $scope[opened] = true;
        };

        $scope.dateOptions = {
            formatYear: 'yy',
            startingDay: 1
        };

        $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
        $scope.format = $scope.formats[0];
        

        // elenco nome dei Campi per ricerca avanzata
        $scope.elencoCampi = [];

        $scope.getCampo = function(x,val){
          //  console.log("--->",$scope.elencoCampi[x],x,val)
            return $scope.elencoCampi[x];
        }



        //primo caricamento dati per ricerca campi db
         APIService.async({
                    method: "getcampiuapalias",
                }).then(function(adata) {

                if(adata.status && adata.message.length){
                    //assegno i dati ricevuti a data
                    var data = adata.message;
                    $scope.elencoCampiRICERCABACK = data;
                }
            });



        $scope.export = function (x){
 
                var data = $scope.uctrl.data;
                if(data){

                    growlService.growl("Esportazione dati avviata!", 'info');


                    var csvContent = "";
        
                    var numeroOggetti = data.length;

                    var soloIntestazione = [];           
                    //aggiugno intestazione
                    var i = 0;
                    for (chiave in data[0]) {
                        if(x){
                            if(chiave != '$$hashKey'){
                                soloIntestazione.push(chiave);
                            } 
                        }else{
                            if(chiave != '$$hashKey' &&  $scope.activeFields[i]){
                                soloIntestazione.push(chiave);
                            } 
                            
                        }
                        i++;
                    }
                    csvContent+= soloIntestazione.join(";")+ "\n";

                    i=0;
                    data.forEach(function(infoArray, index){
                        var soloDati = [];           

                        //aggiugno dati
                       for(chiave in infoArray){

                        if(x){
                            if(chiave != '$$hashKey'){

                                if(chiave =="StartTime" || chiave =="EndTime" || chiave =="AnswerTime"  || chiave == "AlertingTime" || chiave == "CALLEND" || chiave == "CALLBEGIN" || chiave == "ACKEND" || chiave == "ACKBEGIN" || chiave == "WAITEND" || chiave == "WAITBEGIN"){
                                    if(infoArray[chiave]){
                                        var dateRicevuta = infoArray[chiave];
                                        if(dateRicevuta){
                                            var tmp = new Date((dateRicevuta.sec*1000)+(3600*2000) );
                                            var atmp = (tmp.getHours()<10?'0':'') + tmp.getHours() + ":" + (tmp.getMinutes()<10?'0':'') + tmp.getMinutes() + ":" + (tmp.getSeconds()<10?'0':'') + tmp.getSeconds() + " " + (tmp.getDate()<10?'0':'') + tmp.getDate() + "/" + (tmp.getMonth()<9?'0':'') + (tmp.getMonth()+1) + "/" + tmp.getFullYear();
                                            soloDati.push(atmp);

                                        }else{
                                            soloDati.push(" ");
                                        }
                                        
                                    }else{
                                        soloDati.push(" ");

                                    }
                                }else if(chiave =="_id"){
                                    var dollaro = '$id';
                                    soloDati.push(infoArray[chiave][dollaro]);
                                }else{
                                    soloDati.push(infoArray[chiave]);
                                }
                                
                            }
                         }else{
                            if($scope.activeFields[i]){
                                if(chiave =="StartTime" || chiave =="EndTime" || chiave =="AnswerTime"  || chiave == "AlertingTime" || chiave == "CALLEND" || chiave == "CALLBEGIN" || chiave == "ACKEND" || chiave == "ACKBEGIN" || chiave == "WAITEND" || chiave == "WAITBEGIN"){
                                    if(infoArray[chiave]){
                                        var dateRicevuta = infoArray[chiave];
                                        if(dateRicevuta){
                                            var tmp = new Date((dateRicevuta.sec*1000)+(3600*2000) );
                                            var atmp = (tmp.getHours()<10?'0':'') + tmp.getHours() + ":" + (tmp.getMinutes()<10?'0':'') + tmp.getMinutes() + ":" + (tmp.getSeconds()<10?'0':'') + tmp.getSeconds() + " " + (tmp.getDate()<10?'0':'') + tmp.getDate() + "/" + (tmp.getMonth()<9?'0':'') + (tmp.getMonth()+1) + "/" + tmp.getFullYear();
                                            soloDati.push(atmp);
                                        }else{
                                            soloDati.push(" ");
                                        }
                                        
                                    }else{
                                        soloDati.push(" ");
                                    }
                                }else if(chiave =="_id"){
                                    var dollaro = '$id';
                                    soloDati.push(infoArray[chiave][dollaro]);
                                }else{
                                    soloDati.push(infoArray[chiave]);
                                }  
                            }
                         }
                         i++;
                       };
                       i=0; //riparto a acontrollare le field attive (ricorda sono un'array lungo qunato le colonne con true e false se attive o disattive)

                      dataString = soloDati.join(";");
                      csvContent+= index < numeroOggetti ? dataString+ "\n" : dataString;
                    });
                    

                     var myBlob = new Blob([csvContent], {type: "application/octet-stream"});
     
                    var reader = new FileReader();
                     
                    reader.onload = function(event) {
                        var URL = event.target.result;
                        var a = document.createElement('a');
                        a.setAttribute('download', 'ricercaCTI.csv')

                        a.href = URL;
                        a.click();


                    };
                     
                    reader.readAsDataURL(myBlob);

                }else{
                    
                    growlService.growl("Esportazione non riuscita, dati non presenti!", 'warning');

                    return null;
                }

            
                
               
        //    DatiToCsv.getData();
        }

        $scope.selezionaTutti = function(x){
            for(var i = 0; i < $scope.activeFields.length ; i++){
                if(x){
                    $scope.activeFields[i] = true;
                }else{
                    $scope.activeFields[i] = false;
                }
            }
        }


        $scope.bottoneAggiornaDati = true;

        //Caricament dati da API REST
        $scope.aggiornaDati = function(primaChiamata){

            //rimuovo i dati salvati in cache
            $rootScope.UAP = [];

        
            $scope.bottoneAggiornaDati = false;
            //nascondo spazio del grafico
            $scope.showGrafico = false;
            //pulisco filtri front end
            $scope.filtriAddedFront = [];
            $scope.mostraNelGrafico = [];


            //verifico dimenticanza pulsante +
            if($scope.o.campo && $scope.o.operatore && $scope.o.value){
                $scope.addFilter($scope.o.campo, $scope.o.operatore, $scope.o.value, "");
            }


            if (primaChiamata){
                var q = {
                    method: "getuap",
                };    
            }else{
                var query = [];
                //rimuovo il colore per la chiamata alle api
                for(k in $scope.filtriAdded){
                    query.push({
                        "campo": $scope.filtriAdded[k].campo,
                        "operatore": $scope.filtriAdded[k].operatore,
                        "value": $scope.filtriAdded[k].value
                    });
                }
                
                var q = {
                    method: "getuap",
                    datainizio: new Date($scope.dtPopup).getTime(),
                    datafine: new Date($scope.dtPopup2).getTime(),
                    avanzata: $scope.ricercaAvanzata,
                    //tipo: $scope.o.xor,
                    query: query
                };
            }
            console.log("Query;",q);
            $scope.elencoCampi = [];
            
            if($scope.filtriAdded.length<1){
                growlService.growl("Attenzione non è stato impostato nessun filtro, la ricerca potrebbe richiedere del tempo aggiuntivo!", 'warning');
            }
            //console.log('q = ', q);

            growlService.growl("Ricerca avviata, puoi continuare la navigazione!", 'info');

            $scope.uctrl.data = [];

            APIService.async(q).then(function(adata) {

                if(!adata){
                    growlService.growl("Il server ha restituito un errore, provare con una query più piccola!", 'error');
  
                }else if(adata.status && adata.message.length){
                    //assegno i dati ricevuti a data
                    var data = adata.message;

                    if($scope.uctrl){


                        $scope.ricercaEffettuata = true;
                        
                      
                        // creo elenco campi
                        for (x in data[0]){
                            $scope.elencoCampi.push(x);
                        }

                        //controllo numero campi
                        while($scope.elencoCampi.length > $scope.activeFields.length){
                            $scope.activeFields.push(false);
                        }

                        scoping = $scope;
                        //aggiorno la variabile per ng-repeat della tabella
                        $scope.uctrl.data = data;

                        //salvo nel local storage
                        $scope.aggiornaUltimaRicerca(new Date($scope.dtPopup).getTime(), new Date($scope.dtPopup2).getTime(), data, $scope.filtriAdded);

                        //$scope.filtraDati(data, $scope.filtriAdded);

                        //instanzio la ng-table
                        $scope.uctrl.tableSource = new ngTableParams({
                            page: 1,            // show first page
                            count: 50
                        }, 
                        {
                            total: data.length,// $scope.data.length, // length of data
                            getData: function($defer, params) {
                                
                                //controllo se esisteno paramentri che si chiamamo orderby, all'onclick ordino per quel campo
                                if(params.sorting()['orderBy'] != undefined){
                                    
                                    //aggiungo la substr perchè il primo carattere viene messo random, altrimenti ordinerebbe sempre DESC visto che se è ordinata per una qualsiasi colonna non fa più ordinare per la stessa
                                    var orderedData = $filter('orderBy')(data, $scope.rawProperty(params.sorting()['orderBy'].substr(1)), $scope.uctrl.isSortBy);
                                    $scope.uctrl.isSortBy = !$scope.uctrl.isSortBy;
                                    
                                    //ok ma non funziona con le key con spazi o punti
                                    //var orderedData = $filter('orderBy')(data, params.sorting()['orderBy']);

                                   
                                }else{
                                    var orderedData = data;
                                }
                                //verifico se sono definiti filtri
                                //orderedData = $filter('filterFailed')(orderedData, $scope.showOnlyFailed);
                                 if(params.sorting()['filter'] != undefined){

                                var chiave = params.sorting()['filter'].key;
                                var value = params.sorting()['filter'].value;
                                var operatore = params.sorting()['filter'].operatore;
                                
                                if(value != ""){

                                    switch(operatore){
                                            case "!=":
                                                var tmpSrc = {};
                                                tmpSrc[chiave] = "!"+value;
                                                orderedData = $filter('filter')(orderedData,tmpSrc);
                                            break;
                                            
                                            case ">":
                                                var tmpData = [];
                                                orderedData.forEach(function(infoArray, index){
                                                        if(value && infoArray[chiave] > value){
                                                            tmpData.push(infoArray[chiave]);
                                                        }
                                                    }); 
                                                orderedData =[];
                                                orderedData = tmpData;
                                            break;
                                            case "<":
                                                var tmpData = [];
                                                orderedData.forEach(function(infoArray, index){
                                                        if(value && infoArray[chiave] < value){
                                                            tmpData.push(infoArray[chiave]);
                                                        }
                                                    });             
                                                orderedData =[];
                                                orderedData = tmpData;
                                            break;
                                            default://case "=":
                                                var tmpSrc = {};
                                                tmpSrc[chiave] = value;
                                                orderedData = $filter('filter')(orderedData,tmpSrc);

                                            break;

                                        }

                                }else{//fine if
                                    var tmpSrc = {};
                                    tmpSrc[chiave] = value;
                                    orderedData = $filter('filter')(orderedData,tmpSrc);
                                }
                                }

                                

                                params.total(orderedData.length); // set total for recalc pagination
                                
                                $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                                
                                
                            }
                        }
                        );
                        $scope.bottoneAggiornaDati = true;

                        if(adata.message.length<2 && adata.message[0]['_id'] == "noresult"){
                         growlService.growl("Non sono stati trovati records!", 'warning');

                        }else{
                         growlService.growl("Ricevuti "+ adata.message.length+" records UAP", 'info');

                        }

                        //fine se esiste il controller
                    }else{
                        //se non esiste il controller aggiungo a root scope se torna
                        $rootScope.UAP = adata.message;
                    }

                }else{
                    
                    animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di carimento dei dati, si prega di aggiornare la pagina!");

                }
                //console.log(adata);
            });
        }
        
    //carica i dati all'inizio
        // $scope.aggiornaDati(true);
        $scope.ricercaEffettuata = false;


        //questa funzione fixa il problema delle chiavi con spazi o caratteri speciali nell'ordinamento delle tabelle
        //utile per le alias colonne es. Numero Chiamante
        $scope.rawProperty = function(key) {
            return function(item) {
                if((key == "EndTime" || key == "StartTime" || key == "AnswerTime" || key == "AlertingTime")){

                    return item[key]['sec']*1000;
                } 
                return item[key];
            };
        };


        //questa variabile serve per invertire l'ordinamento cambia ad ogni click con true o false
        $scope.uctrl.isSortBy = true;
        


        //$scope.show.SwitchName = false;


        $scope.filtriAdded = [];
        $scope.filtriAddedFront = [];

        $scope.o = {};
        $scope.addFilter = function(campo, operatore, value, colore){
            $scope.filtriAdded.push({'campo':campo,'operatore': operatore, 'value':value, 'colore':colore});
            //$scope.operatore = 
            $scope.o.value = '';
            $scope.o.colore = '';
            $scope.o.campo = undefined;
            $scope.o.operatore = undefined;
            
            $('[color-picker]')[0].style = '';
            //console.log($scope.filtriAdded);

            /* Rimuove il campo già inserito dall'elenco
            var index = $scope.elencoCampi.indexOf(campo);
            if (index > -1) {
                $scope.elencoCampi.splice(index, 1);
            }
            */
        }

        

        //FUNZIONE RICHIAMATA ALL'AAGGIUNTA DI UN FILTRO DI FRONT END
        $scope.addFilterFront = function(campo, operatore, value, colore, tempo){

            var campioni = [];

            for (var i = $scope.uctrl.data.length - 1; i >= 0; i--) {
                    
                    //verifico la condizione tra i dati ricevuti e aggiungo il record
                    switch (operatore){
                        case ' = ':
                            if($scope.uctrl.data[i][campo] == value){
                                campioni.push($scope.uctrl.data[i]);
                            }
                        break;
                        case ' < ':
                            if($scope.uctrl.data[i][campo] < value){
                                campioni.push($scope.uctrl.data[i]);
                            }
                        break;
                        case ' > ':
                            if($scope.uctrl.data[i][campo] > value){
                                campioni.push($scope.uctrl.data[i]);
                            }
                        break;
                    }

            } //end for dati

            $scope.filtriAddedFront.push({'campo':campo, 'operatore':operatore, 'value':value, 'colore':colore, 'tempo':tempo, 'campioni':campioni});

            $scope.showGrafico = true;

            $scope.o.valueFront = '';
            $scope.o.coloreFront = '';
            $scope.o.campoFront = undefined;
            $scope.o.operatoreFront = undefined;

            $('[color-picker]')[0].style = '';

            /* Rimuove il campo già inserito dall'elenco
            var index = $scope.elencoCampi.indexOf(campo);
            if (index > -1) {
                $scope.elencoCampi.splice(index, 1);
            }
            */
        }

        $scope.removeFilter = function(filtro){

            for(var i = 0; i<$scope.filtriAdded.length; i++){
                
                
                if($scope.filtriAdded[i].campo == filtro){
                    $scope.filtriAdded.splice(i,1);
                    //$scope.elencoCampi.push(filtro); // Riaggiunge il campo rimosso all'elenco
                }
                
            }
        }

        $scope.removeFilterFront = function(filtro){

            for(var i = 0; i<$scope.filtriAddedFront.length; i++){
                
                
                if($scope.filtriAddedFront[i].campo == filtro){
                    $scope.filtriAddedFront.splice(i,1);
                    //$scope.elencoCampi.push(filtro); // Riaggiunge il campo rimosso all'elenco
                }
                
            }
            if($scope.filtriAddedFront.length <1 ){
                $scope.showGrafico = false;
            }else{
                $scope.aggiornaGrafico();    
            }
            
        }

        //$scope.mytime = new Date();

          $scope.hstep = 1;
          $scope.mstep = 1;

          $scope.options = {
            hstep: [1, 2, 3], // Numero ore che cambiano cliccando sui bottoni
            mstep: [1, 5, 10, 15, 25, 30]
          };

          $scope.ismeridian = false;
          $scope.toggleMode = function() {
            $scope.ismeridian = ! $scope.ismeridian;
          };

          $scope.update = function() {
            var d = new Date();
            d.setHours( 14 );
            d.setMinutes( 0 );
            $scope.mytime = d;
          };

          $scope.changed = function () {
            if($scope.dtPopup2 < $scope.dtPopup){
                $scope.dtPopup2 = new Date().setTime($scope.dtPopup.getTime() + 60*60*1000);;
            }
    //        $log.log('Time changed to: ' + $scope.dtPopup);
       //     $log.log('Time changed to: ' + $scope.dtPopup2);
          };

          $scope.dtPopup2 = new Date();//.setHours(0,0,0,0);;
          $scope.dtPopup = new Date().setTime(new Date().getTime() - 60*60*1000);//23,59,0,0);;

          $scope.clear1 = function() {
            $scope.dtPopup = null;
          };

          $scope.clear2 = function() {
            $scope.dtPopup2 = null;
          };

        $scope.logic = [];
        $scope.operatori = [];
        $scope.values = [];
        
        $scope.showGrafico = false;

        // Crea array con i valori da visualizzare nei grafici
        /*
        $scope.datiElaborati = [];

        $scope.elaboraDati = function(dati){
            
            // creo, all'interno di datiElaborati, un array per ogni categoria
            for (i in dati[0]){
                $scope.datiElaborati[i] = [];
            }
            
            // inserisco per ogni campione il valore in ogni categoria
            for (i = 0; i < dati.length; i++){
                //console.log(dati[i]);
                for (j in dati[i]){
                    $scope.datiElaborati[j].push(dati[i][j]);
                    
                    console.log('j', j); // key
                    console.log('dati[i][j]', dati[i][j]); // value
                    console.log('$scope.datiElaborati[j]', $scope.datiElaborati[j]);
                    
                }

            }
            
            console.log('$scope.datiElaborati', $scope.datiElaborati);

            var y = $scope.datiElaborati 
            return y;

        }
        */

        $scope.convertiData = function(dateRicevuta){
            if(dateRicevuta){
                var tmp = new Date((dateRicevuta.sec*1000)+(3600*2000) );
                return (tmp.getHours()<10?'0':'') + tmp.getHours() + ":" + (tmp.getMinutes()<10?'0':'') + tmp.getMinutes() + ":" + (tmp.getSeconds()<10?'0':'') + tmp.getSeconds() + " " + (tmp.getDate()<10?'0':'') + tmp.getDate() + "/" + (tmp.getMonth()<9?'0':'') + (tmp.getMonth()+1) + "/" + tmp.getFullYear();
            }
            return "";
        }

        $scope.getCampioni = function(arrayDaCampionare){
            if($scope.o.tempo<1){$scope.o.tempo = 30;}

            var t = $scope.o.tempo;
            
            var array = [];
            //console.log('getCampioni', arrayDaCampionare);
            var Tic = arrayDaCampionare[0].EndTime.sec; // tempoInizialeCampionamento
            var Tfc = arrayDaCampionare[arrayDaCampionare.length-1].EndTime.sec+1; // tempoFinaleCampionamento
            if(Tfc < Tic){ //inverto array
                arrayDaCampionare= arrayDaCampionare.reverse();
                var tmpTic = Tic;
                var tmpTfc = Tfc;
                Tfc = Tic;
                Tic = tmpTfc;
            }


            var Ttc = Tfc - Tic; // Tempo totale di campionamento
            var c = Ttc / t; // Numero di campioni


            for (j = 0; j < c; j++){
                var counter = 0;
                for(i in arrayDaCampionare){
                    // Se il valore è compreso nel tempo di campionamento, incremento il contatore
                    if(Tic + j*t <= arrayDaCampionare[i].EndTime.sec && arrayDaCampionare[i].EndTime.sec < Tic + (j+1)*t){
                        counter++;
                    }                    

                }
                //tempo istantaneo ex j
                tempoIstantaneo = Tic + (t*j); //tempo Iniziale Campionamento + periodo di campionamento * numero del campione attuale

                tempoIstantaneo+=60*60*3;

                //array[j]= new Array(j, counter);
                array[j]= new Array((tempoIstantaneo*1000), counter);
            }

            return array;
        }

        $scope.ricercaAvanzata = true;
        $scope.o.xor = "AND";
        $scope.x = {};

        $scope.aggiornaGrafico = function(){
            $scope.x.datiPerIlGrafico = [];
            

            for (var i = $scope.filtriAddedFront.length - 1; i >= 0; i--) {
                    //
                    //if($scope.filtriAddedFront[i].campo == campo && $scope.filtriAddedFront[i].operatore == operatore && $scope.filtriAddedFront[i].value == value){
                    if($scope.filtriAddedFront[i]['campioni'] && $scope.mostraNelGrafico[i]){    
                        $scope.x.datiPerIlGrafico.push(
                            { 
                                "dati": $scope.getCampioni($scope.filtriAddedFront[i]['campioni']),
                                //"dati": d1,
                                "colore": $scope.filtriAddedFront[i].colore,
                                "label": $scope.filtriAddedFront[i].campo+$scope.filtriAddedFront[i].operatore+$scope.filtriAddedFront[i].value
                            });
                    }
                    
            }

            //console.log('datiPerIlGrafico: ', $scope.x.datiPerIlGrafico);
        }

    })

Anon7 - 2022
AnonSec Team