Skip to content

Commit 4a21762

Browse files
authored
Update JS for new API
1 parent 09e3bc5 commit 4a21762

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

Server/static/js/script.js

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,41 @@ window.onload = function() {
1010
return response.json();
1111
};
1212

13-
fetch('/api/all')
14-
.then(handleResponse)
15-
.then(data => {
16-
document.getElementById('current-time').textContent = data['Current Time'];
17-
document.getElementById('ip-address').textContent = data['IP Address'].replaceAll(" ", "\n");
18-
document.getElementById('cpu-usage').textContent = data['CPU Usage'];
19-
document.getElementById('soc-temp').textContent = data['SoC Temperature'].replace("C", "°C");
20-
document.getElementById('total-ram').textContent = data['Total RAM'];
21-
document.getElementById('used-ram').textContent = data['Used RAM'].concat("MiB");
22-
document.getElementById('total-swap').textContent = data['Total Swap'];
23-
document.getElementById('used-swap').textContent = data['Used Swap'].concat("MiB");
24-
})
25-
.catch(error => console.error('Error fetching API data:', error));
13+
// Function to fetch and update data
14+
const updateData = () => {
15+
fetch('/api/all')
16+
.then(handleResponse)
17+
.then(data => {
18+
// Original metrics
19+
document.getElementById('current-time').textContent = data['Current Time'];
20+
document.getElementById('ip-address').textContent = data['IP Address'].replaceAll(" ", "\n");
21+
document.getElementById('cpu-usage').textContent = data['CPU Usage'];
22+
document.getElementById('soc-temp').textContent = data['SoC Temperature'].replace("C", "°C");
23+
document.getElementById('total-ram').textContent = data['Total RAM'];
24+
document.getElementById('used-ram').textContent = data['Used RAM'].concat("MiB");
25+
document.getElementById('total-swap').textContent = data['Total Swap'];
26+
document.getElementById('used-swap').textContent = data['Used Swap'].concat("MiB");
27+
28+
// New metrics
29+
document.getElementById('system-uptime').textContent = data['System Uptime'];
30+
document.getElementById('disk-usage').textContent = data['Disk Usage'];
31+
document.getElementById('disk-total').textContent = data['Disk Total'];
32+
document.getElementById('disk-used').textContent = data['Disk Used'];
33+
document.getElementById('disk-available').textContent = data['Disk Available'];
34+
document.getElementById('system-model').textContent = data['System Model'];
35+
document.getElementById('kernel-version').textContent = data['Kernel Version'];
36+
document.getElementById('os-version').textContent = data['OS'];
37+
})
38+
.catch(error => console.error('Error fetching API data:', error));
39+
};
40+
41+
// Initial data load
42+
updateData();
2643

44+
// Update data every 5 seconds
45+
setInterval(updateData, 5000);
46+
47+
// Shutdown button handler
2748
document.getElementById('shutdown-btn').addEventListener('click', function() {
2849
const apiKey = prompt('Please enter your API key:');
2950
if (apiKey && confirm('Are you sure you want to shut down the system?')) {
@@ -39,6 +60,23 @@ window.onload = function() {
3960
}
4061
});
4162

63+
// Reboot button handler
64+
document.getElementById('reboot-btn').addEventListener('click', function() {
65+
const apiKey = prompt('Please enter your API key:');
66+
if (apiKey && confirm('Are you sure you want to reboot the system?')) {
67+
fetch('/api/reboot', {
68+
method: 'POST',
69+
headers: {
70+
'x-api-key': apiKey
71+
}
72+
})
73+
.then(handleResponse)
74+
.then(data => alert(data.message))
75+
.catch(error => console.error('Error during reboot:', error));
76+
}
77+
});
78+
79+
// Update button handler
4280
document.getElementById('update-btn').addEventListener('click', function() {
4381
const apiKey = prompt('Please enter your API key:');
4482
if (apiKey && confirm('Are you sure you want to update the system?')) {

0 commit comments

Comments
 (0)