From 295b3a2cf34eb8127a5e5ca9257a91792c3dc560 Mon Sep 17 00:00:00 2001 From: Joel Salisbury Date: Thu, 16 Feb 2017 17:44:36 -0500 Subject: [PATCH 01/18] 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 4e3afff78e7e957d61fba91aa30f569e0f045179 Mon Sep 17 00:00:00 2001 From: Joel Salisbury Date: Mon, 27 Feb 2017 10:29:55 -0500 Subject: [PATCH 02/18] decision endpoint now creates food and checks for existing food --- api/routes/decision.php | 162 ++++++++++++++++++++++++++-------------- 1 file changed, 105 insertions(+), 57 deletions(-) diff --git a/api/routes/decision.php b/api/routes/decision.php index 90d0ca0..68bd951 100644 --- a/api/routes/decision.php +++ b/api/routes/decision.php @@ -124,86 +124,134 @@ function getProductInfo($upc) { $app->get('/getDecision/{upc}/{category}', function($request, $response) { +/** Checking to see if the food is already in the DB, in which case we save lots of time **/ -// get the nutrients by UPC -$prodInfo = getProductInfo($request->getAttribute('upc')); -$nutrients = $prodInfo['response']['body']['product_list']['products'][0]['product_nutrient_list']['product_nutrients']; + $q = new FoodQuery(); + $barcode = $request->getAttribute('upc'); + $food = $q::create() + ->useRankQuery() + ->endUse() + ->useCategoryQuery() + ->endUse() + ->filterByBarcode($barcode) + ->findOne(); -// get the whittled down nutrtient info shittily -$theNuts = array(); +if($food){ + + $rank = $food->getRank(); + $category = $food->getCategory(); + + $res['rankId'] = $food->getRankId(); + $res['rankName'] = $rank->getName(); + + + $res['request']['message'] = "Did not hit Fooducate. Food already exists in DB."; -foreach ($nutrients as $nutrient) { - $theNuts[$nutrient['nutrient']['@attributes']['name']] = $nutrient['@attributes']['value']; } -// echo "

The Product has...

"; -// echo "
";
-// print_r($theNuts);
-// echo "
"; +if(!$food) { + // get the nutrients by UPC + $prodInfo = getProductInfo($request->getAttribute('upc')); + $nutrients = $prodInfo['response']['body']['product_list']['products'][0]['product_nutrient_list']['product_nutrients']; -// get the rules by category - $q = new CategoryRankNutrientQuery; -$c = new CategoryQuery(); + // get the whittled down nutrtient info shittily + $theNuts = array(); + foreach ($nutrients as $nutrient) { + $theNuts[$nutrient['nutrient']['@attributes']['name']] = $nutrient['@attributes']['value']; + } - $allRules = $q->filterByCategoryId($request->getAttribute('category'))->find(); - //$res["food"] = $prodInfo; - $res["food"]['brand'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['brand']; - $res["food"]['name'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['name']; + // echo "

The Product has...

"; + // echo "
";
+      // print_r($theNuts);
+      // echo "
"; - $res["request"]["categoryRuleRun"] = $c->findPk($request->getAttribute("category"))->getName(); + // get the rules by category + $q = new CategoryRankNutrientQuery; + $c = new CategoryQuery(); -//default - $res["rankId"] = 0; - $res["rankName"] = "Red"; + $allRules = $q->filterByCategoryId($request->getAttribute('category'))->find(); + //$res["food"] = $prodInfo; + $res["food"]['brand'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['brand']; + $res["food"]['name'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['name']; -// for each rule, evaluate ingredients - foreach($allRules as $rule) { - $nut = $rule->getNutrient()->getName(); - $operator = $rule->getOperator(); - $threshold = $rule->getThreshold(); - $presentVal = $theNuts[$nut]; + $res["request"]["categoryRuleRun"] = $c->findPk($request->getAttribute("category"))->getName(); - $pass = 0; - switch($operator) { - case "lte": - $pass = ($presentVal <= $threshold); - break; + //default + $res["rankId"] = 3; + $res["rankName"] = "Red"; - case "lt": - $pass = ($presentVal < $threshold); - break; + // for each rule, evaluate ingredients + foreach($allRules as $rule) { + $nut = $rule->getNutrient()->getName(); + $operator = $rule->getOperator(); + $threshold = $rule->getThreshold(); + $presentVal = $theNuts[$nut]; - case "gt": - $pass = ($presentVal > $threshold); - break; - case "gte": - $pass = ($presentVal >= $threshold); - break; + $pass = 0; + switch($operator) { + case "lte": + $pass = ($presentVal <= $threshold); + break; - case "is": - $pass = ($presentVal == $threshold); - break; - } + case "lt": + $pass = ($presentVal < $threshold); + break; + case "gt": + $pass = ($presentVal > $threshold); + break; - $rules[$rule->getRank()->getName()][$rule->getNutrient()->getName()] = [ - "operator" => $operator, - "threshold" => $threshold, - "passed" => $pass?"true" : "false" - ]; + case "gte": + $pass = ($presentVal >= $threshold); + break; - $rules[$rule->getRank()->getName()]['passedRank'] = $pass?"true" : "false"; + case "is": + $pass = ($presentVal == $threshold); + break; + } - if($pass) { - $res["rankId"] = $rule->getRank()->getId(); - $res["rankName"] = $rule->getRank()->getName(); - } - } + $rules[$rule->getRank()->getName()][$rule->getNutrient()->getName()] = [ + "operator" => $operator, + "threshold" => $threshold, + "passed" => $pass?"true" : "false" + ]; + + $rules[$rule->getRank()->getName()]['passedRank'] = $pass?"true" : "false"; + + if($pass) { + $res["rankId"] = $rule->getRank()->getId(); + $res["rankName"] = $rule->getRank()->getName(); + } + } + + + /** Now create this Food with the associated rank and category **/ + + $newFood = new Food; + + $newFoodCat = $request->getAttribute('category'); + + $newFoodRank = $res['rankId']; + + $newFood->setRankId($newFoodRank); + $newFood->setCategoryId($newFoodCat); + $newFood->setBarcode($barcode); + + + if($newFood->save()){ + $msg = "New Food also added to DB."; + } else { + $msg = "There was an error saving this new Food to the DB"; + } + + $res['request']['message'] = $msg; + +} // echo "

The rules expected...

"; // echo "
";

From a24a3fa7e7309a8c112d548bcc1b021d1c5fce5b Mon Sep 17 00:00:00 2001
From: jsalisbury 
Date: Mon, 27 Feb 2017 21:34:29 -0500
Subject: [PATCH 03/18] hotfix for category obj

---
 api/routes/category.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/api/routes/category.php b/api/routes/category.php
index edf756b..c9865eb 100644
--- a/api/routes/category.php
+++ b/api/routes/category.php
@@ -8,10 +8,6 @@
   $q = new CategoryQuery;
   $cats = $q::create()->find();
 
-  
-
-
-
   $response_json = [
     "status" => [
       "code" => $response->getStatusCode(),
@@ -19,12 +15,13 @@
     ],
     "data" => []
   ];
-  foreach( $cats as $cat ) {
 
+  foreach( $cats as $cat ) {
+    $rules = [];
     $q = new CategoryRankNutrientQuery;
     $requestedCatRules = $q->filterByCategoryId($cat->getId())->orderByRankId()->find();
     foreach($requestedCatRules as $rule) {
-      $rules[$rule->getNutrient()->getName()][] = [
+      $rules[$rule->getRank()->getName()][] = [
         "nutrientName" => $rule->getNutrient()->getName(),
         "nutrientId" => $rule->getNutrient()->getId(),
         "operator" => $rule->getOperator(),
@@ -40,9 +37,12 @@
       "name" => $cat->getName(),
       "rules" => $rules
     ];
+
   }
+
   $response = $response->withJSON($response_json);
   return $response;
+
 });
 
 /**

From 71fad92937e71520c40bc9f0d498f41de81cfb3f Mon Sep 17 00:00:00 2001
From: jsalisbury 
Date: Mon, 27 Feb 2017 21:53:17 -0500
Subject: [PATCH 04/18] refactor again

---
 api/routes/category.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/api/routes/category.php b/api/routes/category.php
index c9865eb..1a7b3e2 100644
--- a/api/routes/category.php
+++ b/api/routes/category.php
@@ -21,7 +21,7 @@
     $q = new CategoryRankNutrientQuery;
     $requestedCatRules = $q->filterByCategoryId($cat->getId())->orderByRankId()->find();
     foreach($requestedCatRules as $rule) {
-      $rules[$rule->getRank()->getName()][] = [
+      $rules[$rule->getNutrient()->getName()][strtolower($rule->getRank()->getName())] = [
         "nutrientName" => $rule->getNutrient()->getName(),
         "nutrientId" => $rule->getNutrient()->getId(),
         "operator" => $rule->getOperator(),

From 88b61e30f50490db4c67cf59488bc4a8e3aa82b0 Mon Sep 17 00:00:00 2001
From: jsalisbury 
Date: Mon, 27 Feb 2017 22:14:11 -0500
Subject: [PATCH 05/18] another thing

---
 api/routes/category.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/api/routes/category.php b/api/routes/category.php
index 1a7b3e2..8717ce7 100644
--- a/api/routes/category.php
+++ b/api/routes/category.php
@@ -21,7 +21,7 @@
     $q = new CategoryRankNutrientQuery;
     $requestedCatRules = $q->filterByCategoryId($cat->getId())->orderByRankId()->find();
     foreach($requestedCatRules as $rule) {
-      $rules[$rule->getNutrient()->getName()][strtolower($rule->getRank()->getName())] = [
+      $rules[$rule->getNutrient()->getName()][][strtolower($rule->getRank()->getName())] = [
         "nutrientName" => $rule->getNutrient()->getName(),
         "nutrientId" => $rule->getNutrient()->getId(),
         "operator" => $rule->getOperator(),

From 8c883870ea24b70ce8c504b3183f6384d55f2cf0 Mon Sep 17 00:00:00 2001
From: jsalisbury 
Date: Mon, 27 Feb 2017 22:20:43 -0500
Subject: [PATCH 06/18] final update gah

---
 api/routes/category.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/api/routes/category.php b/api/routes/category.php
index 8717ce7..137363d 100644
--- a/api/routes/category.php
+++ b/api/routes/category.php
@@ -21,7 +21,7 @@
     $q = new CategoryRankNutrientQuery;
     $requestedCatRules = $q->filterByCategoryId($cat->getId())->orderByRankId()->find();
     foreach($requestedCatRules as $rule) {
-      $rules[$rule->getNutrient()->getName()][][strtolower($rule->getRank()->getName())] = [
+      $rules[$rule->getNutrient()->getName()][] = [
         "nutrientName" => $rule->getNutrient()->getName(),
         "nutrientId" => $rule->getNutrient()->getId(),
         "operator" => $rule->getOperator(),

From 6d551b5a37084bbbb396739d277ca4b326359de5 Mon Sep 17 00:00:00 2001
From: Timothy Morris 
Date: Tue, 28 Feb 2017 10:55:17 -0500
Subject: [PATCH 07/18] categories now pulls from api

---
 app/app.js                     |   2 +-
 app/pages/categories/ctrl.js   |  12 +--
 app/pages/categories/view.html |  14 +--
 assets/js/bundle.js            | 170 ++++++++++++++++-----------------
 4 files changed, 95 insertions(+), 103 deletions(-)

diff --git a/app/app.js b/app/app.js
index b5998c6..8ae4155 100644
--- a/app/app.js
+++ b/app/app.js
@@ -20,7 +20,7 @@ app.factory('Food', function ($resource) {
 });
 
 app.factory('Categories', function($resource) {
-  return $resource('assets/json/categories.json');
+  return $resource('http://foodbank.develop.digitalmediauconn.org/api/index.php/category/all');
 });
 
 // TODO: 'Nutrients' factory TEMPORARY
diff --git a/app/pages/categories/ctrl.js b/app/pages/categories/ctrl.js
index 41a927d..d99d832 100644
--- a/app/pages/categories/ctrl.js
+++ b/app/pages/categories/ctrl.js
@@ -44,32 +44,28 @@ app.controller('CategoryCtrl', ['$scope', 'Categories', function ($scope, Catego
 	};
 
 	$scope.addRule = function(categoryName) {
-		var categoryIndex = $scope.getCategoryIndexFromName(categoryName);
+		/*var categoryIndex = $scope.getCategoryIndexFromName(categoryName);
 		if(categoryIndex != -1) {
 			$scope.categories[categoryIndex].rules.push({ nutrient: 'sugar',
 				rule_id: '0',
 				ranks:  [ { name: 'green', operation: 'lt', value: 5 },
 									{ name: 'yellow', operation: 'gt', value: 2 } ] });
-		}
+		}*/
 
 	};
 
 	$scope.removeRule = function(category, rule) {
-		for(var i = 0; i < category.rules.length; i++) {
+		/*for(var i = 0; i < category.rules.length; i++) {
 			if(category.rules[i] == rule) {
 				category.rules.splice(i, 1);
 			}
-		}
+		}*/
 	};
 
 	$scope.addCategory = function() {
 		$scope.categories.push({name: 'New Category', rules: []})
 	};
 
-	$scope.renameCategory = function(category, name) {
-		console.log(name);
-	};
-
 	$scope.removeCategory = function(category) {
 		for(var i = 0; i < $scope.categories.length; i++) {
 			if($scope.categories[i] == category) {
diff --git a/app/pages/categories/view.html b/app/pages/categories/view.html
index 15c172b..7ecfec1 100644
--- a/app/pages/categories/view.html
+++ b/app/pages/categories/view.html
@@ -11,7 +11,7 @@
 				          
 				          
 				        
-								
+								
 							
 					    
@@ -23,22 +23,22 @@ - + - @@ -46,13 +46,13 @@
+
- +
+
- +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
- - - - - - - - - - - - - - - -
Nutrient{{rank}} condition
-
- -
-
-
- -
-
- -
-
+ + +
@@ -52,7 +58,7 @@ - +
-
+
-
By Grade
+
Health Filter
-
Table
+
Card View
diff --git a/app/root/_footer.kit b/app/root/_footer.kit index 84777ec..0b2152c 100644 --- a/app/root/_footer.kit +++ b/app/root/_footer.kit @@ -1,6 +1,6 @@ -
+ diff --git a/app/root/_nav.kit b/app/root/_nav.kit index 08b2a75..faf7041 100644 --- a/app/root/_nav.kit +++ b/app/root/_nav.kit @@ -12,16 +12,16 @@
- diff --git a/app/root/root.styl b/app/root/root.styl index f7a8c6e..c7fa4dc 100644 --- a/app/root/root.styl +++ b/app/root/root.styl @@ -27,7 +27,7 @@ Table of Contents: padding-right: 2em * {display: inline} i - font-size: 6rem + font-size: 4rem h4 font-size: 2.6rem font-weight: 500 diff --git a/assets/css/main.css b/assets/css/main.css index 8219112..8c8f2e4 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -36,6 +36,9 @@ ul.tabs .tab a { ul.tabs .tab a:hover { color: inherit; } +.f404 { + text-align: center; +} .collapsible-body { padding: 1em; box-sizing: border-box; @@ -47,6 +50,19 @@ ul.tabs .tab a:hover { select { display: block !important; } +.row { + display: flex; +} +.catsWrap { + max-width: 100%; + min-width: 100%; + margin: 0 auto; +} +@media all and (min-width: 700px) { + .catsWrap { + min-width: 680px; + } +} .food-search { padding-top: 0.5em; } @@ -86,11 +102,11 @@ select { background-color: #f5f5f5; } .grade { - padding-right: 1em; + padding-right: 2em; } @media all and (min-width: 600px) { .grade { - padding: 0 1em; + padding: 0 2em 0 0; } } .grade nav { @@ -121,6 +137,12 @@ select { [type="checkbox"]+label { padding-left: 26px; } +.table-toggle .switch { + display: flex; +} +.table-toggle label { + margin: 0 auto; +} .foods { display: flex; padding: 3em; @@ -220,6 +242,7 @@ select { padding: 1em; border: 1px solid #f0f0f0; min-width: 300px; + max-width: 500px; box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16), 0 2px 10px 0 rgba(0,0,0,0.12); background: #fff; } @@ -273,6 +296,7 @@ select { font-size: 1.2em; align-items: center; margin-right: 1em; + max-width: 100%; padding-right: 1em; background: #f5f5f5; transition: all 0.2s; @@ -291,10 +315,17 @@ select { flex-basis: 100px; margin-right: 1em; } +.foodTableItem .foodCat { + text-align: right; +} .foodTableItem .name { - flex-basis: 140px; + flex-grow: 1; + white-space: nowrap; + text-overflow: ellipsis; + overflow-y: hidden; } .foodTableItem .barcode { + flex-basis: 117px; color: #888; font-size: 1rem; text-align: right; @@ -388,7 +419,7 @@ h1.nutrientsTitle { display: inline; } .nav-main .logo-area i { - font-size: 6rem; + font-size: 4rem; } .nav-main .logo-area h4 { font-size: 2.6rem; diff --git a/assets/js/bundle.js b/assets/js/bundle.js index f9c58dc..cbf1517 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -6,7 +6,8 @@ var app = angular.module('app', ['ngRoute', 'ngResource', 'ngCookies']); // Factories app.factory('Foods', function($resource) { - return $resource('assets/json/foods.json'); + return $resource('http://foodbank.develop.digitalmediauconn.org/api/food/all'); + // return $resource('assets/json/foods.json'); }); app.factory('FoodDetail', function($resource) { @@ -145,6 +146,13 @@ app.controller('EmailController', ['$scope', function ($scope) { $scope.email = "rogangabe@gmail.com"; }]); +app.controller('404Ctrl', ['$scope', function ($scope) { + $scope.page.title = '404'; + $scope.page.id = '404'; + $scope.page.yourVar = "globalStuff"; + + $scope.var2 = "localStuff"; +}]); function GetRanks() { @@ -235,75 +243,14 @@ app.controller('CategoryCtrl', ['$scope', '$http', 'Categories', 'Nutrients', fu }; }]); - -app.controller('LoginCtrl', ['$scope', 'loginService', function ($scope, loginService) { - $scope.page.title = 'Login'; - $scope.page.id = 'login'; - $scope.page.yourVar = "globalStuff"; - - $scope.selected = { - username: "", - password: "" - }; - - $scope.loginAttempt = { - username: "", - password: "", - attempt: false, - login: false - }; - - $scope.loginService = loginService; - - $scope.login = function( username, password ) { - $scope.loginAttempt.username = username; - $scope.loginAttempt.password = password; - $scope.loginAttempt.attempt = true; - // Sanitize? Pre-check? - console.log($scope.loginService); - $scope.loginService.login( username, password ).then(function(response) { - console.log(response); - // Mock the fact that this takes longer - setTimeout(function() { - $scope.$apply(function() { - $scope.loginAttempt.login = response.login; - $scope.loginAttempt.attempt = false; - }); - }, 1000); - }, function(error) { - console.error(error); - }); - }; - -}]); - -app.factory('loginService', ['$http', function($http) { - return { - login: function( username, password ) { - return $http.get('/app/pages/login/example.json').then(function(response) { - return response.data; - }, function(error) { - return error; - }); - } - }; -}]); -app.controller('404Ctrl', ['$scope', function ($scope) { - $scope.page.title = '404'; - $scope.page.id = '404'; - $scope.page.yourVar = "globalStuff"; - - $scope.var2 = "localStuff"; -}]); - app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'FoodDetail', 'Categories', '$cookies', function ($scope, $http, Foods, FoodDetail, 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'); + $scope.cardView = $cookies.get('showTable') === 'true'; + $scope.$watch('cardView', function () { + $cookies.put('showTable', $scope.cardView ? 'true' : 'false'); }); // Initialize Filters @@ -413,6 +360,58 @@ app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'FoodDetail', 'Categorie }]); +app.controller('LoginCtrl', ['$scope', 'loginService', function ($scope, loginService) { + $scope.page.title = 'Login'; + $scope.page.id = 'login'; + $scope.page.yourVar = "globalStuff"; + + $scope.selected = { + username: "", + password: "" + }; + + $scope.loginAttempt = { + username: "", + password: "", + attempt: false, + login: false + }; + + $scope.loginService = loginService; + + $scope.login = function( username, password ) { + $scope.loginAttempt.username = username; + $scope.loginAttempt.password = password; + $scope.loginAttempt.attempt = true; + // Sanitize? Pre-check? + console.log($scope.loginService); + $scope.loginService.login( username, password ).then(function(response) { + console.log(response); + // Mock the fact that this takes longer + setTimeout(function() { + $scope.$apply(function() { + $scope.loginAttempt.login = response.login; + $scope.loginAttempt.attempt = false; + }); + }, 1000); + }, function(error) { + console.error(error); + }); + }; + +}]); + +app.factory('loginService', ['$http', function($http) { + return { + login: function( username, password ) { + return $http.get('/app/pages/login/example.json').then(function(response) { + return response.data; + }, function(error) { + return error; + }); + } + }; +}]); app.controller('NutrientsCtrl', ['$scope', 'Nutrients', function ($scope, Nutrients) { $scope.page.title = 'Nutrients'; $scope.page.id = 'nutrients'; diff --git a/index.html b/index.html index 80e6cfa..1420184 100644 --- a/index.html +++ b/index.html @@ -48,16 +48,16 @@
- @@ -110,11 +110,11 @@ -