From 1139ff7f10cbc5db89c33e6464bbc690e13c846e Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Sat, 15 Sep 2018 18:26:01 -0400 Subject: [PATCH] Cleanup + work on dash ctrl --- app/public/panel/controllers/DashCtrl.js | 34 ++++++++++++++++++++++---------- public/views/panel/dash.html | 2 +- test/permissions.txt | 5 ++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/public/panel/controllers/DashCtrl.js b/app/public/panel/controllers/DashCtrl.js index 2f18ca3..8920d73 100644 --- a/app/public/panel/controllers/DashCtrl.js +++ b/app/public/panel/controllers/DashCtrl.js @@ -1,18 +1,34 @@ var angular = require('angular'); -angular.module('DashCtrl', ['chart.js']).controller('DashController', ['$scope', $scope => { +angular.module('DashCtrl', ['chart.js', 'StatSvc']).controller('DashController', ['$scope', 'StatService', async ($scope, StatService) => { const colorScheme = ['#2a9fd6']; - - // Calculate and format descending dates back one week + // Calculate and format descending dates back one week to use for x-axis labels const currentDate = new Date(); const oneDay = 1000 * 60 * 60 * 24; - let dates = Array.from({length: 7}, (date, i) => new Date(currentDate - oneDay * (6 - i))); - let labels = dates.map(date => date.toISOString().substr(5, 5)); + 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; + }); $scope.uploadColors = colorScheme; $scope.uploadLabels = labels; $scope.uploadSeries = ['Uploads']; - $scope.uploadData = [[10, 20, 30, 20, 15, 20, 45]]; + //$scope.uploadData = [[5, 11, 4, 3, 7, 9, 21]]; $scope.uploadOptions = { title: { display: true, @@ -23,13 +39,11 @@ angular.module('DashCtrl', ['chart.js']).controller('DashController', ['$scope', $scope.viewColors = colorScheme; $scope.viewLabels = labels; $scope.viewSeries = ['Views']; - $scope.viewData = [[5, 11, 4, 3, 7, 9, 21]]; + //$scope.viewData = [[5, 11, 4, 3, 7, 9, 21]]; $scope.viewOptions = { title: { display: true, text: 'Historical Views' } }; -}]); -{ -} \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/views/panel/dash.html b/public/views/panel/dash.html index 9a24bf0..755ade6 100644 --- a/public/views/panel/dash.html +++ b/public/views/panel/dash.html @@ -38,7 +38,7 @@ -
+
Total Uploads diff --git a/test/permissions.txt b/test/permissions.txt index 362edd4..24b1e11 100644 --- a/test/permissions.txt +++ b/test/permissions.txt @@ -8,4 +8,7 @@ file api create - delete \ No newline at end of file + delete + +stats + get \ No newline at end of file