addFood.jsp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
  3. <t:template>
  4. <jsp:attribute name="title">Add Food</jsp:attribute>
  5. <jsp:attribute name="head">
  6. <script type="text/javascript" src="static/ndbDatabase.js"></script>
  7. <script type="text/javascript" src="static/basicFoodEditor.js"></script>
  8. <script type="text/javascript" src="static/searchBar.js"></script>
  9. <script type="text/javascript" src="static/foodList.js"></script>
  10. <script type="text/javascript">
  11. var app = angular.module('ingredients', ['ndbDatabase', 'basicFoodEditor', 'ui.bootstrap', 'ieat.ui']);
  12. // TODO: Disable debug info in prod version
  13. app.controller('SearchController', ['$scope', '$uibModal', 'NDBSearch', 'NDBFood', 'BasicFood',
  14. function($scope, $uibModal, NDBSearch, NDBFood, BasicFood) {
  15. $scope.searchResults = [];
  16. $scope.table = [
  17. {
  18. name: "NDB #",
  19. col: "ndbno",
  20. size: 1
  21. }, {
  22. name: "Name",
  23. col: "name",
  24. size: 6
  25. }, {
  26. name: "Group",
  27. col: "group"
  28. }, {
  29. name: "Manufacturer",
  30. col: "manu"
  31. }
  32. ];
  33. $scope.searchFn = function(searchTerm) {
  34. NDBSearch.get({
  35. "key": "${ndbKey}",
  36. "query": searchTerm
  37. }, function(data) {
  38. $scope.searchResults = data;
  39. }, function (err) {
  40. // TODO: Actual error handling
  41. console.error(err);
  42. })
  43. };
  44. $scope.promptWindow = function(item) {
  45. var foodRequest = NDBFood.get(
  46. {
  47. "key": "${ndbKey}",
  48. "ndbno": item.ndbno,
  49. "type": "f"
  50. }).$promise.then(function(data) {
  51. return BasicFood.fromNdb(data);
  52. }, function (err) {
  53. // TODO: Proper error handling
  54. console.error(err);
  55. });
  56. $uibModal.open({
  57. // TODO: Figure out what these are and how they work
  58. //ariaLabelledBy: 'modal-title',
  59. //ariaDescribedBy: 'modal-body',
  60. templateUrl: '${url}/static/templates/editBasicFood.html',
  61. controller: 'BasicFoodEditorController',
  62. size: "md",
  63. resolve: {
  64. foodData: function() {return foodRequest;},
  65. ndbKey: function() {return "${ndbKey}";}
  66. }
  67. }).result.then(function() {
  68. // TODO: Push put response into array.
  69. });
  70. };
  71. }]);
  72. </script>
  73. </jsp:attribute>
  74. <jsp:body>
  75. <div class="section container"
  76. data-ng-app="ingredients"
  77. data-ng-controller="SearchController">
  78. <h2>Ingredient Querier</h2>
  79. <div class="form-group">
  80. <label for="search">Search: </label>
  81. <search-bar id="search"
  82. data-on-change="searchFn(searchTerm);"
  83. data-delay="100">
  84. </search-bar>
  85. </div>
  86. <food-list data-table-data="searchResults"
  87. data-structure="table"
  88. data-on-select="promptWindow(item)">
  89. </food-list>
  90. </div>
  91. </jsp:body>
  92. </t:template>