diff --git a/app/pages/food/anotherCtrl.js b/app/pages/food/anotherCtrl.js deleted file mode 100644 index e69de29..0000000 diff --git a/app/pages/food/ctrl.js b/app/pages/food/ctrl.js index 199a701..beb6a28 100644 --- a/app/pages/food/ctrl.js +++ b/app/pages/food/ctrl.js @@ -1,7 +1,92 @@ -app.controller('FoodCtrl', ['$scope', function ($scope) { +app.controller('FoodCtrl', ['$scope', '$http', function ($scope, $http) { $scope.page.title = 'Food'; $scope.page.id = 'food'; - $scope.page.yourVar = "globalStuff"; - $scope.var2 = "localStuff"; + // Initialize Filters + $scope.foods = []; + $scope.categories = []; + $scope.rankSelection = { + "green": true, + "yellow": true, + "red": true + }; + $scope.categorySelection = { "all": true }; + $scope.searchTerm = ""; + + // Initialize CRUD modes + $scope.editMode = false; + $scope.createMode = false; + + // Initialize CRUD form + $scope.foodCRUD = {}; + + // GET foods + $http.get("assets/json/foods.json") + .then(function(response) { + $scope.foods = response.data.data; + }); + + // GET list of categories + $http.get("assets/json/categories.json") + .then(function(response) { + $scope.categories = response.data.data; + + // Preset category filters + $scope.resetCategorySelection(); + }); + + // Set category filters to false + $scope.resetCategorySelection = function () { + $scope.categories.forEach(function(c){ + $scope.categorySelection[c.id] = false; + }); + } + + // Category filter function + $scope.categoryFilter = function (food) { + return ( $scope.categorySelection[food.category_id] | $scope.categorySelection["all"] ); + } + + // Rank filter function + $scope.rankFilter = function (food) { + return ( $scope.rankSelection[food.rank_id] ); + } + + // CRUD: edit food + $scope.edit = function (foodToEdit) { + $scope.editMode = true; + $scope.foodCRUD = foodToEdit; + $scope.foodCRUD.action = "update"; + // console.log($scope.foodCRUD); + }; + + // CRUD: create food + $scope.create = function () { + $scope.createMode = true; + $scope.foodCRUD = {}; + $scope.foodCRUD.rank_mode = "auto"; + $scope.foodCRUD.action = "create"; + // console.log($scope.foodCRUD); + }; + + // CRUD: cancel + $scope.cancel = function () { + $scope.editMode = false; + $scope.createMode = false; + }; + + // CRUD: POST + $scope.submit = function () { + $scope.cancel(); // hide modal + + $http.post('request-url', $scope.foodCRUD) + .success(function (data) { + // console.log(data); + }) + .error(function (data) { + // console.log(data); + }); + }; + + }]); diff --git a/app/pages/food/style.styl b/app/pages/food/style.styl index a07d8f3..0802028 100644 --- a/app/pages/food/style.styl +++ b/app/pages/food/style.styl @@ -4,18 +4,21 @@ cursor: pointer top: 6px right: 0 - &:hover - color: #888 - transform: scale(.9) - transition: all .2s + // &:hover + // color: #888 + // transform: scale(.9) + // transition: all .2s .input-field label.active transform: translateY(-120%) .input-field.col label left: 0 + +.barcode + margin: 0 .food-filter display: flex - flex-flow: row wrap + flex-flow: row no-wrap width: 100% padding: 0 1em .block @@ -24,7 +27,6 @@ &:last-child flex: 0 130px nav - box-shadow: none display: flex align-items: center justify-content: center @@ -51,6 +53,7 @@ flex-wrap: wrap .card-panel + background: lightergray flex-grow: 1 display: flex padding: 0 @@ -61,7 +64,6 @@ &:hover transform: scale(.95) .health - background-color: green width: 3em min-width: @width min-height: @width @@ -69,6 +71,14 @@ display: flex align-items: center justify-content: center + background-color: gray + &.rank-green + background-color: green + &.rank-yellow + background-color: yellow + &.rank-red + background-color: red + i color: white h5 @@ -88,48 +98,13 @@ -.food-crud - font-size: 1.1em - padding: 1em - border: 1px solid lightgray - my-box-shadow() - background: white - [type="radio"]:not(:checked)+label, [type="radio"]:checked+label - padding-left: 1.7em - padding-right: 1em - .grade - margin-bottom: 2em - h4 - margin: 5px 0 25px 0 - p - font-size: 1.1em - font-weight: 500 - color: #BBB - margin-bottom: 5px - a.btn - width: 48% - .orange - float: right - - .nutrition - margin-bottom: 1.5em - td - padding: .5em 5px - td:first-child - font-weight: 500 - width: 50% - -.modal_ .editContent - display: none -.modal_.editMode .editContent - display: inline -.modal_ +.foodModal + display: flex align-items: center justify-content: center - display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ left: 0; @@ -139,3 +114,34 @@ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ + + .CRUD + font-size: 1.1em + padding: 1em + border: 1px solid lightgray + my-box-shadow() + background: white + [type="radio"]:not(:checked)+label, [type="radio"]:checked+label + padding-left: 1.7em + padding-right: 1em + .grade + margin-bottom: 2em + h4 + margin: 5px 0 25px 0 + p + font-size: 1.1em + font-weight: 500 + color: #BBB + margin-bottom: 5px + a.btn + width: 48% + .orange + float: right + + .nutrition + margin-bottom: 1.5em + td + padding: .5em 5px + td:first-child + font-weight: 500 + width: 50% diff --git a/app/pages/food/view.html b/app/pages/food/view.html index b81a390..ded31ce 100644 --- a/app/pages/food/view.html +++ b/app/pages/food/view.html @@ -1,15 +1,18 @@ +
Grade
+