diff --git a/browser/js/allOrders/allOrdersCtrl.controller.js b/browser/js/allOrders/allOrdersCtrl.controller.js index 9e706cf..d013956 100644 --- a/browser/js/allOrders/allOrdersCtrl.controller.js +++ b/browser/js/allOrders/allOrdersCtrl.controller.js @@ -1,11 +1,11 @@ app.controller('AllOrdersCtrl', function($scope, orders, users){ $scope.orders = orders; $scope.users = users; - + $scope.categories = [ 'All', - 'Created', - 'Processing', + 'Created', + 'Processing', 'Cancelled', 'Completed' ]; @@ -13,15 +13,16 @@ app.controller('AllOrdersCtrl', function($scope, orders, users){ $scope.status = { isopen: false }; - + $scope.chooseCategory = function(category){ if(category === 'All') delete $scope.category; - else $scope.category = category; + else $scope.category = category; }; +// what's this for? $scope.toggleDropdown = function($event) { $event.preventDefault(); $event.stopPropagation(); $scope.status.isopen = !$scope.status.isopen; }; -}); \ No newline at end of file +}); diff --git a/browser/js/common/factories/order.factory.js b/browser/js/common/factories/order.factory.js index 9bb542f..591eb79 100644 --- a/browser/js/common/factories/order.factory.js +++ b/browser/js/common/factories/order.factory.js @@ -1,17 +1,20 @@ app.factory('Order', function(DS) { var Order = DS.defineResource({ name: 'order' - }); + }); Order.byUser = function(id) { console.log(id); + this.find('me', {isArray:true}) // /api/order/me + + return this.findAll() - .then(function(orders) { + .then(function(orders) { // maybe filter on the server return orders.filter(function(order) { return id === order.user; }); }); - + }; return Order; - -}).run(function(Order) {}); \ No newline at end of file + +}).run(function(Order) {}); diff --git a/browser/js/home/home.state.js b/browser/js/home/home.state.js index f44a27e..c98d2bb 100644 --- a/browser/js/home/home.state.js +++ b/browser/js/home/home.state.js @@ -16,10 +16,10 @@ app.config(function ($stateProvider) { url: '/', templateUrl: 'js/home/home.html', resolve: { - animals: function(Animal, $stateParams) { + animals: function(Animal, $stateParams) { // why state params return Animal.findAll(); } }, controller: 'HomeCtrl' }); -}); \ No newline at end of file +}); diff --git a/browser/js/shopping-cart/shoppingcart.factory.js b/browser/js/shopping-cart/shoppingcart.factory.js index 082519e..be96261 100644 --- a/browser/js/shopping-cart/shoppingcart.factory.js +++ b/browser/js/shopping-cart/shoppingcart.factory.js @@ -1,7 +1,8 @@ app.factory('Cart', function(DS, $state, $http) { - + // why isn't this file kabob case? + var baseUrl = '/api/cart/me/'; - + function toData(response) { return response.data; } @@ -12,24 +13,32 @@ app.factory('Cart', function(DS, $state, $http) { me: { method: 'GET', isArray: false - } + } }, relations: { hasOne: { user: { localField: 'user', - foreignKey: 'user' + foreignKey: 'user' // that's not what that does I don't think } } + }, + methods: { + cartUpdate: function() { + return this.update(this.data) + .then(toData) + } } }); - + Cart.update = function(cart) { + // methodsssss return $http.put(baseUrl, cart.data) .then(toData); }; - + Cart.matchToAnimals = function(animals, cart) { + // I'm confuzed var matchedCart = cart.map(function(item) { var matched = animals.reduce(function(match, animal) { if(animal._id === item.animal) { @@ -38,11 +47,21 @@ app.factory('Cart', function(DS, $state, $http) { } else return match; },{}); - return matched; - }); + return matched; + }); return matchedCart; }; - - +[{animal: idthing, quantity:17}] +[{name:'Bill Murray', quantity:17}] +cart = animals.filter(function(animal) { + var cartItem = _.find(cart, function(item) { + return item._id === animal._id; + }) + if (!cartItem) return false; + animal.quantity = cartItem.quantity; + return true; +}) + + return Cart; -}).run(function (Cart) {}) \ No newline at end of file +}).run(function (Cart) {}) diff --git a/browser/js/users/users.controller.js b/browser/js/users/users.controller.js index 58b43b4..0f10b25 100644 --- a/browser/js/users/users.controller.js +++ b/browser/js/users/users.controller.js @@ -1,14 +1,16 @@ app.controller('UsersCtrl', function($scope, User, users) { $scope.users = users; + + // you could do $scope.promoteToAdmin = User.promote; $scope.promoteToAdmin = function(id) { User.promote(id); }; - + $scope.deleteUser = function(id) { User.destroy(id); }; - + $scope.triggerReset = function(id) { - User.triggerReset(id); + User.triggerReset(id); }; -}); \ No newline at end of file +}); diff --git a/browser/js/users/users.factory.js b/browser/js/users/users.factory.js index b62449d..68679bc 100644 --- a/browser/js/users/users.factory.js +++ b/browser/js/users/users.factory.js @@ -3,31 +3,33 @@ app.factory('User', function(DS, $http) { function toData (response) { return response.data; } - + var User = DS.defineResource({ name: 'users', relations: { hasMany: { order: { - localField: 'userOrders', + localField: 'userOrders', // why not orders? foreignKey: 'user' } - } + } } }); - + User.promote = function(id) { + // these should be methods + // this.update(data, {suffix: '/admin', method:'POST'}) return $http.post(baseUrl + id + '/admin') .then(toData); }; - + User.triggerReset = function(id) { - return $http.post(baseUrl + id + '/triggerReset') + return $http.post(baseUrl + id + '/triggerReset') }; - + User.reset = function(id, password){ - return $http.post(baseUrl + id + '/reset', password); + return $http.post(baseUrl + id + '/reset', password); }; - + return User; -}).run(function (User) {}); \ No newline at end of file +}).run(function (User) {});