From 6e028a0cc07f0976039260da6b4a093e70e822b6 Mon Sep 17 00:00:00 2001 From: Joel Salisbury Date: Mon, 13 Feb 2017 14:52:01 -0500 Subject: [PATCH 01/11] dem rules --- api/routes/rules.php | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/api/routes/rules.php b/api/routes/rules.php index f18979a..8aca038 100644 --- a/api/routes/rules.php +++ b/api/routes/rules.php @@ -48,7 +48,59 @@ $newRule->setRankId($rank); $newRule->setNutrientId($nutrient); - $newRule->save(); + if($newRule->save()){ + $msg = "New Rule Saved"; + } else { + $msg = "There was an error saving this rule"; + } + + + + $response_json = [ + "status" => [ + "code" => $response->getStatusCode(), + "message" => [$msg] + ] + ]; + + $response = $response->withJSON($response_json); + return $response; + + +}); + +$app->post('/rules/updateRuleById/{ruleId}', function($request, $response) { + + $rule = CategoryRankNutrientQuery::create()->findPk($request->getAttribute("ruleId")); + print_r($rule); + $cat = $request->getParam('catId'); + $nutrient = $request->getParam('nutrientId'); + + $rank = $request->getParam('rankId'); + + + $rule->setThreshold($request->getParam('threshold')); + $rule->setUnits($request->getParam('units')); + $rule->setOperator($request->getParam('operator')); + $rule->setCategoryId($cat); + $rule->setRankId($rank); + $rule->setNutrientId($nutrient); + + if($rule->save()){ + $msg = "Rule updated."; + } else { + $msg = "There was an error saving this rule"; + } + + + $response_json = [ + "status" => [ + "code" => $response->getStatusCode(), + "message" => [$msg] + ] + ]; + $response = $response->withJSON($response_json); + return $response; }); \ No newline at end of file From 4b6c475c3f79347685136433d5b35cf64c85c57e Mon Sep 17 00:00:00 2001 From: Joel Salisbury Date: Thu, 16 Feb 2017 17:19:53 -0500 Subject: [PATCH 02/11] category all --- api/routes/category.php | 23 ++++++++++++++++++++++- api/routes/rules.php | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/api/routes/category.php b/api/routes/category.php index cb5856e..1122017 100644 --- a/api/routes/category.php +++ b/api/routes/category.php @@ -7,6 +7,11 @@ $app->get('/category/all', function( $request, $response ) { $q = new CategoryQuery; $cats = $q::create()->find(); + + + + + $response_json = [ "status" => [ "code" => $response->getStatusCode(), @@ -15,9 +20,25 @@ "data" => [] ]; foreach( $cats as $cat ) { + + $q = new CategoryRankNutrientQuery; + $requestedCatRules = $q->filterByCategoryId($cat->getId())->find(); + foreach($requestedCatRules as $rule) { + $rules[] = [ + "nutrientName" => $rule->getNutrient()->getName(), + "nutrientId" => $rule->getNutrient()->getId(), + "operator" => $rule->getOperator(), + "threshold" => $rule->getThreshold(), + "units" => $rule->getUnits(), + "rank" => $rule->getRankId() + ]; + } + + $response_json["data"][] = [ "id" => $cat->getId(), - "name" => $cat->getName() + "name" => $cat->getName(), + "rules" => $rules ]; } $response = $response->withJSON($response_json); diff --git a/api/routes/rules.php b/api/routes/rules.php index 8aca038..0b81736 100644 --- a/api/routes/rules.php +++ b/api/routes/rules.php @@ -72,7 +72,7 @@ $app->post('/rules/updateRuleById/{ruleId}', function($request, $response) { $rule = CategoryRankNutrientQuery::create()->findPk($request->getAttribute("ruleId")); - print_r($rule); + $cat = $request->getParam('catId'); From f7002de8536815ce3e0ea66a6e2de06e8307eae0 Mon Sep 17 00:00:00 2001 From: Joel Salisbury Date: Thu, 16 Feb 2017 17:29:35 -0500 Subject: [PATCH 03/11] yay --- api/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/index.php b/api/index.php index 2dc475c..7475b8e 100644 --- a/api/index.php +++ b/api/index.php @@ -1,5 +1,5 @@ add('', __DIR__ . '/generated-classes/'); // Propel ORM Classes require './generated-conf/config.php'; // Propel Config From 295b3a2cf34eb8127a5e5ca9257a91792c3dc560 Mon Sep 17 00:00:00 2001 From: Joel Salisbury Date: Thu, 16 Feb 2017 17:44:36 -0500 Subject: [PATCH 04/11] changes to all cats --- api/routes/category.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/routes/category.php b/api/routes/category.php index 1122017..edf756b 100644 --- a/api/routes/category.php +++ b/api/routes/category.php @@ -22,9 +22,9 @@ foreach( $cats as $cat ) { $q = new CategoryRankNutrientQuery; - $requestedCatRules = $q->filterByCategoryId($cat->getId())->find(); + $requestedCatRules = $q->filterByCategoryId($cat->getId())->orderByRankId()->find(); foreach($requestedCatRules as $rule) { - $rules[] = [ + $rules[$rule->getNutrient()->getName()][] = [ "nutrientName" => $rule->getNutrient()->getName(), "nutrientId" => $rule->getNutrient()->getId(), "operator" => $rule->getOperator(), From 8337f3edd64216c4aa3019e2de17e2a9941d70ba Mon Sep 17 00:00:00 2001 From: Gabe Rogan Date: Sat, 18 Feb 2017 11:56:37 -0500 Subject: [PATCH 05/11] Prepared Food Controller for proper JSON syntax --- app/app.js | 36 +++++----- app/pages/food/ctrl.js | 95 +++++++++++++++----------- app/pages/food/style.styl | 61 ++++++++++++++--- app/pages/food/view.html | 88 ++++++++++-------------- app/root/_header.kit | 3 +- assets/css/main.css | 64 ++++++++++++++++-- assets/js/bundle.js | 131 +++++++++++++++++++++--------------- assets/json/categories.json | 8 +-- assets/json/foodDetail.json | 31 +++++++++ assets/json/foods.json | 74 +++++++++++++------- index.html | 3 +- 11 files changed, 390 insertions(+), 204 deletions(-) create mode 100644 assets/json/foodDetail.json diff --git a/app/app.js b/app/app.js index b5998c6..809ba8b 100644 --- a/app/app.js +++ b/app/app.js @@ -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; +// }); diff --git a/app/pages/food/ctrl.js b/app/pages/food/ctrl.js index e683268..a0b201b 100644 --- a/app/pages/food/ctrl.js +++ b/app/pages/food/ctrl.js @@ -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 = {}; @@ -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){ @@ -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); + // }; }]); diff --git a/app/pages/food/style.styl b/app/pages/food/style.styl index ea3dde1..1b07d95 100644 --- a/app/pages/food/style.styl +++ b/app/pages/food/style.styl @@ -67,10 +67,6 @@ -// Table view - - - .foods display: flex @@ -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 @@ -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 @@ -171,6 +168,9 @@ font-weight: 500 color: #BBB margin-bottom: 5px + span + color initial + font-weight normal a.btn width: 48% .orange @@ -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 diff --git a/app/pages/food/view.html b/app/pages/food/view.html index 2b46dc1..a9e8d36 100644 --- a/app/pages/food/view.html +++ b/app/pages/food/view.html @@ -32,16 +32,16 @@
By Category
By Grade
@@ -65,69 +65,56 @@
Table
- -
-
add
-
Add new food
-
- -
-
favorite
+
+
favorite
{{food.name}}
- - - - - - - - - - - - - - - - - - - - - - +
+
+ favorite + {{food.name}} + {{food.category.name}} + {{food.barcode}} +
RankFoodCategory
Add new food
{{food.name}}{{categories[food.category_id].name}}
-
-
-
+
+

{{foodCRUD.name || "Add New Food"}}

+

Barcode: {{foodCRUD.barcode}}

+

Grade: {{foodCRUD.rank.name}}

+

Category: {{foodCRUD.category.name}}

+ + + + + + -
+ -
+ -
+ -