Skip to content

Commit

Permalink
joel fixing API:
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Salisbury committed Jul 6, 2017
1 parent 161e3bb commit a59316e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 62 deletions.
11 changes: 10 additions & 1 deletion api/routes/decision.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ function getProductInfo($upc) {
$threshold = $rule->getThreshold();
$presentVal = $theNuts[$nut];

//echo "Evaluating " . $nut . " is " . $operator . " to " . $threshold . "...";

$pass = 0;
switch($operator) {
Expand All @@ -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,
Expand All @@ -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";
}
}

Expand All @@ -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;

}
Expand Down
124 changes: 63 additions & 61 deletions assets/js/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand All @@ -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
Expand Down Expand Up @@ -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();


Expand All @@ -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,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit a59316e

Please sign in to comment.