1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-30 14:31:42 -05:00

Add unit shortening to users page

This commit is contained in:
Jack Foltz 2018-01-15 18:14:37 -05:00
parent c7e58c490f
commit 150b736071
Signed by: foltik
GPG Key ID: 303F88F996E95541
2 changed files with 18 additions and 1 deletions

View File

@ -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];
}
}
}
}]);

View File

@ -11,7 +11,7 @@
<td>{{user.username}}</td>
<td>{{user.scope}}</td>
<td>{{user.uploadCount}}</td>
<td>{{user.uploadSize}}</td>
<td>{{shorten(user.uploadSize)}}</td>
<td>{{user.date}}</td>
</tr>
</table>