|
|
<!doctype html> <html> <head> <title>Orna Tools - atr0phy.net</title>
<meta charset="utf-8"> <meta name="viewport" contents="width=device-width, initial-scale=1">
<!-- <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"> -->
<!-- UIkit CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/css/uikit.min.css" />
<!-- UIkit JS --> <script src="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/js/uikit.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/js/uikit-icons.min.js"></script> <script src="https://cdn.jsdelivr.net/combine/npm/tablesort@5.2.0,npm/tablesort@5.2.0/src/sorts/tablesort.number.min.js"></script> </head> <body> <nav class="uk-navbar-container" uk-navbar> <div class="uk-navbar-center"> <a href="" class="uk-navbar-item uk-logo">Orna Tools</a> </div> </nav> <div class="uk-container"> <div id="equipment-container" class="uk-padding-large"> <ul class="uk-flex-center" uk-tab> <li class="uk-active"><a href="">Head</a></li> <li><a href="">Chest</a></li> <li><a href="">Leg</a></li> </ul> <ul class="uk-switcher"> {% for slot in ["Head", "Chest", "Leg"] %} <li> <div class="uk-padding-large uk-padding-remove-vertical"> <table id="{{ slot | lower }}-table" class="uk-table"> <caption>{{ slot }} Gear</caption> <thead> <tr> <th class="uk-table-shrink"></th> <th class="uk-table-expand">Item Name</th> <th class="uk-table-shrink">Defense</th> <th class="uk-table-shrink">Resistance</th> <th class="uk-table-shring"></th> </tr> </thead> <tbody> <tr> <td>1</td> <td><input type="text" class="uk-input"/></td> <td><input type="text" class="uk-input"/></td> <td><input type="text" class="uk-input"/></td> <td><a class="uk-icon-button del-row-button" uk-icon="icon:minus-circle;ratio:1"></a></td> </tr> </tbody> </table> <div class="uk-text-center"> <a id="{{ slot | lower }}-button" class="uk-icon-button add-row-button" uk-icon="icon:plus-circle;ratio:2"></a> </div> </div> </li> {% endfor %} </ul> </div> <div class="uk-text-center uk-margin-bottom"> <button id="calculate-button" class="uk-button uk-button-primary">Calculate</button> </div>
<div id="result-panel" class="uk-section"> <hr class="uk-divider-icon" /> <table id="results-table" class="uk-table uk-table-divider uk-table-striped uk-table-hover"> <thead> <th>Total</th> <th>Defense</th> <th>Resistance</th> <th class="uk-table-expand">Head</th> <th class="uk-table-expand">Chest</th> <th class="uk-table-expand">Legs</th> </thead> <tbody></tbody> </table> </div> </div> </body> <script> // Support adding rows to the equipment tables function addEquipmentTableRow() { let input_element = document.createElement("input"); input_element.className="uk-input"; input_element.type = "text";
// Create the delete button let delete_button = document.createElement("a"); delete_button.className="uk-icon-button del-row-button"; delete_button.setAttribute("uk-icon", "icon:minus-circle;ratio:1"); delete_button.addEventListener("click", deleteEquipmentTableRow, false);
let tbody = this.parentElement.previousElementSibling.children[2]; let new_row = tbody.insertRow(-1);
// Append all of the child cells needed new_row.insertCell(0).appendChild(delete_button); new_row.insertCell(0).appendChild(input_element.cloneNode()); new_row.insertCell(0).appendChild(input_element.cloneNode()); new_row.insertCell(0).appendChild(input_element.cloneNode()); new_row.insertCell(0).appendChild(document.createTextNode(tbody.children.length)) }
// Support deleting rows from the equipment table function deleteEquipmentTableRow() { this.parentElement.parentElement.remove(); }
// Process results and display table function processEquipmentResults(results) { var results_tbody = document.querySelector("table#results-table > tbody"); for(result of results) { let new_row = results_tbody.insertRow(-1);
// Append all of the child cells new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][2])); new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][1])); new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][0])); new_row.insertCell(0).appendChild(document.createTextNode(result['res'])); new_row.insertCell(0).appendChild(document.createTextNode(result['def'])); new_row.insertCell(0).appendChild(document.createTextNode(result['def'] + result['res'])); } table_sort.refresh(); }
// Send data to backend function calculateEquipment() { let data = gatherEquipmentData();
// Clear out existing table rows for(let row of document.querySelectorAll("table#results-table > tbody > tr")) { row.remove(); }
fetch('/results', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }).then((response) => response.json()).then((data) => { processEquipmentResults(data) }).catch((error) => { console.log(error); alert("There was a problem..."); }); }
function gatherEquipmentData() { var eq_head = [], eq_chest = [], eq_legs = [];
// Gather head gear for(let row of document.querySelectorAll("table#head-table > tbody > tr")) { eq_head.push([ row.children[1].firstChild.value, parseInt(row.children[2].firstChild.value) || 0, parseInt(row.children[3].firstChild.value) || 0 ]); }
// Gather chest gear for(let row of document.querySelectorAll("table#chest-table > tbody > tr")) { eq_chest.push([ row.children[1].firstChild.value, parseInt(row.children[2].firstChild.value) || 0, parseInt(row.children[3].firstChild.value) || 0 ]); }
// Gather leg gear for(let row of document.querySelectorAll("table#leg-table > tbody > tr")) { eq_legs.push([ row.children[1].firstChild.value, parseInt(row.children[2].firstChild.value) || 0, parseInt(row.children[3].firstChild.value) || 0 ]); }
let data = { "head": eq_head, "chest": eq_chest, "legs": eq_legs };
return data; }
// Add event listeners to our table buttons const add_row_buttons = document.querySelectorAll("a.add-row-button"); for(let button of add_row_buttons) { button.addEventListener("click", addEquipmentTableRow, false); } const del_row_buttons = document.querySelectorAll("a.del-row-button"); for(let button of del_row_buttons) { button.addEventListener("click", deleteEquipmentTableRow, false); }
// Add event listener to Calculate button, call backend document.querySelector("#calculate-button").addEventListener("click", calculateEquipment, false);
// Enable sorting for our results table var table_sort = new Tablesort(document.querySelector("table#results-table")); </script> <style type="text/css"> table:not(#results-table) > tbody > tr > td:first-child { color: #999; }
div > a.add-row-button { color: #32d296; }
table a.del-row-button { color: #f0506e; }
table#results-table > tbody > tr > td:first-child { font-weight: bold; color: #6c9f12; }
/* Result Table from Tablesort.css */ th:not(.no-sort) { cursor: pointer; }
th[role=columnheader]:not(.no-sort):after { content: ''; float: right; margin-top: 7px; border-width: 0 4px 4px; border-style: solid; border-color: #404040 transparent; visibility: hidden; opacity: 0; -ms-user-select: none; -webkit-user-select: none; -moz-user-select: none; user-select: none; }
th[aria-sort=ascending]:not(.no-sort):after { border-bottom: none; border-width: 4px 4px 0; }
th[aria-sort]:not(.no-sort):after { visibility: visible; opacity: 0.4; }
th[role=columnheader]:not(.no-sort):hover:after { visibility: visible; opacity: 1; } </style> </html>
|