|
@@ -8,26 +8,16 @@
|
|
|
<script type="text/javascript" src="static/searchBar.js"></script>
|
|
<script type="text/javascript" src="static/searchBar.js"></script>
|
|
|
<script type="text/javascript" src="static/paginatedTable.js"></script>
|
|
<script type="text/javascript" src="static/paginatedTable.js"></script>
|
|
|
<script type="text/javascript">
|
|
<script type="text/javascript">
|
|
|
- var app = angular.module('ingredients', ['basicFoodEditor', 'ui.bootstrap', 'ieat.ui']);
|
|
|
|
|
|
|
+ var app = angular.module('ingredients', ['ui.bootstrap', 'ieat.ui', 'ieat.ui.editors']);
|
|
|
app.controller('SearchController', ['$scope', '$timeout', '$uibModal', 'Food', 'BasicFood', 'Recipe',
|
|
app.controller('SearchController', ['$scope', '$timeout', '$uibModal', 'Food', 'BasicFood', 'Recipe',
|
|
|
- function($scope, $timeout, $uibModal, Food, BasicFood, Recipe) {
|
|
|
|
|
- $scope.table = [{
|
|
|
|
|
- name: "Name",
|
|
|
|
|
- col: "name",
|
|
|
|
|
- size: 6
|
|
|
|
|
- }, {
|
|
|
|
|
- name: "Group",
|
|
|
|
|
- col: "food_group"
|
|
|
|
|
- }, {
|
|
|
|
|
- name: "Calories",
|
|
|
|
|
- col: "calories_p_100"
|
|
|
|
|
- }
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ function($scope, $timeout, $uibModal, Food, BasicFood, Recipe) {
|
|
|
$scope.searchFn = function(searchTerm) {
|
|
$scope.searchFn = function(searchTerm) {
|
|
|
|
|
+ if (searchTerm) {
|
|
|
|
|
+ this.searchTerm = searchTerm;
|
|
|
|
|
+ }
|
|
|
Food.query({
|
|
Food.query({
|
|
|
"key": "${ndbKey}",
|
|
"key": "${ndbKey}",
|
|
|
- "query": searchTerm
|
|
|
|
|
|
|
+ "query": this.searchTerm
|
|
|
}, function(data) {
|
|
}, function(data) {
|
|
|
$scope.searchResults = data;
|
|
$scope.searchResults = data;
|
|
|
}, function (err) {
|
|
}, function (err) {
|
|
@@ -37,22 +27,60 @@
|
|
|
};
|
|
};
|
|
|
$scope.searchFn("");
|
|
$scope.searchFn("");
|
|
|
|
|
|
|
|
- $scope.promptWindow = function(item) {
|
|
|
|
|
|
|
+ var modalCtrl = ['$scope', '$uibModalInstance', 'food', function($scope, $uibModalInstance, food) {
|
|
|
|
|
+ $scope.food = food;
|
|
|
|
|
+ $scope.submit = $uibModalInstance.close;
|
|
|
|
|
+ $scope.dismiss = $uibModalInstance.dismiss;
|
|
|
|
|
+ }];
|
|
|
|
|
+ var promptWindow = function(item) {
|
|
|
$uibModal.open({
|
|
$uibModal.open({
|
|
|
// TODO: Figure out what these are and how they work
|
|
// TODO: Figure out what these are and how they work
|
|
|
//ariaLabelledBy: 'modal-title',
|
|
//ariaLabelledBy: 'modal-title',
|
|
|
//ariaDescribedBy: 'modal-body',
|
|
//ariaDescribedBy: 'modal-body',
|
|
|
- templateUrl: 'static/templates/editBasicFood.html',
|
|
|
|
|
- controller: 'BasicFoodEditorController',
|
|
|
|
|
- size: "md",
|
|
|
|
|
|
|
+ templateUrl: "modal",
|
|
|
resolve: {
|
|
resolve: {
|
|
|
- foodData: function() {return item.cast();},
|
|
|
|
|
- ndbKey: function() {return "${ndbKey}";}
|
|
|
|
|
|
|
+ food: function() {return item.cast();}
|
|
|
|
|
+ },
|
|
|
|
|
+ controller: modalCtrl,
|
|
|
|
|
+ size: "md"
|
|
|
|
|
+ }).result.then(function(food) {
|
|
|
|
|
+ food.$save(function() {
|
|
|
|
|
+ $scope.searchFn();
|
|
|
|
|
+ }, function(err) {
|
|
|
|
|
+ // TODO: Error handling
|
|
|
|
|
+ console.error(err);
|
|
|
|
|
+ });
|
|
|
|
|
+ }, function(reason) {
|
|
|
|
|
+ if (reason == "delete") {
|
|
|
|
|
+ item.$delete(function() {
|
|
|
|
|
+ $scope.searchFn();
|
|
|
|
|
+ }, function(err) {
|
|
|
|
|
+ // TODO: Error handling
|
|
|
|
|
+ console.error(err);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ console.debug("Dismissed");
|
|
|
}
|
|
}
|
|
|
- }).result.then(function() {
|
|
|
|
|
- // TODO: Push post response into array.
|
|
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ $scope.table = [{
|
|
|
|
|
+ defaultValue: "Edit",
|
|
|
|
|
+ onClick: promptWindow,
|
|
|
|
|
+ size: 1
|
|
|
|
|
+ }, {
|
|
|
|
|
+ name: "Name",
|
|
|
|
|
+ col: "name",
|
|
|
|
|
+ size: 6
|
|
|
|
|
+ }, {
|
|
|
|
|
+ name: "Group",
|
|
|
|
|
+ col: "food_group"
|
|
|
|
|
+ }, {
|
|
|
|
|
+ name: "Calories",
|
|
|
|
|
+ col: "calories_p_100"
|
|
|
|
|
+ }
|
|
|
|
|
+ ];
|
|
|
}]);
|
|
}]);
|
|
|
</script>
|
|
</script>
|
|
|
</jsp:attribute>
|
|
</jsp:attribute>
|
|
@@ -63,11 +91,21 @@
|
|
|
<label for="search">Search: </label>
|
|
<label for="search">Search: </label>
|
|
|
<search-bar id="search" data-on-change="searchFn(searchTerm);" data-delay="100" />
|
|
<search-bar id="search" data-on-change="searchFn(searchTerm);" data-delay="100" />
|
|
|
</div>
|
|
</div>
|
|
|
- <paginated-table data-table-data="searchResults"
|
|
|
|
|
- data-structure="table"
|
|
|
|
|
- data-select-text="Edit"
|
|
|
|
|
- data-on-select="promptWindow(item)">
|
|
|
|
|
|
|
+ <paginated-table data-table-data="searchResults" data-structure="table">
|
|
|
</paginated-table>
|
|
</paginated-table>
|
|
|
|
|
+
|
|
|
|
|
+ <script type="text/ng-template" id="modal">
|
|
|
|
|
+ <basic-food-editor data-ndb-key="${ndbKey}" data-food="food"></basic-food-editor>
|
|
|
|
|
+ <div style="width: 100%; text-align: right; padding-right: 1em; padding-bottom: 1em;">
|
|
|
|
|
+ <button type="button"
|
|
|
|
|
+ class="btn btn-success"
|
|
|
|
|
+ data-ng-click="submit(food);">Submit</button>
|
|
|
|
|
+ <button type="button" class="btn" data-ng-click="dismiss();">Cancel</button>
|
|
|
|
|
+ <button type="button"
|
|
|
|
|
+ class="btn btn-danger"
|
|
|
|
|
+ data-ng-click="dismiss('delete');">Delete</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </script>
|
|
|
</div>
|
|
</div>
|
|
|
</jsp:body>
|
|
</jsp:body>
|
|
|
</t:template>
|
|
</t:template>
|