Skip to content

Instantly share code, notes, and snippets.

@ryanlanciaux ryanlanciaux/app.js
Created Aug 17, 2013

What would you like to do?
var foodApp = angular.module('foodApp', ['ngResource']);
foodApp.factory('Food', ['$resource', function($resource){
return $resource('/food/:id', {id:'@id'}, { update: {method:'PUT' } } );
foodApp.config(['$routeProvider', function($routeProvider) {
.when('/food', {templateUrl: '/templates/list.html', controller: FoodController})
.when('/food/edit/:id', {templateUrl: '/templates/edit.html', controller: FoodController})
.when('/food/create', {templateUrl: '/templates/edit.html', controller: FoodController})
.when('/food/:id', {templateUrl: '/templates/detail.html', controller: FoodController})
.otherwise({redirectTo: '/food'});
function FoodController($scope, $routeParams, $location, Food){
$scope.sort = "name";
$scope.reverse = false;
$scope.currentFood = Food.get({id: $});
} else {
$scope.currentFood = new Food();
$ = Food.query();
$scope.changeSort = function(value){
if ($scope.sort == value){
$scope.reverse = !$scope.reverse;
$scope.sort = value;
$scope.reverse = false;
$scope.addFood = function(){
if ($ && $ != 0){
Food.get({id: $}, function(food){
food.type = $scope.currentFood.type; = $;
food.percentRemaining = $scope.currentFood.percentRemaining;
food.quantity = $scope.currentFood.quantity;
food.$update({}, function(){
$location.path( "/" );
} else {
$location.path( "/" );
<a href="#/food/">Back</a> |
<a href="#/food/edit/{{}}">Edit</a>
<div class="row">
<div class="span3">{{currentFood.type}}</div>
<div class="span3">{{currentFood.expiration}}</div>
<div class="span3">{{currentFood.quantity}}</div>
<div class="row">
<div class="span12 progress">
<div class="bar" style="width: {{currentFood.percentRemaining}}%"></div>
<label for="name">Name:</label>
<input name="name" ng-model="" />
<br />
<label for="type">Type:</label>
<input name="type" ng-model="currentFood.type" />
<br />
<label for="expiration">Expiration</label>
<input name="expiration" ng-model="currentFood.expiration" />
<br />
<label for="quantity">Quantity</label>
<input name="quantity" ng-model="currentFood.quantity" />
<br />
<label for="percentRemaining">Percent Remaining</label>
<input name="percentRemaining" ng-model="currentFood.percentRemaining" /><br />
<div class="span4 text-right">
<div class="row">
<a href='#/food' class="btn">Cancel</a>
<button ng-click="addFood()" class='btn btn-primary'>Add</button>
<h1 id="header">
Food Inventory
<div ng-view></div>
<div id="footer">
<a target="_blank" href="" class="copyright">Built with Sails.js</a>
<style type="text/css">
label { width: 150px; display:inline-block; text-align:right; }
button { margin-right: 10px;}
.text-right { text-align: right;}
<div class="filter">
<label for="filter">filter:</label>
<input type="text" name="filter" ng-model="filter" />
<tr class="row">
<th><a ng-click="changeSort('name')">Name</a></th>
<th><a ng-click="changeSort('type')">Type</a></th>
<th><a ng-click="changeSort('expiration')">Expiration</a></th>
<th><a ng-click="changeSort('quantity')">Quantity</a></th>
<th><a ng-click="changeSort('percentRemaining')">Percent Remaining</a></th>
<tr class="row" ng-repeat="f in food | filter:filter | orderBy:sort:reverse">
<td><a href="#/food/{{}}">{{}}</a></td>
<td class="progress"><div class="bar" style="width: {{f.percentRemaining}}%"></div></td>
<br /> <a href='/#food/create'>Create</a></br /><br />

This comment has been minimized.

Copy link

commented Apr 27, 2014

Having trouble here. Using Sails 0.10.0-rc5 and not getting any views to show.


This comment has been minimized.

Copy link

commented Apr 30, 2014

Figured it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.