Skip to content

Commit

Permalink
categories now pulls from api
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Morris committed Feb 28, 2017
1 parent 68161f2 commit 6d551b5
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 103 deletions.
2 changes: 1 addition & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ app.factory('Food', function ($resource) {
});

app.factory('Categories', function($resource) {
return $resource('assets/json/categories.json');
return $resource('http://foodbank.develop.digitalmediauconn.org/api/index.php/category/all');
});

// TODO: 'Nutrients' factory TEMPORARY
Expand Down
12 changes: 4 additions & 8 deletions app/pages/categories/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,28 @@ 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.removeRule = function(category, rule) {
for(var i = 0; i < category.rules.length; i++) {
/*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) {
Expand Down
14 changes: 7 additions & 7 deletions app/pages/categories/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<input placeholder="Placeholder" id="first_name" type="text" class="validate" ng-model="category.name">
<label for="first_name">Category Name</label>
</div>
<button class="btn grey lighten-2" style="float:right" ng-click="removeCategory(category)">Delete Category</button>
<button class="btn grey" style="float:right" ng-click="removeCategory(category)">Delete Category</button>
</div>
<div class="col s12">
<table class="categoryTable">
Expand All @@ -23,36 +23,36 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="rule in category.rules">
<tr ng-repeat="(rule_nutrient, rules) in category.rules">
<td>
<div class="input-field col s12">
<select>
<option ng-repeat="nutrient in nutrients" value="{{nutrient}}" ng-selected="nutrient==rule.nutrient">{{nutrient}}</option>
<option ng-repeat="nutrient in nutrients" value="{{nutrient}}" ng-selected="nutrient==rule_nutrient">{{nutrient}}</option>
</select>
</div>
</td>
<td ng-repeat="rank in rule.ranks">
<td ng-repeat="rank in rules">
<div class="input-field col s6">
<select>
<option ng-repeat="operation in operations" value="{{operation.name}}" ng-selected="operation.name==rank.operation">{{operation.symbol}}</option>
<option ng-repeat="operation in operations" value="{{operation.name}}" ng-selected="operation.name==rank.operator">{{operation.symbol}}</option>
</select>
</div>
<div class="input-field col s6">
<input type="number" value="{{rank.value | number}}">
<input type="number" value="{{rank.threshold | number}}">
</div>
</td>
<td><button class="btn red" ng-click="removeRule(category, rule)"><i class="material-icons">delete</i></button></td>
</tr>
</tbody>
</table>
<button ng-click="addRule(category.name)" class="btn">Add Rule</button>
<button class="btn green" ng-click="saveData(category)">Save</button>
</div>
</div>
</div>
</li>
</ul>
<button class="btn blue" ng-click="addCategory()" onclick="UpdateTextFields()">Add Category</button>
<button class="btn" ng-click="saveData()">Save</button>
</div>
<!--<div class="col s12 m3">
<div class="card grey darken-3">
Expand Down
170 changes: 83 additions & 87 deletions assets/js/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ app.factory('Food', function ($resource) {
});

app.factory('Categories', function($resource) {
return $resource('assets/json/categories.json');
return $resource('http://foodbank.develop.digitalmediauconn.org/api/index.php/category/all');
});

// TODO: 'Nutrients' factory TEMPORARY
Expand Down Expand Up @@ -149,92 +149,6 @@ app.controller('404Ctrl', ['$scope', function ($scope) {
$scope.var2 = "localStuff";
}]);



function GetRanks() {
return ['green', 'yellow'];
}

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'}];
}

function SaveData(categories) {
console.log('save');
}

app.controller('CategoryCtrl', ['$scope', 'Categories', function ($scope, Categories) {
$scope.page.title = 'Categories';
$scope.page.id = 'cat';
$scope.page.yourVar = "globalStuff";


// GET list of categories
Categories.get({}, function (data) {
$scope.categories = data.data;
});

$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', '$http', 'Foods', 'Food', 'Categories', function ($scope, $http, Foods, Food, Categories) {
$scope.page.title = 'Food';
$scope.page.id = 'food';
Expand Down Expand Up @@ -382,6 +296,88 @@ app.factory('loginService', ['$http', function($http) {
}
};
}]);


function GetRanks() {
return ['green', 'yellow'];
}

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'}];
}

function SaveData(categories) {
console.log('save');
}

app.controller('CategoryCtrl', ['$scope', 'Categories', function ($scope, Categories) {
$scope.page.title = 'Categories';
$scope.page.id = 'cat';
$scope.page.yourVar = "globalStuff";


// GET list of categories
Categories.get({}, function (data) {
$scope.categories = data.data;
});

$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.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('NutrientsCtrl', ['$scope', 'Nutrients', 'Nutrient', function ($scope, Nutrients, Nutrient) {
$scope.page.title = 'Nutrients';
$scope.page.id = 'nutrients';
Expand Down

0 comments on commit 6d551b5

Please sign in to comment.