diff --git a/app/public/panel/controllers/UserCtrl.js b/app/public/panel/controllers/UserCtrl.js index 432a8bd..4cf2dda 100644 --- a/app/public/panel/controllers/UserCtrl.js +++ b/app/public/panel/controllers/UserCtrl.js @@ -6,4 +6,21 @@ angular.module('UserCtrl', ['UserSvc']).controller('UserController', ['$scope', $scope.users = users; }); }; + + $scope.shorten = function(size) { + var units = ['B', 'KB', 'MB', 'GB', 'TB']; + var currUnit = 0; + + var num = parseFloat(size); + for (i = 0; i < units.length; i++) { + if (num / 1000 >= 1 && currUnit < units.length - 1) { + currUnit++; + num /= 1000; + } else { + // Round to 2 decimal places + return Number(Math.round(num + 'e1')+'e-1') + ' ' + + units[currUnit]; + } + } + } }]); \ No newline at end of file diff --git a/public/views/panel/users.html b/public/views/panel/users.html index ef9061a..cca2937 100644 --- a/public/views/panel/users.html +++ b/public/views/panel/users.html @@ -11,7 +11,7 @@ {{user.username}} {{user.scope}} {{user.uploadCount}} - {{user.uploadSize}} + {{shorten(user.uploadSize)}} {{user.date}}