From 040d6369854c2fbf05e717eb4c969a1abfa15327 Mon Sep 17 00:00:00 2001 From: Tim Morris Date: Tue, 13 Dec 2016 00:19:54 -0500 Subject: [PATCH 1/2] begin api receiving setup --- app/pages/categories/ctrl.js | 62 ++++++++++- app/pages/categories/style.styl | 9 ++ app/pages/categories/view.html | 183 +++++++------------------------- assets/css/main.css | 8 ++ assets/js/bundle.js | 74 +++++++++++-- 5 files changed, 182 insertions(+), 154 deletions(-) diff --git a/app/pages/categories/ctrl.js b/app/pages/categories/ctrl.js index 38bbe26..8b0da18 100644 --- a/app/pages/categories/ctrl.js +++ b/app/pages/categories/ctrl.js @@ -1,7 +1,65 @@ + +function GetCategories() { + return [ + { + name: 'fruit', + rules: [ + { nutrient: 'sugar', + rule_id: '1', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] }, + { nutrient: 'sodium', + rule_id: '2', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gtoe', value: 2 } ] }, + { nutrient: 'satfat', + rule_id: '3', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] } ] + + }, + { + name: 'veggie', + rules: [ + { nutrient: 'sugar', + rule_id: '4', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] }, + { nutrient: 'sodium', + rule_id: '5', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] }, + { nutrient: 'satfat', + rule_id: '6', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] } ] + + } + ]; +} + +function GetRanks() { + return ['green', 'yellow']; +} + +function GetNutrients() { + return ['sodium', 'sugar', 'satfat']; +} + +function GetOperations() { + return [{name: 'lt', symbol: 'Less Than'}, + {name: 'ltoe', symbol: 'Less Than or Equal'}, + {name: 'gt', symbol: 'Greater Than'}, + {name: 'gtoe', symbol: 'Greater Than or Equal'}]; +} + app.controller('CategoryCtrl', ['$scope', function ($scope) { $scope.page.title = 'Categories'; $scope.page.id = 'cat'; $scope.page.yourVar = "globalStuff"; - - $scope.var2 = "localStuff"; + + $scope.categories = GetCategories(); + $scope.ranks = GetRanks(); + $scope.nutrients = GetNutrients(); + $scope.operations = GetOperations(); }]); diff --git a/app/pages/categories/style.styl b/app/pages/categories/style.styl index e69de29..f674be6 100644 --- a/app/pages/categories/style.styl +++ b/app/pages/categories/style.styl @@ -0,0 +1,9 @@ +.collapsible-body { + padding: 1em; + box-sizing:border-box; +} + +.card-title, +.collapsible-header { + text-transform:capitalize; +} diff --git a/app/pages/categories/view.html b/app/pages/categories/view.html index 143b85a..d710b91 100644 --- a/app/pages/categories/view.html +++ b/app/pages/categories/view.html @@ -1,144 +1,53 @@
-
+
    -
  • -
    CATEGORY NAME
    +
  • +
    {{ category.name }}
    -
    - -
    -
    -
    -
    -

    Nutrients

    -
    -
    -
    -
    -
    -
    -

    Sugar

    -
    - - -
    -
    - - -
    -
    -
    -

    Sodium

    -
    - - -
    -
    - - -
    -
    -
    -

    Saturated Fat

    -
    - - -
    -
    - - -
    -
    -
    -
    -
    -

    Sugar

    -
    - - -
    -
    - - -
    -
    -
    -

    Sodium

    -
    - - -
    -
    - - -
    -
    -
    -

    Saturated Fat

    -
    - - -
    -
    - - -
    -
    -
    -
    -
    +
    + + + + + + + + + + + + + +
    Nutrient{{rank}} condition
    +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    +
+
-

I'd put more, but then I'd have to change lots of ID's... you get the idea #lazydev

-
+
Filter
-
-
- - -
-
@@ -157,21 +66,7 @@

Nutrients

diff --git a/assets/css/main.css b/assets/css/main.css index 6af37ad..896deef 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -33,6 +33,14 @@ ul.tabs .tab a { ul.tabs .tab a:hover { color: inherit; } +.collapsible-body { + padding: 1em; + box-sizing: border-box; +} +.card-title, +.collapsible-header { + text-transform: capitalize; +} .food-search { padding-top: 0.5em; } diff --git a/assets/js/bundle.js b/assets/js/bundle.js index 632e994..cef1780 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -108,21 +108,79 @@ app.controller('404Ctrl', ['$scope', function ($scope) { }]); -app.controller('CategoryCtrl', ['$scope', function ($scope) { - $scope.page.title = 'Categories'; - $scope.page.id = 'cat'; +app.controller('FoodCtrl', ['$scope', function ($scope) { + $scope.page.title = 'Food'; + $scope.page.id = 'food'; $scope.page.yourVar = "globalStuff"; - + $scope.var2 = "localStuff"; }]); -app.controller('FoodCtrl', ['$scope', function ($scope) { - $scope.page.title = 'Food'; - $scope.page.id = 'food'; + +function GetCategories() { + return [ + { + name: 'fruit', + rules: [ + { nutrient: 'sugar', + rule_id: '1', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] }, + { nutrient: 'sodium', + rule_id: '2', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gtoe', value: 2 } ] }, + { nutrient: 'satfat', + rule_id: '3', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] } ] + + }, + { + name: 'veggie', + rules: [ + { nutrient: 'sugar', + rule_id: '4', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] }, + { nutrient: 'sodium', + rule_id: '5', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] }, + { nutrient: 'satfat', + rule_id: '6', + ranks: [ { name: 'green', operation: 'lt', value: 5 }, + { name: 'yellow', operation: 'gt', value: 2 } ] } ] + + } + ]; +} + +function GetRanks() { + return ['green', 'yellow']; +} + +function GetNutrients() { + return ['sodium', 'sugar', 'satfat']; +} + +function GetOperations() { + return [{name: 'lt', symbol: 'Less Than'}, + {name: 'ltoe', symbol: 'Less Than or Equal'}, + {name: 'gt', symbol: 'Greater Than'}, + {name: 'gtoe', symbol: 'Greater Than or Equal'}]; +} + +app.controller('CategoryCtrl', ['$scope', function ($scope) { + $scope.page.title = 'Categories'; + $scope.page.id = 'cat'; $scope.page.yourVar = "globalStuff"; - $scope.var2 = "localStuff"; + $scope.categories = GetCategories(); + $scope.ranks = GetRanks(); + $scope.nutrients = GetNutrients(); + $scope.operations = GetOperations(); }]); From 19bc8947ec1082972b26365da67a4b054b199f14 Mon Sep 17 00:00:00 2001 From: Timothy Morris Date: Mon, 13 Feb 2017 11:46:06 -0500 Subject: [PATCH 2/2] rule / category CRUD update --- app/pages/categories/ctrl.js | 57 ++++++++++++++++++++++++- app/pages/categories/style.styl | 4 ++ app/pages/categories/view.html | 30 ++++++++++--- assets/css/main.css | 3 ++ assets/js/bundle.js | 75 ++++++++++++++++++++++++++++----- 5 files changed, 149 insertions(+), 20 deletions(-) diff --git a/app/pages/categories/ctrl.js b/app/pages/categories/ctrl.js index 8b0da18..9f515f9 100644 --- a/app/pages/categories/ctrl.js +++ b/app/pages/categories/ctrl.js @@ -48,9 +48,14 @@ function GetNutrients() { function GetOperations() { return [{name: 'lt', symbol: 'Less Than'}, - {name: 'ltoe', symbol: 'Less Than or Equal'}, + {name: 'lte', symbol: 'Less Than or Equal'}, {name: 'gt', symbol: 'Greater Than'}, - {name: 'gtoe', symbol: 'Greater Than or Equal'}]; + {name: 'gte', symbol: 'Greater Than or Equal'}, + {name: 'e', symbol: 'Equal To'}]; +} + +function SaveData(categories) { + console.log('save'); } app.controller('CategoryCtrl', ['$scope', function ($scope) { @@ -62,4 +67,52 @@ app.controller('CategoryCtrl', ['$scope', function ($scope) { $scope.ranks = GetRanks(); $scope.nutrients = GetNutrients(); $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.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++) { + 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) { + $scope.categories.splice(i, 1); + } + } + }; + + $scope.saveData = function() { + SaveData($scope.categories); + }; }]); diff --git a/app/pages/categories/style.styl b/app/pages/categories/style.styl index f674be6..1a565da 100644 --- a/app/pages/categories/style.styl +++ b/app/pages/categories/style.styl @@ -7,3 +7,7 @@ .collapsible-header { text-transform:capitalize; } + +select { + display:block!important; +} diff --git a/app/pages/categories/view.html b/app/pages/categories/view.html index d710b91..15c172b 100644 --- a/app/pages/categories/view.html +++ b/app/pages/categories/view.html @@ -6,43 +6,55 @@
{{ category.name }}
+
+
+ + +
+ +
- +
+ +
Nutrient {{rank}} condition
-
-
- +
+
+ +
-
+
diff --git a/assets/css/main.css b/assets/css/main.css index 896deef..c55a83e 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -41,6 +41,9 @@ ul.tabs .tab a:hover { .collapsible-header { text-transform: capitalize; } +select { + display: block !important; +} .food-search { padding-top: 0.5em; } diff --git a/assets/js/bundle.js b/assets/js/bundle.js index cef1780..db7e9be 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -108,15 +108,6 @@ app.controller('404Ctrl', ['$scope', function ($scope) { }]); -app.controller('FoodCtrl', ['$scope', function ($scope) { - $scope.page.title = 'Food'; - $scope.page.id = 'food'; - $scope.page.yourVar = "globalStuff"; - - $scope.var2 = "localStuff"; -}]); - - function GetCategories() { return [ @@ -167,9 +158,14 @@ function GetNutrients() { function GetOperations() { return [{name: 'lt', symbol: 'Less Than'}, - {name: 'ltoe', symbol: 'Less Than or Equal'}, + {name: 'lte', symbol: 'Less Than or Equal'}, {name: 'gt', symbol: 'Greater Than'}, - {name: 'gtoe', symbol: 'Greater Than or Equal'}]; + {name: 'gte', symbol: 'Greater Than or Equal'}, + {name: 'e', symbol: 'Equal To'}]; +} + +function SaveData(categories) { + console.log('save'); } app.controller('CategoryCtrl', ['$scope', function ($scope) { @@ -181,6 +177,63 @@ app.controller('CategoryCtrl', ['$scope', function ($scope) { $scope.ranks = GetRanks(); $scope.nutrients = GetNutrients(); $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.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++) { + 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) { + $scope.categories.splice(i, 1); + } + } + }; + + $scope.saveData = function() { + SaveData($scope.categories); + }; +}]); + + +app.controller('FoodCtrl', ['$scope', function ($scope) { + $scope.page.title = 'Food'; + $scope.page.id = 'food'; + $scope.page.yourVar = "globalStuff"; + + $scope.var2 = "localStuff"; }]);