| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
- <t:template>
- <jsp:attribute name="title">Add Food</jsp:attribute>
- <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">
- var app = angular.module('ingredients', ['basicFoodEditor', 'ui.bootstrap']);
- app.controller('SearchController', ['$scope', '$timeout', '$uibModal', 'Food', 'BasicFood', 'Recipe',
- function($scope, $timeout, $uibModal, Food, BasicFood, Recipe) {
- $scope.searchTerm = "";
- $scope.searchOffset = 1;
- $scope.searchSize = "10";
-
- var searchTimeout = false;
- var searchFn = function() {
- Food.query({
- "query": $scope.searchTerm
- }, function(data) {
- $scope.searchResults = data;
- }, function (err) {
- console.error(err);
- });
- };
- $scope.searchResults = searchFn();
-
- $scope.$watchGroup(['searchTerm', 'searchOffset'], function(newValues, oldValues, scope) {
- if (searchTimeout)
- {
- $timeout.cancel(searchTimeout);
- }
- if ($scope.searchTerm.length >= 3)
- {
- searchTimeout = $timeout(searchFn, 100);
- }
- });
- function getResource(type) {
- switch (type) {
- case "BasicFood":
- return BasicFood;
- case "Recipe":
- return Recipe;
- default:
- throw "Unrecognized food type: "+type;
- }
- }
-
- $scope.promptWindow = function(id, type) {
- var item = getResource(type).get({"id": id});
- $uibModal.open({
- // TODO: Figure out what these are and how they work
- //ariaLabelledBy: 'modal-title',
- //ariaDescribedBy: 'modal-body',
- templateUrl: 'static/templates/editBasicFood.html',
- controller: 'BasicFoodEditorController',
- size: "md",
- resolve: {
- foodData: function() {return item;}
- }
- }).result.then(searchFn);
- };
- }]);
- </script>
- </jsp:attribute>
- <jsp:body>
- <div class="section container" data-ng-app="ingredients" data-ng-controller="SearchController">
- <h2>Ingredients</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-6">Name</th>
- <th class="col-md-3">Group</th>
- <th class="col-md-3">Calories</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="Edit" class="checkbox-inline" data-ng-click="promptWindow(item.id, item.type)" />
- </th>
- <td>{{ ::item.name }}</td>
- <td>{{ ::item.food_group }}</td>
- <td>{{ ::item.calories_p_100 }}</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>
- </div>
- </div>
- </jsp:body>
- </t:template>
|