Last active
August 29, 2015 14:11
-
-
Save got5/b1ea055510464e3a5dc2 to your computer and use it in GitHub Desktop.
Slide 110 directives_use_tp TP7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.getRatingClass = ProductUtils.getRatingCss; | |
$scope.addToCart = function(pItem){ | |
UserService.addToCart(pItem,1); | |
$location.path('/basket'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<article class="k-product hproduct" ng-repeat="product in products"> | |
<div class="photo-data"> | |
<p> | |
<a ng-href="#/book/{{product.id}}"> | |
<img class="photo" ng-src="img/catalog/{{product.id}}.jpg" /> | |
</a> | |
</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p class="extra new" ng-if="product.isNew">new</p> | |
<h3 class="fn name"> | |
<a ng-href="#/book/{{product.id}}" title="See Product sheet">{{product.name}}</a> | |
</h3> | |
<p ng-class="getRatingClass(product)"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span ng-show="product.comments"> | |
<a href="#comments">{{product.comments.length}} comment(s)</a> | |
</span> | |
<span ng-hide="product.comments"> | |
No comment | |
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="price-data"> | |
<p class="all-prices"> | |
<strong class="price new">{{product.price | currency}}</strong> | |
</p> | |
</div> | |
<div class="buyZone"> | |
<p class="buy"> | |
<a href="#/basket" ng-click="addToCart(product)">Add to basket</a> | |
</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.controller('BasketController', ['$scope', 'UserService', 'User' , function ($scope, UserService) { | |
$scope.items = UserService.getCurrentUser().cart.getItems(); | |
$scope.nbItems = $scope.items.length; | |
$scope.getTotal = function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var UserService = function ($http, $q, $log, $cookies, $cookieStore, User, isDebugMode) { | |
/** Currently logged user. */ | |
var currentUser = null; | |
var saveCurrentUser = function(){ | |
$cookieStore.put('cart',currentUser.cart.getItems()); | |
$cookieStore.put('user',currentUser); | |
}; | |
this.getCurrentUser = function () { | |
if (!currentUser) { | |
currentUser = $cookieStore.get('user'); | |
if (!currentUser) { | |
currentUser = User.createUser(); | |
saveCurrentUser(); | |
}else{ | |
currentUser.cart = User.createCart($cookieStore.get('cart')); | |
} | |
} | |
return currentUser; | |
}; | |
/** Add an item with a given quantity in the user basket. */ | |
this.addToCart = function (pItem, pQty) { | |
this.getCurrentUser().cart.setItemQty(pItem, pQty); | |
saveCurrentUser(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.controller('CatalogController', ['$scope', '$location', 'catalogService','ProductUtils', 'UserService', function ($scope, $location, catalogService, ProductUtils, UserService) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment