-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.html
313 lines (270 loc) · 10.1 KB
/
dashboard.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
305
306
307
308
309
310
311
312
313
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ad Break and Segment Mappings</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #121212;
color: #ffffff;
display: flex;
}
h1, h2 {
color: #ffffff;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 12px;
border: 1px solid #444444;
text-align: left;
}
th {
background-color: #333333;
}
tr:nth-child(even) {
background-color: #1f1f1f;
}
.input-row {
margin-bottom: 20px;
display: flex;
align-items: center;
}
.input-row input {
margin-right: 10px;
padding: 8px;
border: 1px solid #444444;
background-color: #1f1f1f;
color: #ffffff;
}
.input-row button {
padding: 8px 16px;
background-color: #4CAF50;
color: #ffffff;
border: none;
cursor: pointer;
opacity: 0.5;
}
.input-row button:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.clear-button {
padding: 8px 16px;
background-color: #f44336;
color: #ffffff;
border: none;
cursor: pointer;
}
.error-message {
color: #ff0000;
margin-top: 10px;
display: none;
}
select {
background-color: #333;
color: white;
border: 1px solid #444;
padding: 6px;
}
/* Styles for the vertical rail */
.rail {
width: 300px;
max-height: 100vh;
overflow-y: auto;
border-left: 2px solid #333;
padding: 10px;
}
.rail table {
width: 100%;
border-collapse: collapse;
}
.rail th, .rail td {
padding: 8px;
border: 1px solid #444444;
text-align: left;
}
.rail th {
background-color: #444;
position: sticky;
top: 0;
z-index: 1;
}
.rail tr:nth-child(even) {
background-color: #1f1f1f;
}
</style>
</head>
<body>
<div class="main-content">
<h1>Ad Break and Segment Dashboard</h1>
<h2>Available Ad-Breaks</h2>
<table id="adBreakTable">
<thead>
<tr>
<th>BreakID</th>
<th>Ad-Mapping</th>
<th>Assign</th> <!-- Renamed Action to Assign -->
</tr>
</thead>
<tbody>
<!-- Ad-break rows will be populated here -->
</tbody>
</table>
<h2>Segment Mappings</h2>
<table id="segmentTable">
<thead>
<tr>
<th>Segment Name</th>
<th>Segment Mapping</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<!-- Segment rows will be populated here -->
</tbody>
</table>
<div class="input-row">
<input type="text" id="idInput" placeholder="ID" />
<input type="text" id="destInput" placeholder="Dest" />
<button id="addButton" disabled>New Mapping</button>
</div>
<div class="error-message" id="errorMessage">Oops! An error occurred.</div>
</div>
<!-- Vertical Rail to display JSON data -->
<div class="rail">
<h2>Client Beacons</h2>
<table id="messageTable">
<thead>
<tr>
<th>Received</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<!-- Rows for received Client Beacon data will be populated here -->
</tbody>
</table>
</div>
<script>
// Function to update the Ad Break and Segment tables from the provided data
function updateTables(data) {
const adBreakTableBody = document.getElementById('adBreakTable').getElementsByTagName('tbody')[0];
adBreakTableBody.innerHTML = ''; // Clear current table rows
data.AdBreaks.forEach(adBreak => {
const tr = document.createElement('tr');
const tdBreakID = document.createElement('td');
tdBreakID.textContent = adBreak; // BreakID from AdBreaks
const tdAdMapping = document.createElement('td');
tdAdMapping.textContent = data.AdBreakMappings[adBreak] || ""; // Display Ad-Mapping or leave blank if none
const tdAssign = document.createElement('td');
const selectDropdown = document.createElement('select');
const options = ["Smash", "Arrow", "Spikes", "None"];
options.forEach(option => {
const opt = document.createElement('option');
opt.value = option;
opt.textContent = option;
if ((data.AdBreakMappings[adBreak] || "None") === option) {
opt.selected = true;
}
selectDropdown.appendChild(opt);
});
selectDropdown.onchange = async function() {
const selectedAd = selectDropdown.value;
if (data.AdBreakMappings[adBreak] === selectedAd) {
return;
}
const payload = {
break_id: adBreak,
ad: selectedAd
};
const postResponse = await fetch('/map', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (postResponse.ok) {
const updatedData = await postResponse.json();
updateTables(updatedData); // Update the page with the returned data
}
};
tdAssign.appendChild(selectDropdown);
tr.appendChild(tdBreakID);
tr.appendChild(tdAdMapping);
tr.appendChild(tdAssign);
adBreakTableBody.appendChild(tr);
});
const segmentTableBody = document.getElementById('segmentTable').getElementsByTagName('tbody')[0];
segmentTableBody.innerHTML = '';
Object.keys(data.SegmentMappings).forEach(segmentName => {
const tr = document.createElement('tr');
const tdSegmentName = document.createElement('td');
tdSegmentName.textContent = segmentName;
const tdSegmentMapping = document.createElement('td');
tdSegmentMapping.textContent = data.SegmentMappings[segmentName];
const tdAction = document.createElement('td');
const clearButton = document.createElement('button');
clearButton.textContent = 'Clear';
clearButton.className = 'clear-button';
clearButton.onclick = async function() {
const deleteResponse = await fetch(`/segment/${segmentName}`, { method: 'DELETE' });
if (deleteResponse.ok) {
const updatedData = await deleteResponse.json();
updateTables(updatedData);
}
};
tdAction.appendChild(clearButton);
tr.appendChild(tdSegmentName);
tr.appendChild(tdSegmentMapping);
tr.appendChild(tdAction);
segmentTableBody.appendChild(tr);
});
}
// Function to fetch and display the UDP messages in the vertical rail
async function fetchMessages() {
try {
const response = await fetch('http://localhost:8084/status');
const data = await response.json();
const messageTableBody = document.getElementById('messageTable').getElementsByTagName('tbody')[0];
messageTableBody.innerHTML = '';
data.forEach(msg => {
const tr = document.createElement('tr');
const tdReceived = document.createElement('td');
const tdMessage = document.createElement('td');
tdReceived.textContent = new Date(msg.received).toLocaleString();
tdMessage.textContent = msg.message;
tr.appendChild(tdReceived);
tr.appendChild(tdMessage);
messageTableBody.appendChild(tr);
});
} catch (error) {
console.error('Error fetching messages:', error);
}
}
// Refresh the message table every second
setInterval(fetchMessages, 1000);
// Initial fetch to populate tables on page load
async function fetchAndUpdate() {
try {
const response = await fetch('./dashboard.json');
const data = await response.json();
updateTables(data);
} catch (error) {
console.error('Error fetching data:', error);
}
}
// Initial fetch
fetchAndUpdate();
// Add event listeners for input changes and button click
document.getElementById('idInput').addEventListener('input', toggleButtonState);
document.getElementById('destInput').addEventListener('input', toggleButtonState);
document.getElementById('addButton').addEventListener('click', addNewMapping);
</script>
</body>
</html>