You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
11 KiB

5 years ago
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Orna Tools - atr0phy.net</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" contents="width=device-width, initial-scale=1">
  7. <!-- <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"> -->
  8. <!-- UIkit CSS -->
  9. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/css/uikit.min.css" />
  10. <!-- UIkit JS -->
  11. <script src="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/js/uikit.min.js"></script>
  12. <script src="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/js/uikit-icons.min.js"></script>
  13. <script src="https://cdn.jsdelivr.net/combine/npm/tablesort@5.2.0,npm/tablesort@5.2.0/src/sorts/tablesort.number.min.js"></script>
  14. </head>
  15. <body>
  16. <nav class="uk-navbar-container" uk-navbar>
  17. <div class="uk-navbar-center">
  18. <a href="" class="uk-navbar-item uk-logo">Orna Tools</a>
  19. </div>
  20. </nav>
  21. <div class="uk-container">
  22. <div id="equipment-container" class="uk-padding-large">
  23. <ul class="uk-flex-center" uk-tab>
  24. <li class="uk-active"><a href="">Head</a></li>
  25. <li><a href="">Chest</a></li>
  26. <li><a href="">Leg</a></li>
  27. </ul>
  28. <ul class="uk-switcher">
  29. {% for slot in ["Head", "Chest", "Leg"] %}
  30. <li>
  31. <div class="uk-padding-large uk-padding-remove-vertical">
  32. <table id="{{ slot | lower }}-table" class="uk-table">
  33. <caption>{{ slot }} Gear</caption>
  34. <thead>
  35. <tr>
  36. <th class="uk-table-shrink"></th>
  37. <th class="uk-table-expand">Item Name</th>
  38. <th class="uk-table-shrink">Defense</th>
  39. <th class="uk-table-shrink">Resistance</th>
  40. <th class="uk-table-shring"></th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. <tr>
  45. <td>1</td>
  46. <td><input type="text" class="uk-input"/></td>
  47. <td><input type="text" class="uk-input"/></td>
  48. <td><input type="text" class="uk-input"/></td>
  49. <td><a class="uk-icon-button del-row-button" uk-icon="icon:minus-circle;ratio:1"></a></td>
  50. </tr>
  51. </tbody>
  52. </table>
  53. <div class="uk-text-center">
  54. <a id="{{ slot | lower }}-button" class="uk-icon-button add-row-button" uk-icon="icon:plus-circle;ratio:2"></a>
  55. </div>
  56. </div>
  57. </li>
  58. {% endfor %}
  59. </ul>
  60. </div>
  61. <div class="uk-text-center uk-margin-bottom">
  62. <button id="calculate-button" class="uk-button uk-button-primary">Calculate</button>
  63. </div>
  64. <div id="result-panel" class="uk-section">
  65. <hr class="uk-divider-icon" />
  66. <table id="results-table" class="uk-table uk-table-divider uk-table-striped uk-table-hover">
  67. <thead>
  68. <th>Total</th>
  69. <th>Defense</th>
  70. <th>Resistance</th>
  71. <th class="uk-table-expand">Head</th>
  72. <th class="uk-table-expand">Chest</th>
  73. <th class="uk-table-expand">Legs</th>
  74. </thead>
  75. <tbody></tbody>
  76. </table>
  77. </div>
  78. </div>
  79. </body>
  80. <script>
  81. // Support adding rows to the equipment tables
  82. function addEquipmentTableRow() {
  83. let input_element = document.createElement("input");
  84. input_element.className="uk-input";
  85. input_element.type = "text";
  86. // Create the delete button
  87. let delete_button = document.createElement("a");
  88. delete_button.className="uk-icon-button del-row-button";
  89. delete_button.setAttribute("uk-icon", "icon:minus-circle;ratio:1");
  90. delete_button.addEventListener("click", deleteEquipmentTableRow, false);
  91. let tbody = this.parentElement.previousElementSibling.children[2];
  92. let new_row = tbody.insertRow(-1);
  93. // Append all of the child cells needed
  94. new_row.insertCell(0).appendChild(delete_button);
  95. new_row.insertCell(0).appendChild(input_element.cloneNode());
  96. new_row.insertCell(0).appendChild(input_element.cloneNode());
  97. new_row.insertCell(0).appendChild(input_element.cloneNode());
  98. new_row.insertCell(0).appendChild(document.createTextNode(tbody.children.length))
  99. }
  100. // Support deleting rows from the equipment table
  101. function deleteEquipmentTableRow() {
  102. this.parentElement.parentElement.remove();
  103. }
  104. // Process results and display table
  105. function processEquipmentResults(results) {
  106. var results_tbody = document.querySelector("table#results-table > tbody");
  107. for(result of results) {
  108. let new_row = results_tbody.insertRow(-1);
  109. // Append all of the child cells
  110. new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][2]));
  111. new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][1]));
  112. new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][0]));
  113. new_row.insertCell(0).appendChild(document.createTextNode(result['res']));
  114. new_row.insertCell(0).appendChild(document.createTextNode(result['def']));
  115. new_row.insertCell(0).appendChild(document.createTextNode(result['def'] + result['res']));
  116. }
  117. table_sort.refresh();
  118. }
  119. // Send data to backend
  120. function calculateEquipment() {
  121. let data = gatherEquipmentData();
  122. // Clear out existing table rows
  123. for(let row of document.querySelectorAll("table#results-table > tbody > tr")) {
  124. row.remove();
  125. }
  126. fetch('/results', {
  127. method: 'POST',
  128. headers: { 'Content-Type': 'application/json' },
  129. body: JSON.stringify(data)
  130. }).then((response) => response.json()).then((data) => {
  131. processEquipmentResults(data)
  132. }).catch((error) => {
  133. console.log(error);
  134. alert("There was a problem...");
  135. });
  136. }
  137. function gatherEquipmentData() {
  138. var eq_head = [], eq_chest = [], eq_legs = [];
  139. // Gather head gear
  140. for(let row of document.querySelectorAll("table#head-table > tbody > tr")) {
  141. eq_head.push([
  142. row.children[1].firstChild.value,
  143. parseInt(row.children[2].firstChild.value) || 0,
  144. parseInt(row.children[3].firstChild.value) || 0
  145. ]);
  146. }
  147. // Gather chest gear
  148. for(let row of document.querySelectorAll("table#chest-table > tbody > tr")) {
  149. eq_chest.push([
  150. row.children[1].firstChild.value,
  151. parseInt(row.children[2].firstChild.value) || 0,
  152. parseInt(row.children[3].firstChild.value) || 0
  153. ]);
  154. }
  155. // Gather leg gear
  156. for(let row of document.querySelectorAll("table#leg-table > tbody > tr")) {
  157. eq_legs.push([
  158. row.children[1].firstChild.value,
  159. parseInt(row.children[2].firstChild.value) || 0,
  160. parseInt(row.children[3].firstChild.value) || 0
  161. ]);
  162. }
  163. let data = {
  164. "head": eq_head,
  165. "chest": eq_chest,
  166. "legs": eq_legs
  167. };
  168. return data;
  169. }
  170. // Add event listeners to our table buttons
  171. const add_row_buttons = document.querySelectorAll("a.add-row-button");
  172. for(let button of add_row_buttons) {
  173. button.addEventListener("click", addEquipmentTableRow, false);
  174. }
  175. const del_row_buttons = document.querySelectorAll("a.del-row-button");
  176. for(let button of del_row_buttons) {
  177. button.addEventListener("click", deleteEquipmentTableRow, false);
  178. }
  179. // Add event listener to Calculate button, call backend
  180. document.querySelector("#calculate-button").addEventListener("click", calculateEquipment, false);
  181. // Enable sorting for our results table
  182. var table_sort = new Tablesort(document.querySelector("table#results-table"));
  183. </script>
  184. <style type="text/css">
  185. table:not(#results-table) > tbody > tr > td:first-child {
  186. color: #999;
  187. }
  188. div > a.add-row-button {
  189. color: #32d296;
  190. }
  191. table a.del-row-button {
  192. color: #f0506e;
  193. }
  194. table#results-table > tbody > tr > td:first-child {
  195. font-weight: bold;
  196. color: #6c9f12;
  197. }
  198. /* Result Table from Tablesort.css */
  199. th:not(.no-sort) {
  200. cursor: pointer;
  201. }
  202. th[role=columnheader]:not(.no-sort):after {
  203. content: '';
  204. float: right;
  205. margin-top: 7px;
  206. border-width: 0 4px 4px;
  207. border-style: solid;
  208. border-color: #404040 transparent;
  209. visibility: hidden;
  210. opacity: 0;
  211. -ms-user-select: none;
  212. -webkit-user-select: none;
  213. -moz-user-select: none;
  214. user-select: none;
  215. }
  216. th[aria-sort=ascending]:not(.no-sort):after {
  217. border-bottom: none;
  218. border-width: 4px 4px 0;
  219. }
  220. th[aria-sort]:not(.no-sort):after {
  221. visibility: visible;
  222. opacity: 0.4;
  223. }
  224. th[role=columnheader]:not(.no-sort):hover:after {
  225. visibility: visible;
  226. opacity: 1;
  227. }
  228. </style>
  229. </html>