mirror of
https://github.com/fluencelabs/cosmos-hackathon-frontend
synced 2025-05-29 13:41:21 +00:00
refactoring
This commit is contained in:
parent
e2ac75d18f
commit
3a8374b4f2
@ -24,8 +24,10 @@
|
||||
<section class="container">
|
||||
<div class="m-5"><h1>Cosmic Salmon. Hook A Fish</h1></div>
|
||||
<div class="input-group border-primary m-5">
|
||||
<input type="text" class="form-control" placeholder="Node IP" id="node-ip" value="1">
|
||||
<input type="text" class="form-control" placeholder="Binary Source" id="binary-url" value="1">
|
||||
<input type="text" class="form-control" placeholder="Node IP" id="node-ip" value="207.154.210.117">
|
||||
<input type="text" class="form-control" placeholder="Node Port" id="node-port" value="26657">
|
||||
<input type="text" class="form-control" placeholder="Binary Source" id="binary-url" value="QmQ69JoPDaKFpPSbWvvUGRGG5E83u6nTP2hRegmCoa6aW5">
|
||||
<input type="text" class="form-control" placeholder="Name" id="node-name" value="name service">
|
||||
<button type="button" class="btn btn-outline-secondary" id="start-check">Start Check</button>
|
||||
</div>
|
||||
|
||||
|
81
index.js
81
index.js
@ -46,17 +46,21 @@ window.onload = function () {
|
||||
};
|
||||
|
||||
function startCheckEvent() {
|
||||
let nodeIpEl = document.getElementById("node-ip");
|
||||
let binaryUrlEl = document.getElementById("binary-url");
|
||||
let nodeIpEl = document.getElementById("node-ip").value;
|
||||
let portEl = document.getElementById("node-port").value;
|
||||
let binaryUrlEl = document.getElementById("binary-url").value;
|
||||
let nameEl = document.getElementById("node-name").value;
|
||||
|
||||
let someInfo = {
|
||||
name: nodeIpEl.value,
|
||||
name: nameEl,
|
||||
nodesNumber: 34,
|
||||
lastHeight: 13,
|
||||
binaryLink: "#"
|
||||
};
|
||||
|
||||
startCheck(someInfo.name, someInfo);
|
||||
let createUrl = `http://localhost:8090/create/${nameEl}/${nodeIpEl}/${portEl}/${binaryUrlEl}`;
|
||||
|
||||
startCheck(createUrl, someInfo.name, someInfo);
|
||||
}
|
||||
|
||||
function appendNewZone(id, info, status) {
|
||||
@ -80,7 +84,6 @@ function appendNewZone(id, info, status) {
|
||||
|
||||
function setHeightAndWidth(el, currentHeight, lastHeight) {
|
||||
let percent = currentHeight / lastHeight * 100;
|
||||
console.log("hey = " + percent);
|
||||
el.style.width = `${percent}%`;
|
||||
el.innerHTML = `Height: ${currentHeight}`;
|
||||
}
|
||||
@ -184,51 +187,49 @@ function getProgressBar(id) {
|
||||
return document.getElementById(id).getElementsByClassName("progress-bar")[0];
|
||||
}
|
||||
|
||||
function startCheck(zoneId, info) {
|
||||
function startCheck(createUrl, zoneId, info) {
|
||||
|
||||
if (state[zoneId]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.open( "GET", "http://localhost:8090/create/" + zoneId, false ); // false for synchronous request
|
||||
xmlHttp.send( null );
|
||||
fetch(createUrl).then((sa) => {
|
||||
let socket = new WebSocket("ws://127.0.0.1:8090/websocket/" + zoneId);
|
||||
|
||||
let socket = new WebSocket("ws://127.0.0.1:8090/websocket/start/file/" + zoneId);
|
||||
socket.onopen = function(e) {
|
||||
|
||||
socket.onopen = function(e) {
|
||||
|
||||
state[zoneId] = {
|
||||
info: info
|
||||
console.log(e);
|
||||
state[zoneId] = {
|
||||
info: info
|
||||
};
|
||||
appendNewZone(zoneId, info);
|
||||
};
|
||||
appendNewZone(zoneId, info);
|
||||
console.log("Websocket was opened: " + JSON.stringify(e));
|
||||
};
|
||||
|
||||
let k = 0;
|
||||
let k = 0;
|
||||
|
||||
socket.onmessage = function(event) {
|
||||
let st = state[zoneId];
|
||||
let data = JSON.parse(event.data);
|
||||
let el = getProgressBar(zoneId);
|
||||
k++;
|
||||
if (data.height) {
|
||||
if (st.info.lastHeight < 1000 || k % 100 === 0) {
|
||||
setHeightAndWidth(el, data.height, st.info.lastHeight);
|
||||
} else {
|
||||
changeHeight(el, data.height)
|
||||
}
|
||||
} else {
|
||||
setError(zoneId);
|
||||
socket.close()
|
||||
}
|
||||
};
|
||||
socket.onmessage = function(event) {
|
||||
let st = state[zoneId];
|
||||
let data = JSON.parse(event.data);
|
||||
let el = getProgressBar(zoneId);
|
||||
k++;
|
||||
if (data.correct) {
|
||||
if (st.info.lastHeight < 1000 || k % 100 === 0) {
|
||||
setHeightAndWidth(el, data.height, st.info.lastHeight);
|
||||
} else {
|
||||
changeHeight(el, data.height)
|
||||
}
|
||||
} else {
|
||||
setError(zoneId);
|
||||
socket.close()
|
||||
}
|
||||
};
|
||||
|
||||
socket.onclose = function(event) {
|
||||
console.log("Websocket was closed. Cause: " + JSON.stringify(event))
|
||||
};
|
||||
socket.onclose = function(event) {
|
||||
console.log("Websocket was closed. Cause: " + JSON.stringify(event))
|
||||
};
|
||||
|
||||
socket.onerror = function(error) {
|
||||
console.log("Error: " + JSON.stringify(error))
|
||||
};
|
||||
socket.onerror = function(error) {
|
||||
console.log("Error: " + JSON.stringify(error))
|
||||
};
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user