Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'hotfix/categories-operator-selection'
  • Loading branch information
Timothy Morris committed Apr 7, 2017
2 parents 1577c37 + 752c8d8 commit 7e26bda
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 97 deletions.
9 changes: 1 addition & 8 deletions app/pages/categories/view.html
Expand Up @@ -6,13 +6,6 @@
<div class="collapsible-header">{{ category.name }}</div>
<div class="collapsible-body">
<div class="row">
<!--<div class="col s12">
<div class="input-field col s6">
<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" style="float:right" ng-click="removeCategory(category)">Delete Category</button>
</div>-->
<div class="col s6" ng-repeat="rule in category.rules[0]">
<div class="card">
<div class="card-content">
Expand All @@ -29,7 +22,7 @@
</div>
<div class="col s4">
<select>
<option ng-repeat="operation in operations" value="{{operation.name}}" ng-selected="operation.name==rank.operator">{{operation.symbol}}</option>
<option ng-repeat="operation in operations" value="{{operation.name}}" ng-selected="operation.name==rule.operator">{{operation.symbol}}</option>
</select>
</div>
<div class="col s4">
Expand Down
178 changes: 89 additions & 89 deletions assets/js/bundle.js
Expand Up @@ -154,6 +154,95 @@ app.controller('404Ctrl', ['$scope', function ($scope) {
$scope.var2 = "localStuff";
}]);


function GetRanks() {
return [{name: 'green', id: 1}, {name: 'yellow', id: 2}];
}

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

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


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

$scope.ranks = GetRanks();

$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) {
return i;
}
}
return -1;
};

$scope.addRule = function(categoryName) {
var categoryIndex = $scope.getCategoryIndexFromName(categoryName);
if(categoryIndex != -1) {
$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[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.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(category) {
$http.post('http://foodbank.develop.digitalmediauconn.org/api/index.php/rules/saveBatch/' + category.id, category.rules[0]);
};
}]);

app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'FoodDetail', 'Categories', '$cookies', function ($scope, $http, Foods, FoodDetail, Categories, $cookies) {
$scope.page.title = 'Food';
$scope.page.id = 'food';
Expand Down Expand Up @@ -271,95 +360,6 @@ app.controller('FoodCtrl', ['$scope', '$http', 'Foods', 'FoodDetail', 'Categorie

}]);


function GetRanks() {
return [{name: 'green', id: 1}, {name: 'yellow', id: 2}];
}

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

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


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

$scope.ranks = GetRanks();

$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) {
return i;
}
}
return -1;
};

$scope.addRule = function(categoryName) {
var categoryIndex = $scope.getCategoryIndexFromName(categoryName);
if(categoryIndex != -1) {
$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[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.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(category) {
$http.post('http://foodbank.develop.digitalmediauconn.org/api/index.php/rules/saveBatch/' + category.id, category.rules[0]);
};
}]);

app.controller('LoginCtrl', ['$scope', 'loginService', function ($scope, loginService) {
$scope.page.title = 'Login';
$scope.page.id = 'login';
Expand Down

0 comments on commit 7e26bda

Please sign in to comment.