Skip to content

Commit

Permalink
Prepared Food Controller for proper JSON syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Rogan committed Feb 18, 2017
1 parent 68161f2 commit 8337f3e
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 204 deletions.
36 changes: 19 additions & 17 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
var app = angular.module('app', ['ngRoute', 'ngResource']);
var app = angular.module('app', ['ngRoute', 'ngResource', 'ngCookies']);

// Root controllers in /root/ folder
// Page controllers in /pages/[your-page] folder

// Factories

// TODO: 'Foods' factory TEMPORARY
app.factory('Foods', function($resource) {
return $resource('assets/json/foods.json');
});

// Just does a PUT request when u call Food.update
app.factory('Food', function ($resource) {
// {food: '@id'} means replace :food with $scope.foodCRUD.id
var data = $resource('http://foodbank.develop.digitalmediauconn.org/api/food/:food', {food: '@id'}, {
update:{ method:'PUT' }
});
return data;
});
// app.factory('FoodDetail', function($resource) {
// return $resource('assets/json/foodDetail.json');
// });

app.factory('Categories', function($resource) {
return $resource('assets/json/categories.json');
});

// TODO: 'Nutrients' factory TEMPORARY
app.factory('Nutrients', function($resource) {
return $resource('assets/json/nutrients.json');
});

app.factory('Nutrient', function ($resource) {
var data = $resource('http://foodbank.develop.digitalmediauconn.org/api/nutrients/:nutrient', {nutrient: '@id'}, {
update:{ method:'PUT' }
});
return data;
});
// Just does a PUT request when u call Food.update
// app.factory('Food', function ($resource) {
// // {food: '@id'} means replace :food with $scope.foodCRUD.id
// var data = $resource('http://foodbank.develop.digitalmediauconn.org/api/food/:food', {food: '@id'}, {
// update:{ method:'PUT' }
// });
// return data;
// });

// app.factory('Nutrient', function ($resource) {
// var data = $resource('http://foodbank.develop.digitalmediauconn.org/api/nutrients/:nutrient', {nutrient: '@id'}, {
// update:{ method:'PUT' }
// });
// return data;
// });
95 changes: 57 additions & 38 deletions app/pages/food/ctrl.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'Food', 'Categories', function ($scope, $http, Foods, Food, Categories) {
app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'Categories', '$cookies', function ($scope, $http, Foods, Categories, $cookies) {
$scope.page.title = 'Food';
$scope.page.id = 'food';

// Cookie for Table/Card view prefence
$scope.tableView = $cookies.get('showTable') === 'true';
$scope.$watch('tableView', function () {
$cookies.put('showTable', $scope.tableView ? 'true' : 'false');
});

// Initialize Filters
$scope.foods = [];
$scope.categories = [];
$scope.rankSelection = {
"green": true,
"yellow": true,
"red": true,
"gray": true
"1": true,
"2": true,
"3": true,
"4": true
};
$scope.categorySelection = { "all": true };
$scope.searchTerm = "";



// Initialize CRUD modes
$scope.editMode = false;
$scope.createMode = false;

// Initialize CRUD form
$scope.foodCRUD = {};

Expand All @@ -42,7 +42,6 @@ app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'Food', 'Categories', fu
});



// Set category filters to false
$scope.resetCategorySelection = function () {
$scope.categories.forEach(function(c){
Expand All @@ -51,43 +50,63 @@ app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'Food', 'Categories', fu
}
// Category filter function
$scope.categoryFilter = function (food) {
return ( $scope.categorySelection[food.category_id] | $scope.categorySelection["all"] );
return ( $scope.categorySelection[food.category.id] | $scope.categorySelection["all"] );
}
// Rank filter function
$scope.rankFilter = function (food) {
return ( $scope.rankSelection[food.rank_id] );
return ( $scope.rankSelection[food.rank.id] );
}



// CRUD: edit food
$scope.edit = function (foodToEdit) {
$scope.editMode = true;
$scope.foodCRUD = foodToEdit;
$scope.foodCRUD.action = "update";
// console.log($scope.foodCRUD);
};

// CRUD: create food
$scope.create = function () {
$scope.createMode = true;
$scope.foodCRUD = {};
$scope.foodCRUD.rank_mode = "auto";
$scope.foodCRUD.action = "create";
// console.log($scope.foodCRUD);
// Modal : View Food
$scope.view = function (foodToView) {
$scope.showModal = true;
$scope.foodCRUD = foodToView;
};

// CRUD: cancel
// Modal : Cancel
$scope.cancel = function () {
$scope.editMode = false;
$scope.createMode = false;
$scope.showModal = false;
};

// CRUD: POST
$scope.submit = function () {
$scope.cancel(); // hide modal
Food.update($scope.foodCRUD);
};
// NOTE: End of code for now





// Initialize CRUD modes
// $scope.editMode = false;
// $scope.createMode = false;

// CRUD: edit food
// $scope.edit = function (foodToEdit) {
// $scope.editMode = true;
// $scope.foodCRUD = foodToEdit;
// $scope.foodCRUD.action = "update";
// console.log($scope.foodCRUD);
// };
//
// // CRUD: create food
// $scope.create = function () {
// $scope.createMode = true;
// $scope.foodCRUD = {};
// $scope.foodCRUD.rank_mode = "auto";
// $scope.foodCRUD.action = "create";
// // console.log($scope.foodCRUD);
// };
//
// // CRUD: cancel
// $scope.cancel = function () {
// $scope.editMode = false;
// $scope.createMode = false;
// };
//
// // CRUD: POST
// $scope.submit = function () {
// $scope.cancel(); // hide modal
// Food.update($scope.foodCRUD);
// };


}]);
61 changes: 53 additions & 8 deletions app/pages/food/style.styl
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@



// Table view




.foods
display: flex
Expand Down Expand Up @@ -113,13 +109,13 @@
background-color: purple
i
color: white
.rank-green
.rank-1
background-color: green
.rank-yellow
.rank-2
background-color: yellow
.rank-red
.rank-3
background-color: red
.rank-gray
.rank-4
background-color: gray


Expand Down Expand Up @@ -157,6 +153,7 @@
font-size: 1.1em
padding: 1em
border: 1px solid lightgray
min-width 300px
my-box-shadow()
background: white
[type="radio"]:not(:checked)+label, [type="radio"]:checked+label
Expand All @@ -171,6 +168,9 @@
font-weight: 500
color: #BBB
margin-bottom: 5px
span
color initial
font-weight normal
a.btn
width: 48%
.orange
Expand All @@ -183,3 +183,48 @@
td:first-child
font-weight: 500
width: 50%



// Table view
.foodTable
display flex
flex-flow: row wrap;
align-content: stretch;
width 100%

.foodTableItem
display inline-flex
flex 1 430px
margin-bottom 12px
font-size 1.2em
align-items center
margin-right 1em
padding-right 1em
background #f5f5f5
+above(760px)
max-width calc(50% - 1em)
transition: all .2s
cursor: pointer
my-box-shadow()
&:hover
transform: scale(.95)
span
flex-basis 100px
margin-right 1em
.name
flex-basis 140px
.barcode
color #888
font-size 1rem
text-align right
margin-right 0
.health
height 35px
width @height
min-height @height
min-width @height
max-height @height
max-width @height
i
font-size 21px
Loading

0 comments on commit 8337f3e

Please sign in to comment.