diff --git a/app/app.js b/app/app.js index dfe3e57..2164777 100644 --- a/app/app.js +++ b/app/app.js @@ -20,7 +20,7 @@ app.factory('Categories', function($resource) { }); app.factory('Nutrients', function($resource) { - return $resource('assets/json/nutrients.json'); + return $resource('http://foodbank.develop.digitalmediauconn.org/api/index.php/nutrient/all'); }); // Just does a PUT request when u call Food.update diff --git a/app/pages/categories/ctrl.js b/app/pages/categories/ctrl.js index d99d832..c3b8dbe 100644 --- a/app/pages/categories/ctrl.js +++ b/app/pages/categories/ctrl.js @@ -1,6 +1,6 @@ function GetRanks() { - return ['green', 'yellow']; + return [{name: 'green', id: 1}, {name: 'yellow', id: 2}]; } function GetNutrients() { @@ -15,14 +15,9 @@ function GetOperations() { {name: 'e', symbol: 'Equal To'}]; } -function SaveData(categories) { - console.log('save'); -} - -app.controller('CategoryCtrl', ['$scope', 'Categories', function ($scope, Categories) { +app.controller('CategoryCtrl', ['$scope', '$http', 'Categories', 'Nutrients', function ($scope, $http, Categories, Nutrients) { $scope.page.title = 'Categories'; $scope.page.id = 'cat'; - $scope.page.yourVar = "globalStuff"; // GET list of categories @@ -31,9 +26,16 @@ app.controller('CategoryCtrl', ['$scope', 'Categories', function ($scope, Catego }); $scope.ranks = GetRanks(); - $scope.nutrients = GetNutrients(); + + $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) { @@ -44,26 +46,32 @@ 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.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.length; i++) { - if(category.rules[i] == rule) { - category.rules.splice(i, 1); + 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.categories.push({name: 'New Category', rules: []}) }; $scope.removeCategory = function(category) { @@ -74,7 +82,7 @@ app.controller('CategoryCtrl', ['$scope', 'Categories', function ($scope, Catego } }; - $scope.saveData = function() { - SaveData($scope.categories); + $scope.saveData = function(category) { + $http.post('http://foodbank.develop.digitalmediauconn.org/api/index.php/rules/saveBatch/' + category.id, category.rules[0]); }; }]); diff --git a/app/pages/categories/view.html b/app/pages/categories/view.html index 7ecfec1..5d9511e 100644 --- a/app/pages/categories/view.html +++ b/app/pages/categories/view.html @@ -6,45 +6,51 @@
{{ category.name }}
-
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
- - - - - - - - - - - - - - - -
Nutrient{{rank}} condition
-
- -
-
-
- -
-
- -
-
+ + +
@@ -52,7 +58,7 @@
- +