A simple file sharing site with an easy to use API and online panel.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.3KB

  1. var angular = require('angular');
  2. angular.module('DashCtrl', ['chart.js', 'StatSvc']).controller('DashController', ['$scope', 'StatService', async ($scope, StatService) => {
  3. const colorScheme = ['#2a9fd6'];
  4. // Calculate and format descending dates back one week to use for x-axis labels
  5. const currentDate = new Date();
  6. const oneDay = 1000 * 60 * 60 * 24;
  7. let labels = Array.from({length: 7}, (date, i) =>
  8. (new Date(currentDate - oneDay * (6 - i))).toISOString().substr(5, 5));
  9. const toHumanReadable = bytes => {
  10. const units = ['B', 'KB', 'MB', 'GB', 'TB'];
  11. let index = 0;
  12. for (; bytes >= 1024 && index < units.length - 1; index++, bytes /= 1024) {}
  13. return bytes.toFixed(3) + ' ' + units[index];
  14. };
  15. StatService.getWeek((err, stats) => {
  16. $scope.uploadData = [Array.from({length: 7}, (val, i) => stats[labels[i]] && stats[labels[i]].uploads ? stats[labels[i]].uploads : 0)];
  17. $scope.viewData = [Array.from({length: 7}, (val, i) => stats[labels[i]] && stats[labels[i]].views ? stats[labels[i]].views : 0)];
  18. $scope.stats = stats;
  19. $scope.statUploads = Object.keys(stats).reduce((acc, key) => acc + (stats[key].uploads ? stats[key].uploads : 0), 0);
  20. $scope.statUploadSize = toHumanReadable(Object.keys(stats).reduce((acc, key) => acc + (stats[key].size ? stats[key].size : 0), 0));
  21. $scope.statViews = Object.keys(stats).reduce((acc, key) => acc + (stats[key].views ? stats[key].views : 0), 0);
  22. });
  23. StatService.getAll((err, stats) => {
  24. $scope.statTotalUploads = stats.count;
  25. $scope.statTotalUploadSize = toHumanReadable(stats.size);
  26. $scope.statTotalViews = stats.views;
  27. });
  28. $scope.uploadColors = colorScheme;
  29. $scope.uploadLabels = labels;
  30. $scope.uploadSeries = ['Uploads'];
  31. //$scope.uploadData = [[5, 11, 4, 3, 7, 9, 21]];
  32. $scope.uploadOptions = {
  33. title: {
  34. display: true,
  35. text: 'Historical Uploads'
  36. },
  37. };
  38. $scope.viewColors = colorScheme;
  39. $scope.viewLabels = labels;
  40. $scope.viewSeries = ['Views'];
  41. //$scope.viewData = [[5, 11, 4, 3, 7, 9, 21]];
  42. $scope.viewOptions = {
  43. title: {
  44. display: true,
  45. text: 'Historical Views'
  46. }
  47. };
  48. }]);