+ added address adding input to web ui in sidebar

fixes #10
This commit is contained in:
Kevin Froman 2020-10-03 22:43:18 +00:00
parent 092233027c
commit 45940b2dba
5 changed files with 66 additions and 2 deletions

View file

@ -10,6 +10,18 @@
<div class="quickview-block">
Blocks to upload: <span id="uploadBlocks">unknown</span>
</div>
<div class="quickview-block">
<div class="field has-addons">
<div class="control">
<input class="input" type="text" placeholder="Node address" id="addPeerInput">
</div>
<div class="control">
<a class="button is-info" id="addPeerBtn">
Add Peer
</a>
</div>
</div>
</div>
</div>
</div>
<button class="button is-primary is-hidden sidebarBtn" data-show="quickview" data-target="quickviewDefault">Show quickview</button>

View file

@ -7,8 +7,38 @@ fetch('/shared/sidebar/sidebar.html', {
.then(function(resp) {
document.getElementById('sidebarContainer').innerHTML = resp
var quickviews = bulmaQuickview.attach()
sidebarAddPeerRegister()
})
function sidebarAddPeerRegister(){
document.getElementById('addPeerBtn').onclick = function(){
let newPeer = document.getElementById('addPeerInput').value
fetch('/addpeer/' + newPeer, {
method: 'POST',
headers: {
"token": webpass
}})
.then((resp) => resp.text())
.then(function(data) {
alert(data)
if (data == "success"){
PNotify.success({
text: 'Peer added'
})
return
}
else if(data == "already added"){
PNotify.notice({
text: 'Peer already added'
})
return
}
PNotify.error({text: data})
})
}
}
window.addEventListener("keydown", function(event) {
if (event.key === "s"){
if (document.activeElement.nodeName == "TEXTAREA" || document.activeElement.nodeName == "INPUT"){
@ -44,7 +74,6 @@ window.addEventListener("keydown", function(event) {
}})
.then((resp) => resp.text())
.then(function(resp) {
console.debug(resp.length, existingUploadValue)
if (resp.length <= 2 && existingUploadValue !== "0"){
document.getElementById("uploadBlocks").innerText = "0"
return