Skip to content

Commit

Permalink
JS4: Client-Server Communication and Angular Testing
Browse files Browse the repository at this point in the history
- Post feedback to store in db
- Replace data sources with ngResource
  • Loading branch information
yogykwan committed May 14, 2017
1 parent afc5113 commit afa3c14
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 59 deletions.
12 changes: 8 additions & 4 deletions app/scripts/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ angular.module('confusionApp')

}])

.controller('FeedbackController', ['$scope', function ($scope) {
.controller('FeedbackController', ['$scope', 'feedbackFactory', function ($scope, feedbackFactory) {
$scope.sendFeedback = function () {

console.log($scope.feedback);
Expand All @@ -69,6 +69,8 @@ angular.module('confusionApp')
console.log('incorrect');
}
else {
feedbackFactory.getFeedback().save($scope.feedback);

$scope.invalidChannelSelection = false;
$scope.feedback = {mychannel: "", firstName: "", lastName: "", agree: false, email: ""};
$scope.feedback.mychannel = "";
Expand Down Expand Up @@ -133,11 +135,13 @@ angular.module('confusionApp')
}
);

$scope.promotion = menuFactory.getPromotion(0);
$scope.leader = corporateFactory.getLeader(0);
$scope.promotion = menuFactory.getPromotions().get({id: 0});

$scope.leader = corporateFactory.getLeaders().get({id: 0});

}])

.controller('AboutController', ['$scope', 'corporateFactory', function ($scope, corporateFactory) {
$scope.leaders = corporateFactory.getLeaders();
$scope.leaders = corporateFactory.getLeaders().query();
}])
;
66 changes: 13 additions & 53 deletions app/scripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,30 @@ angular.module('confusionApp')
return $resource(baseURL + "dishes/:id", null, {'update': {method: 'PUT'}});
};

var promotions = [
{
_id: 0,
name: 'Weekend Grand Buffet',
image: 'images/buffet.png',
label: 'New',
price: '19.99',
description: 'Featuring mouthwatering combinations with a choice of five different salads, six enticing appetizers, six main entrees and five choicest desserts. Free flowing bubbly and soft drinks. All for just $19.99 per person ',
}

];

this.getPromotion = function (index) {
return promotions[index];
this.getPromotions = function () {
return $resource(baseURL + "promotions/:id", null);
};

}])

.factory('corporateFactory', function () {
.factory('corporateFactory', ['$resource', 'baseURL', function ($resource, baseURL) {

var corpfac = {};

var leadership = [
{
name: "Peter Pan",
image: 'images/alberto.png',
designation: "Chief Epicurious Officer",
abbr: "CEO",
description: "Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which The Frying Pan became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural culinary connections."
},
{
name: "Dhanasekaran Witherspoon",
image: 'images/alberto.png',
designation: "Chief Food Officer",
abbr: "CFO",
description: "Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties of food sources. As he puts it in his own words, Everything that runs, wins, and everything that stays, pays!"
},
{
name: "Agumbe Tang",
image: 'images/alberto.png',
designation: "Chief Taste Officer",
abbr: "CTO",
description: "Blessed with the most discerning gustatory sense, Agumbe, our CFO, personally ensures that every dish that we serve meets his exacting tastes. Our chefs dread the tongue lashing that ensues if their dish does not meet his exacting standards. He lives by his motto, You click only if you survive my lick."
},
{
name: "Alberto Somayya",
image: 'images/alberto.png',
designation: "Executive Chef",
abbr: "EC",
description: "Award winning three-star Michelin chef with wide International experience having worked closely with whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences. He says, Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!"
}

];

corpfac.getLeaders = function () {
return leadership;
};

corpfac.getLeader = function (index) {
return leadership[index];
return $resource(baseURL + "leadership/:id", null);
};

return corpfac;

})
}])

.service('feedbackFactory', ['$resource', 'baseURL', function ($resource, baseURL) {

this.getFeedback = function () {
return $resource(baseURL + "feedback/:id", null, {'update': {method: 'PUT'}});
};

}])

;
18 changes: 16 additions & 2 deletions json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,19 @@
"description": "Award winning three-star Michelin chef with wide International experience having worked closely with whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences. He says, Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!"
}
],
"feedback": []
}
"feedback": [
{
"mychannel": "Email",
"firstName": "1",
"lastName": "1",
"agree": true,
"email": "1@1",
"tel": {
"areaCode": "1",
"number": "1"
},
"comments": "1",
"id": 1
}
]
}

0 comments on commit afa3c14

Please sign in to comment.