Canvas Statistics collection (concept)

locationchangesucces
angularjs

#1
  1. Place the code below into yourappWEB-INF\pages\header.script.others.ftl
  2. Update $tm1Ui service to update cube structure and data

//JS:

app.run([’$rootScope’, ‘$state’, ‘$stateParams’, ‘$location’, ‘$tm1Ui’, ‘$timeout’, ‘$window’, function ($rootScope, $state, $stateParams, $location, $tm1Ui, $timeout, $window) {

console.log('STATISTICS states %o', $state);
//$broadcast: $locationChangeSuccess, $locationChangeStart, $destroy, $routeUpdate, $routeChangeStart, $routeChangeSuccess, $routeChangeError

var appName = $tm1Ui.applicationInfo().then(function (appInfo) {
    console.log('STATISTICS application %o', appInfo.name);
    return appInfo.name;
});

var userStatisticsUpdate = function () {

    $tm1Ui.applicationInstances().then(function (appInstInfo) {
        console.log('STATISTICS application appInstances %o', appInstInfo);

        for (i = 0; i < appInstInfo.length; i++) {
            if (appInstInfo[i]) {

                var currentInstance = appInstInfo[i].name;
                //console.log(currentInstance );
                var currentUser = appUser(currentInstance);
                //console.log(currentUser );

                var currentAppName = appName;
                console.log('STATISTICS app Name %o', currentAppName);

                var currentPage = $location.path();
                var currentState = $state.getCurrentPath();

                $tm1Ui.applicationUser(currentInstance).then(function (user) {
                    // console.log('user details %o', user);
                    //return {user:user};
                    console.log('STATISTICS USER %o', user);
                    if (user && !user.error) {
                        updateStatistics(currentInstance, user.Name, currentAppName, currentState, currentPage);
                    } else {
                        console.warn('STATISTICS Not logged In');
                    };

                });
            }

        }



    });
}


var appUser = function (instance) {
    $tm1Ui.applicationUser(instance).then(function (user) {
        console.log('STATISTICS user details %o', user);
        return { user: user };
    });
};



var updateStatistics = function (instance, user, appName, state, page) {
    //  console.log($state);
    // var state = toState;
    state = $location.path();
    //  console.log('STATISTICS  location ---- %o', $location.state());
    //  console.log($state.current.name);
    var d = new Date();
    var n = d.getTime();
    var currentTime = d.getHours() + ':' + ((d.getMinutes() < 10) ? '0' : '') + d.getMinutes();
    var currentDate = d.toLocaleDateString();
    console.log(currentDate + ' ' + user + ' ' + appName.name + ' ' + $state.current.name + ' ' + page + ' ' + currentTime + ' ' + n);

    // update dimensions first
    //
    // add here your cube for Statistics For example:
    //  $tm1Ui.cellPut(currentTime, instance, 'Your Statistics cube', appName,  page, user, currentDate, 'time')



}


/*$rootScope.$on('$locationChangeStart', function(event, url, oldUrl, state, oldState){

 });*/

$rootScope.$on('$locationChangeSuccess', function (event, url, oldUrl, state, oldState) {

    var navStart = $window.performance.timing.navigationStart;
    var loadTime = $window.performance.timing.domContentLoadedEventEnd - $window.performance.timing.navigationStart;
    //  console.log("Work time: ", loadTime)
    /*  console.log("PAGE LOAD TIME 0___ Time until reaching run phase: ", Date.now() - $window.timerStart); */
    console.log("STATISTICS Time until reaching run phase: ", Date.now() - navStart);

    /* window.onload = function(){
     setTimeout(function(){
         var t = performance.timing;
          console.log('PAGE LOAD TIME 3: ',t.loadEventEnd - t.responseEnd);
       }, 0);
     }*/

    console.log('STATISTICS old url to url %o', oldUrl + ' to ' + url);
    console.log('STATISTICS location state %o', state + ' ' + oldState);
    console.log('STATISTICS location path %o', $location.path());
    console.log(appName);
    userStatisticsUpdate();
});

}]);