diff --git a/api/routes/decision.php b/api/routes/decision.php index 14005aa..d3aef1a 100644 --- a/api/routes/decision.php +++ b/api/routes/decision.php @@ -190,6 +190,7 @@ function getProductInfo($upc) { $threshold = $rule->getThreshold(); $presentVal = $theNuts[$nut]; + //echo "Evaluating " . $nut . " is " . $operator . " to " . $threshold . "..."; $pass = 0; switch($operator) { @@ -209,11 +210,14 @@ function getProductInfo($upc) { $pass = ($presentVal >= $threshold); break; - case "is": + case "e": $pass = ($presentVal == $threshold); break; } + // echo "Present Value is " . $presentVal . " so ..."; + // echo $pass; + $rules[$rule->getRank()->getName()][$rule->getNutrient()->getName()] = [ "operator" => $operator, @@ -226,6 +230,9 @@ function getProductInfo($upc) { if($pass) { $res["rankId"] = $rule->getRank()->getId(); $res["rankName"] = $rule->getRank()->getName(); + } else { + $res["rankId"] = 3; + $res["rankName"] = "Red"; } } @@ -250,6 +257,8 @@ function getProductInfo($upc) { $msg = "There was an error saving this new Food to the DB"; } + //$msg = "testing"; + $res['request']['message'] = $msg; } diff --git a/assets/js/bundle.js b/assets/js/bundle.js index cbf1517..edd9860 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -6,7 +6,7 @@ var app = angular.module('app', ['ngRoute', 'ngResource', 'ngCookies']); // Factories app.factory('Foods', function($resource) { - return $resource('http://foodbank.develop.digitalmediauconn.org/api/food/all'); + return $resource('api/food/all'); // return $resource('assets/json/foods.json'); }); @@ -17,11 +17,11 @@ app.factory('FoodDetail', function($resource) { }); app.factory('Categories', function($resource) { - return $resource('http://foodbank.develop.digitalmediauconn.org/api/index.php/category/all'); + return $resource('api/index.php/category/all'); }); app.factory('Nutrients', function($resource) { - return $resource('http://foodbank.develop.digitalmediauconn.org/api/index.php/nutrient/all'); + return $resource('api/index.php/nutrient/all'); }); // Just does a PUT request when u call Food.update @@ -177,18 +177,21 @@ app.controller('CategoryCtrl', ['$scope', '$http', 'Categories', 'Nutrients', fu // GET list of categories - Categories.get({}, function (data) { - $scope.categories = data.data; + Categories.get().$promise.then(function(response){ + $scope.categories = response.data; + ; }); $scope.ranks = GetRanks(); $scope.units = ['mg', 'g']; - Nutrients.get({}, function(data) { - $scope.nutrients = data.data; - }); + Nutrients.get().$promise.then(function(response){ + + $scope.nutrients = response.data; + + }); $scope.operations = GetOperations(); @@ -206,7 +209,6 @@ app.controller('CategoryCtrl', ['$scope', '$http', 'Categories', 'Nutrients', fu if(categoryIndex != -1) { $scope.categories[categoryIndex].rules[0].push({ ruleId: 0, - nutrientName: $scope.nutrients[0].name, nutrientId: $scope.nutrients[0].id, operator: "lte", threshold: 10, @@ -243,6 +245,58 @@ 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('FoodCtrl', ['$scope', '$http', 'Foods', 'FoodDetail', 'Categories', '$cookies', function ($scope, $http, Foods, FoodDetail, Categories, $cookies) { $scope.page.title = 'Food'; $scope.page.id = 'food'; @@ -360,58 +414,6 @@ 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';