fixed huge cpu load

This commit is contained in:
cubedro
2015-05-19 22:07:06 +03:00
parent 403304947a
commit 89ba119123
6 changed files with 43 additions and 43 deletions

View File

@@ -63,10 +63,10 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
}
}
// var timeout = setInterval(function ()
// {
// $scope.$apply();
// }, 200);
var timeout = setInterval(function ()
{
$scope.$apply();
}, 200);
$scope.getNumber = function (num) {
return new Array(num);

View File

@@ -7,48 +7,48 @@ angular.module('netStatsApp.directives', [])
elm.text(version);
};
}])
.directive('timeAgo', ['$interval', function($interval) {
function link (scope, element, attrs)
{
var timestamp,
timeoutId;
// .directive('timeAgo', ['$interval', function($interval) {
// function link (scope, element, attrs)
// {
// var timestamp,
// timeoutId;
function updateTime() {
element.text(timeAgo())
}
// function updateTime() {
// element.text(timeAgo())
// }
function timeAgo()
{
if(timestamp === 0)
return '∞';
// function timeAgo()
// {
// if(timestamp === 0)
// return '∞';
var time = (new Date()).getTime();
var diff = Math.floor((time - timestamp)/1000);
// var time = (new Date()).getTime();
// var diff = Math.floor((time - timestamp)/1000);
if(diff < 60)
return Math.round(diff) + ' s ago';
// if(diff < 60)
// return Math.round(diff) + ' s ago';
return moment.duration(Math.round(diff), 's').humanize() + ' ago';
};
// return moment.duration(Math.round(diff), 's').humanize() + ' ago';
// };
scope.$watch(attrs.timeAgo, function(value) {
timestamp = value;
updateTime();
});
// scope.$watch(attrs.timeAgo, function(value) {
// timestamp = value;
// updateTime();
// });
element.on('$destroy', function() {
$interval.cancel(timeoutId);
});
// element.on('$destroy', function() {
// $interval.cancel(timeoutId);
// });
timeoutId = $interval(function () {
updateTime();
}, 200);
};
// timeoutId = $interval(function () {
// updateTime();
// }, 200);
// };
return {
link: link
};
}])
// return {
// link: link
// };
// }])
.directive('sparkchart', function () {
return {