added basic addition of miners to the list and improved some functionality of the web tool
This commit is contained in:
@@ -26,8 +26,8 @@ def scan(request: Request):
|
|||||||
|
|
||||||
|
|
||||||
@app.post("/scan/add_miners")
|
@app.post("/scan/add_miners")
|
||||||
def add_miners_scan(request: Request):
|
async def add_miners_scan(request: Request):
|
||||||
print(request)
|
print(await request.json())
|
||||||
return scan
|
return scan
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row w-100">
|
<div class="row w-100">
|
||||||
<button class="btn btn-primary mb-4" onclick="addMiners()" type="button" id="addButton">Add Selected Miners</button>
|
<button class="btn btn-primary mb-4 mx-1" onclick="addMiners()" type="button" id="addButton">Add Selected Miners</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row w-100">
|
<div class="row w-100">
|
||||||
@@ -53,6 +53,9 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
window.post = function(url, data) {
|
||||||
|
return fetch(url, {method: "POST", headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)});
|
||||||
|
}
|
||||||
var ws = new WebSocket("ws://localhost:80/scan/ws");
|
var ws = new WebSocket("ws://localhost:80/scan/ws");
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
if (event.data == "Done") {
|
if (event.data == "Done") {
|
||||||
@@ -72,11 +75,11 @@
|
|||||||
var miners = document.getElementById('minerTable')
|
var miners = document.getElementById('minerTable')
|
||||||
miners.innerHTML = ""
|
miners.innerHTML = ""
|
||||||
miner_data.forEach(function(miner) {
|
miner_data.forEach(function(miner) {
|
||||||
console.log(miner)
|
|
||||||
var tr = document.createElement('tr')
|
var tr = document.createElement('tr')
|
||||||
|
tr.id = miner["ip"]
|
||||||
|
|
||||||
var checkbox_td = document.createElement('td')
|
var checkbox_td = document.createElement('td')
|
||||||
checkbox_td.innerHTML = '<input type="checkbox" class="select-item checkbox" name="select-item" value="' + miner["ip"] + '" />'
|
checkbox_td.innerHTML = '<input type="checkbox" class="select-item checkbox" name="minerCheckboxes" value="' + miner["ip"] + '" />'
|
||||||
checkbox_td.className = "active"
|
checkbox_td.className = "active"
|
||||||
|
|
||||||
var ip_td = document.createElement('td')
|
var ip_td = document.createElement('td')
|
||||||
@@ -111,14 +114,27 @@
|
|||||||
} else {
|
} else {
|
||||||
ws.send("192.168.1.0/24")
|
ws.send("192.168.1.0/24")
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
function cancelScan(event) {
|
function cancelScan(event) {
|
||||||
document.getElementById("scanStatus").innerHTML = "Canceling..."
|
document.getElementById("scanStatus").innerHTML = "Canceling..."
|
||||||
document.getElementById("scanButton").innerHTML = "Canceling..."
|
document.getElementById("scanButton").innerHTML = "Canceling..."
|
||||||
document.getElementById("cancelButton").style = "display:none;"
|
document.getElementById("cancelButton").style = "display:none;"
|
||||||
ws.send("-Cancel-")
|
ws.send("-Cancel-")
|
||||||
}
|
};
|
||||||
|
function addMiners(event) {
|
||||||
|
var checkedBoxes = document.querySelectorAll('input[name=minerCheckboxes]:checked');
|
||||||
|
if !(checkedBoxes.length == 0) {
|
||||||
|
var minerList = [];
|
||||||
|
for (i = 0; i< checkedBoxes.length; i++) {
|
||||||
|
minerList.push(checkedBoxes[i].defaultValue);
|
||||||
|
}
|
||||||
|
post("{{url_for('add_miners_scan')}}", {miners: minerList})
|
||||||
|
for (i = 0; i< minerList.length; i++) {
|
||||||
|
var tr_to_remove = document.getElementById(minerList[i])
|
||||||
|
tr_to_remove.remove()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|||||||
Reference in New Issue
Block a user