diff --git a/app/pages/food/ctrl.js b/app/pages/food/ctrl.js
index 7aa5094..561545d 100644
--- a/app/pages/food/ctrl.js
+++ b/app/pages/food/ctrl.js
@@ -1,29 +1,57 @@
app.controller('FoodCtrl', ['$scope', '$http', function ($scope, $http) {
- $http.get("assets/json/data.json")
- .then(function(response) {
- $scope.foods = response.data.data;
- });
-
$scope.page.title = 'Food';
$scope.page.id = 'food';
+ // Initialize Filters
+ $scope.foods = [];
+ $scope.categories = [];
+ $scope.categorySelection = { "all": true };
+ $scope.searchTerm = "";
+
+ // Initialize CRUD modes
$scope.editMode = false;
$scope.createMode = false;
- $scope.foodCRUD = {}
+ // 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.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"] );
+ }
+ // CRUD: edit food
$scope.edit = function (foodToEdit) {
$scope.editMode = true;
$scope.foodCRUD = foodToEdit;
$scope.foodCRUD.rank_mode = "0"; //TODO: remove this when API implements it
};
+ // CRUD: create food
$scope.create = function () {
$scope.createMode = true;
$scope.foodCRUD = {}
$scope.foodCRUD.rank_mode = "0";
};
+ // CRUD: cancel
$scope.cancel = function () {
$scope.editMode = false;
$scope.createMode = false;
diff --git a/app/pages/food/style.styl b/app/pages/food/style.styl
index d4664d6..1ca7e7f 100644
--- a/app/pages/food/style.styl
+++ b/app/pages/food/style.styl
@@ -4,10 +4,10 @@
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
diff --git a/app/pages/food/view.html b/app/pages/food/view.html
index aac25c4..00e0d92 100644
--- a/app/pages/food/view.html
+++ b/app/pages/food/view.html
@@ -2,8 +2,8 @@
-
-
+
+
+
@@ -117,7 +118,7 @@
{{foodCRUD.name || "Add New Food"}}
-
+
Nutrition Facts (WIP)
@@ -148,45 +149,3 @@ {{foodCRUD.name || "Add New Food"}}
-
-
-
diff --git a/assets/css/main.css b/assets/css/main.css
index 57b92aa..f352e93 100644
--- a/assets/css/main.css
+++ b/assets/css/main.css
@@ -44,11 +44,6 @@ ul.tabs .tab a:hover {
top: 6px;
right: 0;
}
-.food-search i:hover {
- color: #888;
- transform: scale(0.9);
- transition: all 0.2s;
-}
.food-search .input-field label.active {
transform: translateY(-120%);
}
diff --git a/assets/js/bundle.js b/assets/js/bundle.js
index cca9a93..544db03 100644
--- a/assets/js/bundle.js
+++ b/assets/js/bundle.js
@@ -108,32 +108,69 @@ app.controller('404Ctrl', ['$scope', function ($scope) {
}]);
-app.controller('FoodCtrl', ['$scope', '$http', function ($scope, $http) {
- $http.get("assets/json/data.json")
- .then(function(response) {
- $scope.foods = response.data.data;
- });
+app.controller('CategoryCtrl', ['$scope', function ($scope) {
+ $scope.page.title = 'Categories';
+ $scope.page.id = 'cat';
+ $scope.page.yourVar = "globalStuff";
+
+ $scope.var2 = "localStuff";
+}]);
+
+app.controller('FoodCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.page.title = 'Food';
$scope.page.id = 'food';
+ // Initialize Filters
+ $scope.foods = [];
+ $scope.categories = [];
+ $scope.categorySelection = { "all": true };
+ $scope.searchTerm = "";
+
+ // Initialize CRUD modes
$scope.editMode = false;
$scope.createMode = false;
- $scope.foodCRUD = {}
+ // 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.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"] );
+ }
+
+ // CRUD: edit food
$scope.edit = function (foodToEdit) {
$scope.editMode = true;
$scope.foodCRUD = foodToEdit;
$scope.foodCRUD.rank_mode = "0"; //TODO: remove this when API implements it
};
+ // CRUD: create food
$scope.create = function () {
$scope.createMode = true;
$scope.foodCRUD = {}
$scope.foodCRUD.rank_mode = "0";
};
+ // CRUD: cancel
$scope.cancel = function () {
$scope.editMode = false;
$scope.createMode = false;
@@ -141,15 +178,6 @@ app.controller('FoodCtrl', ['$scope', '$http', function ($scope, $http) {
}]);
-app.controller('CategoryCtrl', ['$scope', function ($scope) {
- $scope.page.title = 'Categories';
- $scope.page.id = 'cat';
- $scope.page.yourVar = "globalStuff";
-
- $scope.var2 = "localStuff";
-}]);
-
-
app.controller('LoginCtrl', ['$scope', function ($scope) {
$scope.page.title = 'Login';
$scope.page.id = 'login';
diff --git a/assets/json/categories.json b/assets/json/categories.json
new file mode 100644
index 0000000..698bad0
--- /dev/null
+++ b/assets/json/categories.json
@@ -0,0 +1,18 @@
+{
+ "status": "ok",
+ "code": "200",
+ "data": [
+ {
+ "id": "1",
+ "name": "Fruit"
+ },
+ {
+ "id": "2",
+ "name": "Veggie"
+ },
+ {
+ "id": "3",
+ "name": "Fattie"
+ }
+ ]
+}
diff --git a/assets/json/data.json b/assets/json/foods.json
similarity index 100%
rename from assets/json/data.json
rename to assets/json/foods.json