2018-08-15 09:27:32 -04:00
|
|
|
var 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-08-15 11:23:30 -04:00
|
|
|
const colorScheme = ['#2a9fd6'];
|
2018-09-15 18:26:01 -04:00
|
|
|
// Calculate and format descending dates back one week to use for x-axis labels
|
2018-09-15 14:00:20 -04:00
|
|
|
const currentDate = new Date();
|
|
|
|
const oneDay = 1000 * 60 * 60 * 24;
|
2018-09-15 18:26:01 -04:00
|
|
|
let labels = Array.from({length: 7}, (date, i) =>
|
|
|
|
(new Date(currentDate - oneDay * (6 - i))).toISOString().substr(5, 5));
|
|
|
|
|
|
|
|
StatService.getWeek((err, stats) => {
|
|
|
|
$scope.uploadData = [Array.from({length: 7}, (val, i) => stats[labels[i]] ? stats[labels[i]].uploads : 0)];
|
|
|
|
$scope.viewData = [Array.from({length: 7}, (val, i) => stats[labels[i]] ? stats[labels[i]].views : 0)];
|
|
|
|
|
|
|
|
$scope.stats = stats;
|
|
|
|
|
|
|
|
$scope.statUploads = Object.keys(stats).reduce((acc, key) => acc + stats[key].uploads);
|
|
|
|
$scope.statUploadSize = Object.keys(stats).reduce((acc, key) => acc + stats[key].size);
|
|
|
|
$scope.statViews = Object.keys(stats).reduce((acc, key) => acc + stats[key].views);
|
|
|
|
});
|
|
|
|
|
|
|
|
StatService.getAll((err, stats) => {
|
|
|
|
$scope.statTotalUploads = stats.count;
|
|
|
|
$scope.statTotalUploadSize = stats.size;
|
|
|
|
$scope.statTotalViews = stats.views;
|
|
|
|
});
|
2018-08-15 11:23:30 -04:00
|
|
|
|
|
|
|
$scope.uploadColors = colorScheme;
|
2018-09-15 14:00:20 -04:00
|
|
|
$scope.uploadLabels = labels;
|
2018-08-15 09:27:32 -04:00
|
|
|
$scope.uploadSeries = ['Uploads'];
|
2018-09-15 18:26:01 -04:00
|
|
|
//$scope.uploadData = [[5, 11, 4, 3, 7, 9, 21]];
|
2018-08-15 09:27:32 -04:00
|
|
|
$scope.uploadOptions = {
|
2018-08-15 11:23:30 -04:00
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'Historical Uploads'
|
|
|
|
},
|
2018-08-15 09:27:32 -04:00
|
|
|
};
|
|
|
|
|
2018-08-15 11:23:30 -04:00
|
|
|
$scope.viewColors = colorScheme;
|
2018-09-15 14:00:20 -04:00
|
|
|
$scope.viewLabels = labels;
|
2018-08-15 11:23:30 -04:00
|
|
|
$scope.viewSeries = ['Views'];
|
2018-09-15 18:26:01 -04:00
|
|
|
//$scope.viewData = [[5, 11, 4, 3, 7, 9, 21]];
|
2018-08-15 11:23:30 -04:00
|
|
|
$scope.viewOptions = {
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'Historical Views'
|
|
|
|
}
|
|
|
|
};
|
2018-09-15 18:26:01 -04:00
|
|
|
}]);
|