Skip to content

Commit 2d52a91

Browse files
committed
displays saved data from dashboard
1 parent f903ee1 commit 2d52a91

File tree

5 files changed

+184
-76
lines changed

5 files changed

+184
-76
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
a# Submission for Frontend Engineer
1+
# Submission for Frontend Engineer
22
This is MEAN Stack app that can be run nightly. It pulls information from an API and caches the information for later display.
33

4+
## Pages
5+
Main pages are /admin and /dashboard
6+
47
## Configuration
58
### Client
69
**Scripts**

client/partials/dashboard.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,16 @@ <h1>Dashboard Display</h1>
66
<h3>Visual Section</h3>
77

88
</section>
9+
10+
<div>
11+
<h3>Posts</h3>
12+
{{posts}}
13+
</div>
14+
<br>
15+
<br>
16+
<br>
17+
<div>
18+
<h3>Likes</h3>
19+
{{likes}}
20+
</div>
921
</div>

client/scripts/controllers/DashboardCtrl.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,29 @@
22
'use strict';
33

44
angular.module('frontendEngineeringChallengeApp')
5-
.controller('DashboardCtrl', function ($scope) {
5+
.controller('DashboardCtrl', function ($scope, $rootScope, $timeout, LocalService) {
6+
7+
// Attempt to get past records to display in our spreadsheet
8+
LocalService.getLikes();
9+
LocalService.getPosts();
10+
11+
//***** Listeners *****//
12+
13+
$rootScope.$on('local-posts-data-received', function(){
14+
// Moves up the call stack instead of using $scope.apply()
15+
$timeout(function(){
16+
$scope.posts = LocalService.posts();
17+
});
18+
});
19+
20+
$rootScope.$on('local-likes-data-received', function(){
21+
// Moves up the call stack instead of using $scope.apply()
22+
$timeout(function(){
23+
$scope.likes = LocalService.likes();
24+
});
25+
});
26+
627

7-
$scope.hello = 'This is a hello dictated by the DASHBOARD controller';
828

929
});
1030
}(window.angular));
Lines changed: 122 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,125 @@
11
// This service allows us to persist information to our own MongoDB
22

3-
(function(angular){
4-
5-
angular.module('frontendEngineeringChallengeApp')
6-
.service('LocalService', function($http, $q, $rootScope){
7-
8-
// Initializations
9-
var spreadsheetObj = [];
10-
11-
12-
function handleError(response) {
13-
// todo: Handle Errors
14-
console.log('handling error for our own data persistance');
15-
}
16-
17-
function handleSuccess(response) {
18-
console.log('successly received spreadsheet object');
19-
20-
// Return spreadsheet array for our admin view
21-
spreadsheetObj = response.data;
22-
23-
// Finally, broadcast a singular data-received event
24-
$rootScope.$broadcast('spreadsheet-data');
25-
}
26-
27-
function postData(url, dataObj){
28-
var request = $http({
29-
method: "post",
30-
url: url,
31-
params: {
32-
action: "post"
33-
},
34-
35-
data: dataObj
36-
});
37-
}
38-
39-
// Expose Local Methods for our own Data Peristence
40-
return {
41-
spreadsheet: function spreadsheet(){
42-
return spreadsheetObj;
43-
},
44-
// Pulls Data For Posts and Likes
45-
getRecords: function getRecords(getRecords){
46-
var request = $http({
47-
method: "get",
48-
url: '/records',
49-
params: {
50-
action: "get"
51-
}
52-
});
53-
54-
return( request.then(handleSuccess, handleError) )
55-
},
56-
57-
postRecord: function postRecord(recordObj){
58-
var url = '/record';
59-
60-
postData(url, recordObj);
61-
},
62-
// Post the incoming Post Data
63-
postPostData: function postPostData(postObj){
64-
var url = '/post';
65-
66-
postData(url, postObj);
67-
},
68-
// Post the incoming Like Data
69-
postLikeData: function postLikeData(likeObj){
70-
var url = '/like';
71-
72-
postData(url, likeObj);
73-
}
74-
}
75-
});
3+
(function(angular) {
4+
5+
angular.module('frontendEngineeringChallengeApp')
6+
.service('LocalService', function($http, $q, $rootScope) {
7+
8+
// Initializations
9+
var spreadsheetObj = [];
10+
var postsObj = {};
11+
var likesObj = {};
12+
13+
14+
function handleError(response) {
15+
// todo: Handle Errors
16+
console.log('handling error for our own data persistance');
17+
}
18+
19+
function handleSuccess(response) {
20+
console.log('successly received spreadsheet object');
21+
22+
// Return spreadsheet array for our admin view
23+
spreadsheetObj = response.data;
24+
25+
// Finally, broadcast a singular data-received event
26+
$rootScope.$broadcast('spreadsheet-data');
27+
}
28+
function handlePostsSuccess(response) {
29+
console.log('successly received posts object');
30+
31+
// Return spreadsheet array for our admin view
32+
postsObj = response.data;
33+
$rootScope.$broadcast('local-posts-data-received');
34+
}
35+
36+
function handleLikesSuccess(response) {
37+
console.log('successly received likes object');
38+
39+
// Return spreadsheet array for our admin view
40+
likesObj = response.data;
41+
$rootScope.$broadcast('local-likes-data-received');
42+
}
43+
44+
function postData(url, dataObj) {
45+
var request = $http({
46+
method: "post",
47+
url: url,
48+
params: {
49+
action: "post"
50+
},
51+
52+
data: dataObj
53+
});
54+
}
55+
56+
// Expose Local Methods for our own Data Peristence
57+
return {
58+
spreadsheet: function spreadsheet() {
59+
return spreadsheetObj;
60+
},
61+
// Pulls Data For Posts and Likes
62+
getRecords: function getRecords() {
63+
var request = $http({
64+
method: "get",
65+
url: '/records',
66+
params: {
67+
action: "get"
68+
}
69+
});
70+
71+
return ( request.then(handleSuccess, handleError) )
72+
},
73+
74+
getPosts: function getPosts() {
75+
var request = $http({
76+
method: "get",
77+
url: '/posts',
78+
params: {
79+
action: "get"
80+
}
81+
});
82+
83+
return ( request.then(handlePostsSuccess, handleError) )
84+
},
85+
86+
getLikes: function getLikes() {
87+
var request = $http({
88+
method: "get",
89+
url: '/likes',
90+
params: {
91+
action: "get"
92+
}
93+
});
94+
95+
return ( request.then(handleLikesSuccess, handleError) )
96+
},
97+
98+
postRecord: function postRecord(recordObj) {
99+
var url = '/record';
100+
101+
postData(url, recordObj);
102+
},
103+
// Post the incoming Post Data
104+
postPostData: function postPostData(postObj) {
105+
var url = '/post';
106+
107+
postData(url, postObj);
108+
},
109+
// Post the incoming Like Data
110+
postLikeData: function postLikeData(likeObj) {
111+
var url = '/like';
112+
113+
postData(url, likeObj);
114+
},
115+
116+
posts: function posts(){
117+
return postsObj;
118+
},
119+
120+
likes: function likes(){
121+
return likesObj;
122+
}
123+
}
124+
});
76125
}(window.angular));

server/routes.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ module.exports = function(app) {
3232

3333
});
3434

35+
app.get('/posts', function(req, res){
36+
37+
var posts = Post.find()
38+
.exec(function(err, posts){
39+
// create the json data for our API endpoint
40+
res.json({
41+
posts: posts
42+
});
43+
});
44+
45+
});
46+
47+
app.get('/likes', function(req, res){
48+
49+
var likes = Like.find()
50+
.exec(function(err, likes){
51+
// create the json data for our API endpoint
52+
res.json({
53+
likes: likes
54+
});
55+
});
56+
57+
});
58+
3559
app.post('/record', function(req, res){
3660
var id = req.body.id;
3761
var time = req.body.time;

0 commit comments

Comments
 (0)