Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <th:block th:include="~{fragments/head}"></th:block>
  5. <meta charset="UTF-8">
  6. </head>
  7. <body>
  8. <div class="container-fluid">
  9. <header>
  10. <th:block th:include="~{fragments/navbar}"></th:block>
  11. </header>
  12. <div class="container-fluid">
  13. <form class="form-inline">
  14. <div class="mr-5">
  15. <h1 id="selector">Your choice</h1>
  16. </div>
  17. <div class="form-check form-check-inline">
  18. <input class="form-check-input" type="radio"
  19. name="virusesFetchRadio" id="virusesFetchRadio" value="option1">
  20. <label class="form-check-label" for="virusesFetchRadio">Viruses</label>
  21. </div>
  22. <div class="form-check form-check-inline">
  23. <input class="form-check-input" type="radio"
  24. name="capitalsFetchRadio" id="capitalsFetchRadio" value="option2">
  25. <label class="form-check-label" for="capitalsFetchRadio">Capitals</label>
  26. </div>
  27. </form>
  28. <div id="selectMessage" style="text-align: center;">
  29. <h1>Select what data you want to visualize!</h1>
  30. </div>
  31. </div>
  32.  
  33. <script>
  34.  
  35. $("#capitalsFetchRadio").click(() => {
  36. if ($("#virusesFetchRadio").prop("checked") || !($("#capitalsFetchRadio").prop("checked") && $("#virusesFetchRadio").prop("checked"))) {
  37.  
  38. $("#tableBody").empty();
  39. $("#tableHead").empty();
  40. $("#headerText").empty();
  41.  
  42. $("#virusesFetchRadio").prop("checked", false);
  43. $("#selectMessage").remove();
  44. $("#headerText").append("All Capitals");
  45.  
  46. const tableHeaders =
  47. "<tr> <th scope=\"col\">#</th>" +
  48. "<th scope=\"col\">Name</th>" +
  49. "<th scope=\"col\">Latitude</th>" +
  50. "<th scope=\"col\">Longitude</th>" + "</tr>";
  51.  
  52. $("#tableHead").append(tableHeaders);
  53. fetch("http://localhost:8000/capitals/fetch")
  54. .then((response) => response.json())
  55. .then((json) => json.forEach((capital) => {
  56.  
  57. const capitalDetails =
  58. "<tr>" +
  59. "<td>" + capital.id + "</td>" +
  60. "<td>" + capital.name + "</td>" +
  61. "<td>" + capital.latitude + "</td>" +
  62. "<td>" + capital.longitude + "</td>" +
  63. "</tr>";
  64.  
  65. $("#tableBody").append(capitalDetails);
  66. }));
  67. }
  68. });
  69. </script>
  70.  
  71. <script>
  72. $("#virusesFetchRadio").click(() => {
  73. if ($("#capitalsFetchRadio").prop("checked") || !($("#capitalsFetchRadio").prop("checked") && $("#virusesFetchRadio").prop("checked"))) {
  74.  
  75. $("#tableBody").empty();
  76. $("#tableHead").empty();
  77. $("#headerText").empty();
  78.  
  79. $("#capitalsFetchRadio").prop("checked", false);
  80. $("#selectMessage").remove();
  81. $("#headerText").append("All Viruses");
  82.  
  83. const tableHeaders =
  84. "<tr> <th scope=\"col\">#</th>" +
  85. "<th scope=\"col\">Name</th>" +
  86. " <th scope=\"col\">Magnitude</th>" +
  87. " <th scope=\"col\">Released On</th>" +
  88. " <th scope=\"col\"></th>" +
  89. " <th scope=\"col\"></th>" +
  90. +"</tr>";
  91.  
  92. $("#tableHead").append(tableHeaders);
  93. fetch("http://localhost:8000/viruses/fetch")
  94. .then((response) => response.json())
  95. .then((json) => json.forEach((capital) => {
  96.  
  97. const capitalDetails =
  98. "<tr>" +
  99. "<td>" + capital.id + "</td>" +
  100. "<td>" + capital.name + "</td>" +
  101. "<td>" + capital.latitude + "</td>" +
  102. "<td>" + capital.longitude + "</td>"
  103. + "</tr>";
  104.  
  105. $("#tableBody").append(capitalDetails);
  106. }));
  107. }
  108. });
  109. </script>
  110.  
  111.  
  112. <div class="container mt-4">
  113. <h1 id="headerText"></h1>
  114. <table id="showTable" class="table">
  115. <thead id="tableHead">
  116. </thead>
  117. <tbody id="tableBody">
  118. </tbody>
  119. </table>
  120. </div>
  121. </div>
  122. </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement