-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
292 lines (250 loc) · 10.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lilypad Job 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;
}
</style>
</head>
<body>
<h1>Lilypad Job 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-id">Job ID:</label>
<select id="filter-id" onchange="applyAllFilters()"></select>
<label for="filter-jobcreator">Job Creator:</label>
<select id="filter-jobcreator" onchange="applyAllFilters()"></select>
<label for="filter-dealid">Deal ID:</label>
<select id="filter-dealid" onchange="applyAllFilters()"></select>
<label for="filter-state">State:</label>
<select id="filter-state" onchange="applyAllFilters()"></select>
<label for="filter-module">Module:</label>
<select id="filter-module" onchange="applyAllFilters()"></select>
<label for="filter-event">Event:</label>
<select id="filter-event" onchange="applyAllFilters()"></select>
<label for="filter-updated">Updated At:</label>
<select id="filter-updated" onchange="applyAllFilters()"></select>
</div>
<table id="uptime-status">
<thead>
<tr>
<th>Job ID</th>
<th>Job Creator</th>
<th>Deal ID</th>
<th>State</th>
<th>Module</th>
<th>Event</th>
<th>Updated At</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/jobs');
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`);
}
const jobs = await response.json();
console.log("Data parsed:", jobs);
if (!jobs.length) {
throw new Error("No job data returned or incorrect format.");
}
tableBody.innerHTML = '';
jobs.forEach(job => {
const row = createJobRow(job);
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 createJobRow(job) {
const row = document.createElement('tr');
row.innerHTML = `
<td data-key="id">${job.ID}</td>
<td data-key="jobcreator">${job.JobCreator}</td>
<td data-key="dealid">${job.DealID}</td>
<td data-key="state">${job.State}</td>
<td data-key="module">${job.Module}</td>
<td data-key="event">${job.Event}</td>
<td data-key="updated">${new Date(job.UpdatedAt).toLocaleString()}</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');
['id', 'jobcreator', 'dealid', 'state', 'module', 'event', 'updated'].forEach(key => {
populateDropdown(`filter-${key}`, allRows, key);
});
}
function applyAllFilters() {
console.log("Applying filters...");
const filters = {
id: document.getElementById('filter-id').value.toLowerCase(),
jobcreator: document.getElementById('filter-jobcreator').value.toLowerCase(),
dealid: document.getElementById('filter-dealid').value.toLowerCase(),
state: document.getElementById('filter-state').value.toLowerCase(),
module: document.getElementById('filter-module').value.toLowerCase(),
event: document.getElementById('filter-event').value.toLowerCase(),
updated: document.getElementById('filter-updated').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"])');
['id', 'jobcreator', 'dealid', 'state', 'module', 'event', 'updated'].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>