change node name functionalitijd
This commit is contained in:
91
web/newWebsite/text.js
Normal file
91
web/newWebsite/text.js
Normal file
@@ -0,0 +1,91 @@
|
||||
apiGetAllNode = "http://145.92.8.114/getNodeInfo?macAdress=*"
|
||||
|
||||
nodeDataArray = {};
|
||||
|
||||
var updateNode = document.getElementById('editNode');
|
||||
var locationInput = document.getElementById("inputLocation");
|
||||
var nameInput = document.getElementById("inputName");
|
||||
var select = document.getElementById('mySelect');
|
||||
|
||||
document.getElementById("inputName").placeholder = "Type new name here..";
|
||||
document.getElementById("inputLocation").placeholder = "Type new location here..";
|
||||
|
||||
updateNode.style.display = "none";
|
||||
|
||||
function settings() {
|
||||
if (updateNode.style.display === "none") {
|
||||
updateNode.style.display = "block";
|
||||
locationInput.value = "";
|
||||
nameInput.value = "";
|
||||
|
||||
fetch(apiGetAllNode)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
document.getElementById('text').innerHTML = "Error: Network response was not ok";
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
document.getElementById('text').innerHTML = "Fetching data";
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
document.getElementById('text').innerHTML = "Data fetched";
|
||||
handleData(data);
|
||||
})
|
||||
|
||||
} else {
|
||||
updateNode.style.display = "none";
|
||||
}
|
||||
|
||||
}
|
||||
function handleData(JSONdata) {
|
||||
var i, L = select.options.length - 1;
|
||||
for (i = L; i >= 0; i--) {
|
||||
select.remove(i);
|
||||
}
|
||||
|
||||
for (var i = 0; i < JSONdata.length; i++) {
|
||||
var node = JSONdata[i].NodeID;
|
||||
var name = JSONdata[i].Name;
|
||||
var location = JSONdata[i].Location;
|
||||
nodeDataArray[node] = { name: name, location: location };
|
||||
// Create new option element
|
||||
var option = document.createElement('option');
|
||||
|
||||
// Set the value of the option
|
||||
option.value = node;
|
||||
|
||||
// Set the text of the option
|
||||
option.text = name;
|
||||
|
||||
// Add the option to the select
|
||||
select.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
function changeText() {
|
||||
var nodeName = encodeURIComponent(document.getElementById('inputName').value);
|
||||
var nodeLocation = encodeURIComponent(document.getElementById('inputLocation').value);
|
||||
|
||||
updateNodeInfo(select.value, nodeName, nodeLocation);
|
||||
|
||||
var text = document.getElementById('text');
|
||||
|
||||
text.innerHTML = "Changes made"
|
||||
}
|
||||
|
||||
function updateNodeInfo(node, newNodeName, newNodeLocation) {
|
||||
apiUrl = "http://145.92.8.114/updateData?node=" + node + "&name=" + newNodeName + "&location=" + newNodeLocation;
|
||||
fetch(apiUrl)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user