-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some initial angular controllers/services and connected UI up t…
…o API for some really basic product info.
- Loading branch information
john
committed
Apr 23, 2014
1 parent
bca3e44
commit f4eda23
Showing
20 changed files
with
189 additions
and
76 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#main-container{ | ||
margin-top:60px; | ||
|
||
} | ||
|
||
#basket-table{ | ||
width:100%; | ||
} | ||
|
||
|
||
#basket-table tr:nth-child(2n) td{ | ||
background-color:#efefef; | ||
} | ||
|
||
#basket-table th, | ||
#basket-table td{ | ||
padding:5px; | ||
} | ||
|
||
|
File renamed without changes
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
// public/js/appRoutes.js | ||
angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { | ||
|
||
|
||
$routeProvider | ||
.when('/', { | ||
templateUrl: '/views/product-list.html', | ||
controller: 'ProductListController' | ||
}) | ||
.when('/product/:id', { | ||
templateUrl: '/views/product-details.html', | ||
controller: 'ProductDetailsController' | ||
}) | ||
.when('/basket', { | ||
templateUrl: '/views/basket.html', | ||
controller: 'BasketController' | ||
}); | ||
|
||
$locationProvider.html5Mode(true); | ||
|
||
}]); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
|
||
angular.module('BasketCtrl', []).controller('BasketController', function($scope, Products) { | ||
Products.getAll(function(data){ | ||
$scope.products = data; | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
angular.module('ProductDetailsCtrl', []).controller('ProductDetailsController', function($scope, $routeParams, Products) { | ||
var id = $routeParams.id; | ||
Products.getOne(id, function(data){ | ||
$scope.product=data; | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
|
||
angular.module('ProductListCtrl', []).controller('ProductListController', function($scope, Products) { | ||
Products.getAll(function(data){ | ||
$scope.products = data; | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
angular.module('ProductService', []).factory('Products', ['$http', function($http) { | ||
|
||
return { | ||
getAll: function(callback) { | ||
$http({ | ||
method: 'get', | ||
url: '/api/products' | ||
}).success(function(data) { | ||
//console.log(data); | ||
callback(data); | ||
}).error(function() { | ||
alert("error"); | ||
}); | ||
}, | ||
|
||
getOne : function(id, callback) { | ||
$http({ | ||
method: 'get', | ||
url: '/api/products/'+id | ||
}).success(function(data) { | ||
//console.log(data); | ||
callback(data); | ||
}).error(function() { | ||
alert("error"); | ||
}); | ||
} | ||
|
||
// , | ||
// | ||
// create : function(productData) { | ||
// return $http.post('/api/products', productData); | ||
// }, | ||
// | ||
// delete : function(id) { | ||
// return $http.delete('/api/products/' + id); | ||
// } | ||
}; | ||
|
||
}]); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<table id="basket-table"> | ||
<thead> | ||
<tr> | ||
<th>Product</th> | ||
<th>Qty</th> | ||
<th>Price</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Product #1</td> | ||
<td>1</td> | ||
<td>£10.00</td> | ||
</tr> | ||
<tr> | ||
<td>Product #2</td> | ||
<td>1</td> | ||
<td>£10.00</td> | ||
</tr> | ||
<tr> | ||
<td>Product #3</td> | ||
<td>1</td> | ||
<td>£10.00</td> | ||
</tr> | ||
<tr> | ||
<td colspan="2" align="right">Total</td> | ||
<td>£30.00</td> | ||
|
||
</tr> | ||
</tbody> | ||
</table> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
<form> | ||
<div class="row"> | ||
<div class="col-md-9" > | ||
<img src="/img/horse524.jpg" alt="A horse" style="width:100%;" /> | ||
</div> | ||
|
||
<div class="col-md-3" > | ||
<h1>{{product.Name}}</h1> | ||
<select> | ||
<option value="">Qty</option> | ||
<option data-ng-repeat="i in [1,2,3,4,5,6,7,8,9,10]">{{i}}</option> | ||
</select> | ||
<input type="submit" value="Add to basket" /> | ||
</div> | ||
</div> | ||
</form> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h1>product list </h1> | ||
<div class="col-sm-3" data-ng-repeat="i in products"> | ||
<form> | ||
<a href="/product/{{i._id}}"> | ||
<img src="/img/horse524.jpg" alt="A horse" style="width:100%;" /></a> | ||
<p>{{i.Name}} : {{_id}}</p> | ||
<select> | ||
<option value="">Qty</option> | ||
<option data-ng-repeat="j in [1,2,3,4,5,6,7,8,9,10]">{{j}}</option> | ||
</select> | ||
<input type="submit" value="Add to basket" /> | ||
</form> | ||
</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