Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…/foodbank into develop
  • Loading branch information
Joel Salisbury committed Feb 13, 2017
2 parents e37c370 + f9cb184 commit 51ffe5d
Show file tree
Hide file tree
Showing 24 changed files with 7,267 additions and 365 deletions.
34 changes: 33 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
var app = angular.module('app', ['ngRoute']);
var app = angular.module('app', ['ngRoute', 'ngResource']);

// Root controllers in /root/ folder
// Page controllers in /pages/[your-page] folder

// Factories

// TODO: 'Foods' factory TEMPORARY
app.factory('Foods', function($resource) {
return $resource('assets/json/foods.json');
});

// Just does a PUT request when u call Food.update
app.factory('Food', function ($resource) {
// {food: '@id'} means replace :food with $scope.foodCRUD.id
var data = $resource('http://foodbank.develop.digitalmediauconn.org/api/food/:food', {food: '@id'}, {
update:{ method:'PUT' }
});
return data;
});

app.factory('Categories', function($resource) {
return $resource('assets/json/categories.json');
});

// TODO: 'Nutrients' factory TEMPORARY
app.factory('Nutrients', function($resource) {
return $resource('assets/json/nutrients.json');
});

app.factory('Nutrient', function ($resource) {
var data = $resource('http://foodbank.develop.digitalmediauconn.org/api/nutrients/:nutrient', {nutrient: '@id'}, {
update:{ method:'PUT' }
});
return data;
});
19 changes: 6 additions & 13 deletions app/app.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,15 @@ app.config( function ($routeProvider, $locationProvider) {
controller: 'FoodCtrl'
})

// Sandbox Demo
.when('/news', {
templateUrl: 'app/sandbox/news.html',
controller: 'NewsCtrl'
})

// Sandbox Demo
.when('/competitions', {
templateUrl: 'app/sandbox/competition.html',
controller: 'CompetitionCtrl'
.when('/nutrients', {
templateUrl: 'app/pages/nutrients/view.html',
controller: 'NutrientsCtrl'
})

// Sandbox Demo
.when('/todo', {
templateUrl: 'app/sandbox/todo.html',
controller: 'TodoCtrl'
.when('/rest', {
templateUrl: 'app/sandbox/rest.html',
controller: 'RestCtrl'
})

// 404 Not Found
Expand Down
115 changes: 113 additions & 2 deletions app/pages/categories/ctrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,118 @@

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: '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', 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();

$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);
};
}]);
13 changes: 13 additions & 0 deletions app/pages/categories/style.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.collapsible-body {
padding: 1em;
box-sizing:border-box;
}

.card-title,
.collapsible-header {
text-transform:capitalize;
}

select {
display:block!important;
}
Loading

0 comments on commit 51ffe5d

Please sign in to comment.