|
|
@@ -5,124 +5,90 @@
|
|
|
<jsp:attribute name="head">
|
|
|
<script type="text/javascript" src="static/ndbDatabase.js"></script>
|
|
|
<script type="text/javascript" src="static/basicFoodEditor.js"></script>
|
|
|
+ <script type="text/javascript" src="static/searchBar.js"></script>
|
|
|
+ <script type="text/javascript" src="static/foodList.js"></script>
|
|
|
<script type="text/javascript">
|
|
|
- var app = angular.module('ingredients', ['ndbDatabase', 'basicFoodEditor', 'ui.bootstrap']);
|
|
|
- app.controller('SearchController', ['$scope', '$timeout', '$uibModal', 'NDBSearch', 'NDBReport', 'BasicFood',
|
|
|
- function($scope, $timeout, $uibModal, NDBSearch, NDBReport, BasicFood) {
|
|
|
- $scope.searchTerm = "";
|
|
|
- $scope.searchOffset = 1;
|
|
|
- $scope.searchSize = "10";
|
|
|
+ var app = angular.module('ingredients', ['ndbDatabase', 'basicFoodEditor', 'ui.bootstrap', 'ieat.ui']);
|
|
|
+ // TODO: Disable debug info in prod version
|
|
|
+ app.controller('SearchController', ['$scope', '$uibModal', 'NDBSearch', 'NDBFood', 'BasicFood',
|
|
|
+ function($scope, $uibModal, NDBSearch, NDBFood, BasicFood) {
|
|
|
$scope.searchResults = [];
|
|
|
-
|
|
|
- var searchTimeout = false;
|
|
|
- $scope.$watchGroup(['searchTerm', 'searchOffset'], function(newValues, oldValues, scope) {
|
|
|
- if (searchTimeout)
|
|
|
- {
|
|
|
- $timeout.cancel(searchTimeout);
|
|
|
- }
|
|
|
- if ($scope.searchTerm.length >= 3)
|
|
|
+ $scope.table = [
|
|
|
{
|
|
|
- searchTimeout = $timeout(function() {
|
|
|
- NDBSearch.get({
|
|
|
- key: "${ndbKey}",
|
|
|
- "query": $scope.searchTerm
|
|
|
- }, function(data) {
|
|
|
- console.debug(data);
|
|
|
- $scope.searchResults = data;
|
|
|
- }, function (err) {
|
|
|
- console.error(err);
|
|
|
- });
|
|
|
- }, 100);
|
|
|
+ name: "NDB #",
|
|
|
+ col: "ndbno",
|
|
|
+ size: 1
|
|
|
+ }, {
|
|
|
+ name: "Name",
|
|
|
+ col: "name",
|
|
|
+ size: 6
|
|
|
+ }, {
|
|
|
+ name: "Group",
|
|
|
+ col: "group"
|
|
|
+ }, {
|
|
|
+ name: "Manufacturer",
|
|
|
+ col: "manu"
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
- var ndbToIeat = function(foodData) {
|
|
|
- return new BasicFood({
|
|
|
- ndbno: parseInt(foodData.ndbno),
|
|
|
- name: foodData.name,
|
|
|
- food_group: foodData.fg,
|
|
|
- default_unit: foodData.ru,
|
|
|
- calories_p_100: foodData.nutrients.find(function (nutrient) {
|
|
|
- // TODO: Replace 208 with soft-loaded value from database
|
|
|
- // 208 is the id for kCalories
|
|
|
- return nutrient.nutrient_id == 208;
|
|
|
- }).value
|
|
|
- });
|
|
|
+ ];
|
|
|
+
|
|
|
+ $scope.searchFn = function(searchTerm) {
|
|
|
+ NDBSearch.get({
|
|
|
+ "key": "${ndbKey}",
|
|
|
+ "query": searchTerm
|
|
|
+ }, function(data) {
|
|
|
+ $scope.searchResults = data;
|
|
|
+ }, function (err) {
|
|
|
+ // TODO: Actual error handling
|
|
|
+ console.error(err);
|
|
|
+ })
|
|
|
};
|
|
|
|
|
|
- $scope.promptWindow = function(ndbno) {// {ndb.api.key}
|
|
|
- var foodRequest = NDBReport.get(
|
|
|
+ $scope.promptWindow = function(item) {
|
|
|
+ var foodRequest = NDBFood.get(
|
|
|
{
|
|
|
"key": "${ndbKey}",
|
|
|
- "ndbno": ndbno,
|
|
|
+ "ndbno": item.ndbno,
|
|
|
"type": "f"
|
|
|
}).$promise.then(function(data) {
|
|
|
- return ndbToIeat(data)
|
|
|
+ return BasicFood.fromNdb(data);
|
|
|
}, function (err) {
|
|
|
// TODO: Proper error handling
|
|
|
console.error(err);
|
|
|
});
|
|
|
- $uibModal.open({
|
|
|
- // TODO: Figure out what these are and how they work
|
|
|
- //ariaLabelledBy: 'modal-title',
|
|
|
- //ariaDescribedBy: 'modal-body',
|
|
|
- templateUrl: '${url}/static/templates/editBasicFood.html',
|
|
|
- controller: 'BasicFoodEditorController',
|
|
|
- size: "md",
|
|
|
- resolve: {
|
|
|
- foodData: function() {return foodRequest;},
|
|
|
- ndbKey: function() {return "${ndbKey}";}
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
+ $uibModal.open({
|
|
|
+ // TODO: Figure out what these are and how they work
|
|
|
+ //ariaLabelledBy: 'modal-title',
|
|
|
+ //ariaDescribedBy: 'modal-body',
|
|
|
+ templateUrl: '${url}/static/templates/editBasicFood.html',
|
|
|
+ controller: 'BasicFoodEditorController',
|
|
|
+ size: "md",
|
|
|
+ resolve: {
|
|
|
+ foodData: function() {return foodRequest;},
|
|
|
+ ndbKey: function() {return "${ndbKey}";}
|
|
|
+ }
|
|
|
+ }).result.then(function() {
|
|
|
+ // TODO: Push put response into array.
|
|
|
+ });
|
|
|
+ };
|
|
|
}]);
|
|
|
</script>
|
|
|
</jsp:attribute>
|
|
|
<jsp:body>
|
|
|
- <div class="section container" data-ng-app="ingredients" data-ng-controller="SearchController">
|
|
|
+ <div class="section container"
|
|
|
+ data-ng-app="ingredients"
|
|
|
+ data-ng-controller="SearchController">
|
|
|
<h2>Ingredient Querier</h2>
|
|
|
<div class="form-group">
|
|
|
<label for="search">Search: </label>
|
|
|
- <input type="text" class="form-control input-sm" id="search" data-ng-model="searchTerm" />
|
|
|
- </div>
|
|
|
- <table class="table table-striped table-hover table-responsive">
|
|
|
- <tr>
|
|
|
- <th class="col-md-1"> </th>
|
|
|
- <th class="col-md-1">NDB #</th>
|
|
|
- <th class="col-md-6">Name</th>
|
|
|
- <th class="col-md-3">Group</th>
|
|
|
- <th class="col-md-3">Manufacturer</th>
|
|
|
- </tr>
|
|
|
- <tr data-ng-repeat="item in searchResults | limitTo:searchSize:searchSize*(searchOffset-1)"
|
|
|
- data-ng-click="item.checked = !item.checked">
|
|
|
- <th><input type="button"
|
|
|
- value="Add"
|
|
|
- class="checkbox-inline"
|
|
|
- data-ng-click="promptWindow(item.ndbno)" /></th>
|
|
|
- <td>{{ ::item.ndbno }}</td>
|
|
|
- <td>{{ ::item.name }}</td>
|
|
|
- <td>{{ ::item.group }}</td>
|
|
|
- <td>{{ ::item.manu }}</td>
|
|
|
- </tr>
|
|
|
- </table>
|
|
|
- <div class="form-group col-xs-5">
|
|
|
- <ul class="pagination-sm"
|
|
|
- style="margin: 0;"
|
|
|
- data-uib-pagination=""
|
|
|
- data-boundary-links="true"
|
|
|
- force-ellipses="true"
|
|
|
- data-total-items="searchResults.length"
|
|
|
- data-ng-model="searchOffset"
|
|
|
- data-items-per-page="searchSize"></ul>
|
|
|
- </div>
|
|
|
- <div class="form-group form-group-sm col-xs-2 pull-right">
|
|
|
- <select id="sizeSelector" class="form-control input-sm" data-ng-model="searchSize">
|
|
|
- <option>10</option>
|
|
|
- <option>20</option>
|
|
|
- <option>30</option>
|
|
|
- <option>40</option>
|
|
|
- </select>
|
|
|
+ <search-bar id="search"
|
|
|
+ data-on-change="searchFn(searchTerm);"
|
|
|
+ data-delay="100">
|
|
|
+ </search-bar>
|
|
|
</div>
|
|
|
+ <food-list data-table-data="searchResults"
|
|
|
+ data-structure="table"
|
|
|
+ data-on-select="promptWindow(item)">
|
|
|
+ </food-list>
|
|
|
</div>
|
|
|
</jsp:body>
|
|
|
</t:template>
|