diff --git a/app/pages/categories/view.html b/app/pages/categories/view.html index a2bacdb..8b1862c 100644 --- a/app/pages/categories/view.html +++ b/app/pages/categories/view.html @@ -6,13 +6,6 @@
{{ category.name }}
-
@@ -29,7 +22,7 @@
diff --git a/assets/js/bundle.js b/assets/js/bundle.js index ab81d6b..cbf1517 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -154,6 +154,95 @@ app.controller('404Ctrl', ['$scope', function ($scope) { $scope.var2 = "localStuff"; }]); + +function GetRanks() { + return [{name: 'green', id: 1}, {name: 'yellow', id: 2}]; +} + +function GetNutrients() { + return ['sodium', 'sugar', 'satfat']; +} + +function GetOperations() { + return [{name: 'lt', symbol: 'Less Than'}, + {name: 'lte', symbol: 'Less Than or Equal'}, + {name: 'gt', symbol: 'Greater Than'}, + {name: 'gte', symbol: 'Greater Than or Equal'}, + {name: 'e', symbol: 'Equal To'}]; +} + +app.controller('CategoryCtrl', ['$scope', '$http', 'Categories', 'Nutrients', function ($scope, $http, Categories, Nutrients) { + $scope.page.title = 'Categories'; + $scope.page.id = 'cat'; + + + // GET list of categories + Categories.get({}, function (data) { + $scope.categories = data.data; + }); + + $scope.ranks = GetRanks(); + + $scope.units = ['mg', 'g']; + + Nutrients.get({}, function(data) { + $scope.nutrients = data.data; + }); + + $scope.operations = GetOperations(); + + + $scope.getCategoryIndexFromName = function(categoryName) { + for(var i = 0; i < $scope.categories.length; i++) { + if($scope.categories[i].name == categoryName) { + return i; + } + } + return -1; + }; + + $scope.addRule = function(categoryName) { + var categoryIndex = $scope.getCategoryIndexFromName(categoryName); + 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, + units: "mg", + rank: 1, + categoryId: categoryIndex + }); + } + + }; + + $scope.removeRule = function(category, rule) { + for(var i = 0; i < category.rules[0].length; i++) { + if(category.rules[0][i] == rule) { + category.rules[0].splice(i, 1); + } + } + }; + + $scope.addCategory = function() { + //$scope.categories.push({name: 'New Category', rules: []}) + }; + + $scope.removeCategory = function(category) { + for(var i = 0; i < $scope.categories.length; i++) { + if($scope.categories[i] == category) { + $scope.categories.splice(i, 1); + } + } + }; + + $scope.saveData = function(category) { + $http.post('http://foodbank.develop.digitalmediauconn.org/api/index.php/rules/saveBatch/' + category.id, category.rules[0]); + }; +}]); + app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'FoodDetail', 'Categories', '$cookies', function ($scope, $http, Foods, FoodDetail, Categories, $cookies) { $scope.page.title = 'Food'; $scope.page.id = 'food'; @@ -271,95 +360,6 @@ app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'FoodDetail', 'Categorie }]); - -function GetRanks() { - return [{name: 'green', id: 1}, {name: 'yellow', id: 2}]; -} - -function GetNutrients() { - return ['sodium', 'sugar', 'satfat']; -} - -function GetOperations() { - return [{name: 'lt', symbol: 'Less Than'}, - {name: 'lte', symbol: 'Less Than or Equal'}, - {name: 'gt', symbol: 'Greater Than'}, - {name: 'gte', symbol: 'Greater Than or Equal'}, - {name: 'e', symbol: 'Equal To'}]; -} - -app.controller('CategoryCtrl', ['$scope', '$http', 'Categories', 'Nutrients', function ($scope, $http, Categories, Nutrients) { - $scope.page.title = 'Categories'; - $scope.page.id = 'cat'; - - - // GET list of categories - Categories.get({}, function (data) { - $scope.categories = data.data; - }); - - $scope.ranks = GetRanks(); - - $scope.units = ['mg', 'g']; - - Nutrients.get({}, function(data) { - $scope.nutrients = data.data; - }); - - $scope.operations = GetOperations(); - - - $scope.getCategoryIndexFromName = function(categoryName) { - for(var i = 0; i < $scope.categories.length; i++) { - if($scope.categories[i].name == categoryName) { - return i; - } - } - return -1; - }; - - $scope.addRule = function(categoryName) { - var categoryIndex = $scope.getCategoryIndexFromName(categoryName); - 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, - units: "mg", - rank: 1, - categoryId: categoryIndex - }); - } - - }; - - $scope.removeRule = function(category, rule) { - for(var i = 0; i < category.rules[0].length; i++) { - if(category.rules[0][i] == rule) { - category.rules[0].splice(i, 1); - } - } - }; - - $scope.addCategory = function() { - //$scope.categories.push({name: 'New Category', rules: []}) - }; - - $scope.removeCategory = function(category) { - for(var i = 0; i < $scope.categories.length; i++) { - if($scope.categories[i] == category) { - $scope.categories.splice(i, 1); - } - } - }; - - $scope.saveData = function(category) { - $http.post('http://foodbank.develop.digitalmediauconn.org/api/index.php/rules/saveBatch/' + category.id, category.rules[0]); - }; -}]); - app.controller('LoginCtrl', ['$scope', 'loginService', function ($scope, loginService) { $scope.page.title = 'Login'; $scope.page.id = 'login';