UNPKG

gaf-mobile

Version:

GAF mobile Web site

37 lines (32 loc) 1.18 kB
'use strict'; angular.module('gafMobileApp') .controller('StatsCtrl', function($scope, $q, $interval, Stats) { var self = this; // Get & refresh the statistics $q.all([Stats.getGeneralStats(), Stats.get24hStats()]) .then(function(promises) { var stats = promises[0]; var stats24h = promises[1]; var startTime = Date.now() / 1000; // Init the stats var startStats = { totalUsers: stats.getTotalUsers(), millionUsers: Math.floor(stats.getTotalUsers() / 1000000), totalProjects: stats.getTotalProjects() }; angular.extend(self, angular.copy(startStats)); // Update the users & projects stats 5 seconds var t = $interval(function() { var ellaspedTime = (Date.now() / 1000) - startTime; self.totalUsers = startStats.totalUsers + (stats24h.get24hUsers() / 24 / 60 / 60) * ellaspedTime ; self.totalProjects = startStats.totalProjects + (stats24h.get24hProjects() / 24 / 60 / 60) * ellaspedTime; }, 5000); // Intervals are not automatically destroyed when // a controller's scope is destroyed $scope.$on('$destroy', function() { $interval.cancel(t); }); }); });