browseFood.jsp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
  3. <t:template>
  4. <jsp:attribute name="title">Manage 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/paginatedTable.js"></script>
  10. <script type="text/javascript">
  11. var app = angular.module('ingredients', ['basicFoodEditor', 'ui.bootstrap', 'ieat.ui']);
  12. app.controller('SearchController', ['$scope', '$timeout', '$uibModal', 'Food', 'BasicFood', 'Recipe',
  13. function($scope, $timeout, $uibModal, Food, BasicFood, Recipe) {
  14. $scope.table = [{
  15. name: "Name",
  16. col: "name",
  17. size: 6
  18. }, {
  19. name: "Group",
  20. col: "food_group"
  21. }, {
  22. name: "Calories",
  23. col: "calories_p_100"
  24. }
  25. ];
  26. $scope.searchFn = function(searchTerm) {
  27. Food.query({
  28. "key": "${ndbKey}",
  29. "query": searchTerm
  30. }, function(data) {
  31. $scope.searchResults = data;
  32. }, function (err) {
  33. // TODO: Actual error handling
  34. console.error(err);
  35. })
  36. };
  37. $scope.searchFn("");
  38. $scope.promptWindow = function(item) {
  39. $uibModal.open({
  40. // TODO: Figure out what these are and how they work
  41. //ariaLabelledBy: 'modal-title',
  42. //ariaDescribedBy: 'modal-body',
  43. templateUrl: 'static/templates/editBasicFood.html',
  44. controller: 'BasicFoodEditorController',
  45. size: "md",
  46. resolve: {
  47. foodData: function() {return item.cast();},
  48. ndbKey: function() {return "${ndbKey}";}
  49. }
  50. }).result.then(function() {
  51. // TODO: Push post response into array.
  52. });
  53. };
  54. }]);
  55. </script>
  56. </jsp:attribute>
  57. <jsp:body>
  58. <div class="section container" data-ng-app="ingredients" data-ng-controller="SearchController">
  59. <h2>Ingredients</h2>
  60. <div class="form-group">
  61. <label for="search">Search: </label>
  62. <search-bar id="search" data-on-change="searchFn(searchTerm);" data-delay="100" />
  63. </div>
  64. <paginated-table data-table-data="searchResults"
  65. data-structure="table"
  66. data-select-text="Edit"
  67. data-on-select="promptWindow(item)">
  68. </paginated-table>
  69. </div>
  70. </jsp:body>
  71. </t:template>