ingredients.scala.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. @*
  2. * This template is called from the `index` template. This template
  3. * handles the rendering of the page header and body tags. It takes
  4. * two arguments, a `String` for the title of the page and an `Html`
  5. * object to insert into the body of the page.
  6. *@
  7. @()
  8. <!DOCTYPE html>
  9. <html lang="en">
  10. <head>
  11. <title>Ingredients</title>
  12. <meta name="viewport" content="width=device-width, initial-scale=1" />
  13. <link rel="stylesheet" type="text/css" href="@routes.Assets.versioned("stylesheets/main.css")" />
  14. <link rel="stylesheet" type="text/css" href="@routes.Assets.versioned("lib/bootstrap/css/bootstrap.min.css")" />
  15. <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")" />
  16. <script type="text/javascript" src="@routes.Assets.versioned("lib/angularjs/angular.min.js")"></script>
  17. <script type="text/javascript" src="@routes.Assets.versioned("lib/angularjs/angular-resource.min.js")"></script>
  18. <script type="text/javascript"
  19. src="@routes.Assets.versioned("lib/angular-ui-bootstrap/ui-bootstrap-tpls.min.js")"></script>
  20. <script type="text/javascript" src="@routes.Assets.versioned("javascripts/ndbDatabase.js")"></script>
  21. <script type="text/javascript">
  22. var app = angular.module('ingredients', ['ndbDatabase', 'ui.bootstrap']);
  23. app.controller('SearchController', ['$scope', '$timeout', 'NDBSearch', function($scope, $timeout, NDBSearch) {
  24. $scope.searchTerm = "";
  25. $scope.searchOffset = 1;
  26. $scope.searchSize = "10";
  27. $scope.searchResults = [];
  28. var searchTimeout = false;
  29. $scope.$watchGroup(['searchTerm', 'searchOffset'], function(newValues, oldValues, scope) {
  30. if (searchTimeout)
  31. {
  32. $timeout.cancel(searchTimeout);
  33. }
  34. if ($scope.searchTerm.length >= 3)
  35. {
  36. searchTimeout = $timeout(function() {
  37. NDBSearch.get({key: "CfiHcUnSf0RX0jBuqiWjDK2d2ziOmoZG15CTdhQn",
  38. "query": $scope.searchTerm
  39. }, function(data) {
  40. console.log(data);
  41. $scope.searchResults = data;
  42. }, function (err) {
  43. console.error(err);
  44. });
  45. }, 100);
  46. }
  47. });
  48. $scope.focusItem = function(ndbno) {
  49. };
  50. }]);
  51. </script>
  52. </head>
  53. <body data-ng-app="ingredients">
  54. <div class="section container" data-ng-controller="SearchController">
  55. <h2>Ingredient Querier</h2>
  56. <div class="form-group">
  57. <label for="search">Search: </label>
  58. <input type="text" class="form-control input-sm" id="search" data-ng-model="searchTerm" />
  59. </div>
  60. <table class="table table-striped table-hover table-responsive">
  61. <tr>
  62. <th class="col-md-1"> </th>
  63. <th class="col-md-1">NDB #</th>
  64. <th class="col-md-6">Name</th>
  65. <th class="col-md-3">Group</th>
  66. <th class="col-md-3">Manufacturer</th>
  67. </tr>
  68. <tr data-ng-repeat="item in searchResults | limitTo:searchSize:searchSize*(searchOffset-1)"
  69. data-ng-click="item.checked = !item.checked">
  70. <th><input type="checkbox" class="checkbox-inline" data-ng-model="item.checked"></th>
  71. <td>{{ ::item.ndbno }}</td>
  72. <td>{{ ::item.name }}</td>
  73. <td>{{ ::item.group }}</td>
  74. <td>{{ ::item.manu }}</td>
  75. </tr>
  76. </table>
  77. <div class="form-group col-xs-5">
  78. <ul class="pagination-sm"
  79. style="margin: 0;"
  80. data-uib-pagination=""
  81. data-total-items="searchResults.length"
  82. data-ng-model="searchOffset"
  83. data-items-per-page="searchSize"></ul>
  84. </div>
  85. <div class="form-group form-group-sm col-xs-2 pull-right">
  86. <select id="sizeSelector" class="form-control input-sm" data-ng-model="searchSize">
  87. <option>10</option>
  88. <option>20</option>
  89. <option>30</option>
  90. <option>40</option>
  91. </select>
  92. </div>
  93. </div>
  94. </body>
  95. </html>