-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
304 lines (260 loc) · 11.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lilypad GPU Status</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
<style>
body {
margin: 0;
padding: 0;
background-color: #121212;
/* Dark background */
color: #a7ffef;
/* lilypad green */
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}
h1 {
text-align: center;
font-size: 2.5rem;
color: #ffffff;
margin-top: 20px;
}
.filter-container {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
.filter-container label {
color: #ffffff;
font-weight: bold;
margin-right: 10px;
}
.filter-container select {
margin-right: 10px;
padding: 5px;
background-color: #000000;
color: #a7ffef;
border: 1px solid #a7ffef;
}
table {
width: 90%;
margin-top: 20px;
border-collapse: collapse;
box-shadow: 0 0 20px #a7ffef;
border-radius: 10px;
overflow: hidden;
max-height: 75vh;
}
th,
td {
padding: 15px;
text-align: left;
background-color: #000000;
border-radius: 5px;
box-shadow: 0 0 10px #a7ffef;
line-height: 1.6;
}
.online {
color: #a7ffef;
}
.offline {
color: #ff3d00;
}
.gpu-present {
font-weight: bold;
}
.gpu-icon {
margin-right: 10px;
color: #a7ffef;
}
</style>
</head>
<body>
<h1>Lilypad GPU Status</h1>
<div id="refreshStatus" style="position: fixed; top: 10px; right: 10px; color: white;">
<div id="spinner" style="display: none;">
<i class="fas fa-spinner fa-spin"></i> Refreshing...
</div>
<div id="countdown"></div>
</div>
<div class="filter-container">
<label for="filter-wallet">Wallet Address:</label>
<select id="filter-wallet" onchange="applyAllFilters()"></select>
<label for="filter-status">Status:</label>
<select id="filter-status" onchange="applyAllFilters()"></select>
<label for="filter-connected">Connected Since:</label>
<select id="filter-connected" onchange="applyAllFilters()"></select>
<label for="filter-gpu">GPU:</label>
<select id="filter-gpu" onchange="applyAllFilters()"></select>
<label for="filter-cpu">CPU:</label>
<select id="filter-cpu" onchange="applyAllFilters()"></select>
<label for="filter-ram">RAM:</label>
<select id="filter-ram" onchange="applyAllFilters()"></select>
<label for="filter-location">Location:</label>
<select id="filter-location" onchange="applyAllFilters()"></select>
</div>
<table id="uptime-status">
<thead>
<tr>
<th>Wallet Address</th>
<th>Status</th>
<th>Connected Since</th>
<th>GPU</th>
<th>CPU</th>
<th>RAM</th>
<th>Location</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
let countdownTimer;
let refreshInterval = 30000; // 30 seconds
async function fetchUptimeData() {
showSpinner(true);
const tableBody = document.querySelector('#uptime-status tbody');
console.log("Fetching data...");
try {
const response = await fetch('https://api-testnet.lilypad.tech/metrics-dashboard/nodes');
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`);
}
const nodes = await response.json();
console.log("Data parsed:", nodes);
if (!nodes.length) {
throw new Error("No nodes data returned or incorrect format.");
}
tableBody.innerHTML = '';
nodes.forEach(node => {
const row = createNodeRow(node);
tableBody.appendChild(row);
});
populateInitialDropdowns(); // Call after data is fetched and table is populated
applyAllFilters(); // Reapply filters to the new data
} catch (error) {
console.error('Fetch error:', error);
tableBody.innerHTML = `<tr><td colspan="7">Error loading data: ${error.message}. Please try again later.</td></tr>`;
} finally {
showSpinner(false);
startCountdown(refreshInterval); // Restart the countdown after fetching is complete
}
}
function startCountdown(duration) {
clearInterval(countdownTimer); // Ensure no previous timer is running
let timer = duration / 1000; // Convert to seconds
updateCountdownDisplay(timer); // Update immediately before starting interval
countdownTimer = setInterval(() => {
if (--timer < 0) {
clearInterval(countdownTimer);
document.getElementById('countdown').textContent = "Refreshing...";
fetchUptimeData(); // Fetch data when countdown ends
} else {
updateCountdownDisplay(timer);
}
}, 1000);
}
function updateCountdownDisplay(seconds) {
const minutes = parseInt(seconds / 60, 10);
const remainingSeconds = parseInt(seconds % 60, 10);
document.getElementById('countdown').textContent = `${pad(minutes)}:${pad(remainingSeconds)}`;
}
function pad(number) {
return number < 10 ? '0' + number : number;
}
function showSpinner(show) {
document.getElementById('spinner').style.display = show ? "block" : "none";
document.getElementById('countdown').style.display = show ? "none" : "block";
}
function createNodeRow(node) {
const row = document.createElement('tr');
row.innerHTML = `
<td data-key="wallet">${node.ID}</td>
<td data-key="status">${node.Online ? 'Online' : 'Offline'}</td>
<td data-key="connected">${node.ConnectedSince ? new Date(node.ConnectedSince).toLocaleString() : 'N/A'}</td>
<td data-key="gpu">${node.GPU} ${node.GPU > 0 ? '(GPU Present)' : ''}</td>
<td data-key="cpu">${node.CPU}</td>
<td data-key="ram">${node.RAM}MB</td>
<td data-key="location">${node.CountryCode}</td>
`;
return row;
}
function populateDropdown(filterId, rows, key) {
const dropdown = document.getElementById(filterId);
const values = new Set(['All']); // Start with 'All' as a default option
rows.forEach(row => {
const cell = row.querySelector(`td[data-key='${key}']`);
if (cell) {
values.add(cell.textContent.trim());
}
});
const currentFilter = dropdown.value;
dropdown.innerHTML = ''; // Clear existing options
values.forEach(value => {
const option = document.createElement('option');
option.value = option.textContent = value;
// Set 'Online' as selected only on the first load for 'Status' dropdown
if (filterId === 'filter-status' && value === 'Online' && !dropdown.initiated) {
option.selected = true;
} else {
option.selected = value === currentFilter;
}
dropdown.appendChild(option);
});
// Mark the dropdown as initiated to avoid resetting the filter on subsequent data loads
if (filterId === 'filter-status') {
dropdown.initiated = true;
}
}
// Make sure the initial population is done correctly
function populateInitialDropdowns() {
const allRows = document.querySelectorAll('#uptime-status tbody tr');
['wallet', 'status', 'connected', 'gpu', 'cpu', 'ram', 'location'].forEach(key => {
populateDropdown(`filter-${key}`, allRows, key);
});
}
function applyAllFilters() {
console.log("Applying filters...");
const filters = {
wallet: document.getElementById('filter-wallet').value.toLowerCase(),
status: document.getElementById('filter-status').value.toLowerCase(),
connected: document.getElementById('filter-connected').value.toLowerCase(),
gpu: document.getElementById('filter-gpu').value.toLowerCase(),
cpu: document.getElementById('filter-cpu').value.toLowerCase(),
ram: document.getElementById('filter-ram').value.toLowerCase(),
location: document.getElementById('filter-location').value.toLowerCase(),
};
const rows = document.querySelectorAll('#uptime-status tbody tr');
rows.forEach(row => {
let visible = true;
Object.keys(filters).forEach(key => {
const columnValue = row.querySelector(`td[data-key='${key}']`).textContent.toLowerCase();
if (filters[key] !== 'all' && !columnValue.includes(filters[key])) {
visible = false;
}
});
row.style.display = visible ? '' : 'none';
});
updateDropdownsBasedOnVisibility();
}
function updateDropdownsBasedOnVisibility() {
const visibleRows = document.querySelectorAll('#uptime-status tbody tr:not([style*="display: none"])');
['wallet', 'status', 'connected', 'gpu', 'cpu', 'ram', 'location'].forEach(key => {
populateDropdown(`filter-${key}`, visibleRows, key);
});
}
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('select').forEach(select => {
select.addEventListener('change', applyAllFilters);
});
fetchUptimeData();
});
setInterval(fetchUptimeData, refreshInterval);
</script>
</body>
</html>