1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-12-04 03:15:20 -05:00
shimapan/app/public/panel/controllers/DashCtrl.js

40 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2018-12-31 18:37:34 -05:00
const angular = require('angular');
2018-09-15 18:26:01 -04:00
angular.module('DashCtrl', ['chart.js', 'StatSvc']).controller('DashController', ['$scope', 'StatService', async ($scope, StatService) => {
2018-09-15 22:25:49 -04:00
const toHumanReadable = bytes => {
2018-12-31 18:37:34 -05:00
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
2018-09-15 22:25:49 -04:00
let index = 0;
2018-12-31 18:37:34 -05:00
for(; bytes >= 1024 && index < units.length - 1; index++)
bytes /= 1024;
2018-09-15 22:25:49 -04:00
return bytes.toFixed(3) + ' ' + units[index];
};
2018-09-15 18:26:01 -04:00
2019-01-01 17:55:04 -05:00
const getWeekUploadStats = async () => {
const stats = await StatService.getUploadsWeek();
console.log(stats);
$scope.statWeekUploads = stats.length;
$scope.statWeekUploadSize = toHumanReadable(stats.reduce((acc, stat) => acc + stat.size, 0));
};
2018-12-31 18:37:34 -05:00
2019-01-01 17:55:04 -05:00
const getWeekViewStats = async () => {
const stats = await StatService.getViewsWeek();
$scope.statWeekViews = stats.length;
};
2018-08-15 11:23:30 -04:00
2019-01-01 17:55:04 -05:00
const getAllUploadStats = async () => {
const stats = await StatService.getUploads();
console.log(stats);
$scope.statTotalUploads = stats.length;
$scope.statTotalUploadSize = toHumanReadable(stats.reduce((acc, stat) => acc + stat.size, 0));
};
2019-01-01 17:55:04 -05:00
const getAllViewStats = async () => {
const stats = await StatService.getViews();
$scope.statTotalViews = stats.length;
2018-08-15 11:23:30 -04:00
};
2019-01-01 17:55:04 -05:00
await Promise.all([getWeekUploadStats(), getWeekViewStats(), getAllUploadStats(), getAllViewStats()]);
$scope.$apply();
2018-09-15 18:26:01 -04:00
}]);