|
7 | 7 | // 'save-complete' notifies that we have persisted the data to our own local storage |
8 | 8 |
|
9 | 9 | angular.module('frontendEngineeringChallengeApp') |
10 | | - .controller('AdminCtrl', function ($scope, $rootScope, $timeout, $interval, APIService) { |
| 10 | + .controller('AdminCtrl', function ($scope, $rootScope, $timeout, $interval, APIService, LocalService) { |
11 | 11 |
|
12 | 12 | // After a successful API call, we will replace our API objects |
13 | 13 | var receivedPostsData = false; |
|
16 | 16 | var receivedLikesData = false; |
17 | 17 | $scope.APIlikesData = undefined; |
18 | 18 |
|
19 | | - $scope.spreadsheet = []; |
| 19 | + // Attempt to get past records |
| 20 | + LocalService.getRecords(); |
20 | 21 |
|
21 | 22 | // Persist the data received from API to our own storage |
22 | 23 | function persistData(data){ |
|
26 | 27 | $timeout(function(){ |
27 | 28 | // Persist record and push record onto our spreadsheet |
28 | 29 | var record = constructRecordObj(); |
| 30 | + // Get it to show locally |
29 | 31 | $scope.spreadsheet.push(record); |
30 | 32 |
|
| 33 | + // Persist it to our Mongo Database |
| 34 | + LocalService.postRecord(record); |
| 35 | + |
31 | 36 | $scope.lastTimestamp = record.time; |
32 | 37 | $scope.$broadcast('save-complete'); |
33 | 38 | }, 2000); |
|
92 | 97 |
|
93 | 98 | }); |
94 | 99 |
|
| 100 | + // When we receive our spreadsheet object |
| 101 | + $rootScope.$on('spreadsheet-data', function(){ |
| 102 | + console.log('this is our spreadsheet object'); |
| 103 | + $scope.spreadsheet = LocalService.spreadsheet().records; |
| 104 | + console.log($scope.spreadsheet); |
| 105 | + }) |
| 106 | + |
95 | 107 |
|
96 | 108 | /***** Helper Functions *****/ |
97 | 109 |
|
|
0 commit comments