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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta name="author" content="Daniel Jones">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Matrix Display</title>
<style>
.block {
display: block;
width: 100%;
border: none;
background-color: #04AA6D;
color: white;
padding: 14px 28px;
font-size: 16px;
cursor: pointer;
text-align: center;
}
.block:hover {
background-color: #ddd;
color: black;
}
body {
background: #F7F0FF;
}
.center {
display: flex;
justify-content: center;
align-items: center;
height: auto;
}
.content {
border-radius: 10px;
//border: 3px solid green;
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
max-width: 95%;
max-height: 95%;
}
#centertext {
text-align: center
}
#footer {
text-align: left;
position: fixed;
bottom: 0;
left: 0
}
fieldset {
margin-bottom: 1em;
border-right: 1px solid #666;
border-bottom: 3px solid #000000;
border: 3px solid #000000;
}
table.minimalistBlack {
border: 3px solid #000000;
width: 100%;
text-align: center;
border-collapse: collapse;
}
table.minimalistBlack td,
table.minimalistBlack th {
border: 1px solid #000000;
padding: 5px 4px;
}
table.minimalistBlack tbody td {
font-size: 13px;
}
table.minimalistBlack thead {
background: #CFCFCF;
background: -moz-linear-gradient(top, #dbdbdb 0%, #d3d3d3 66%, #CFCFCF 100%);
background: -webkit-linear-gradient(top, #dbdbdb 0%, #d3d3d3 66%, #CFCFCF 100%);
background: linear-gradient(to bottom, #dbdbdb 0%, #d3d3d3 66%, #CFCFCF 100%);
border-bottom: 3px solid #000000;
}
table.minimalistBlack thead th {
font-size: 15px;
font-weight: bold;
color: #000000;
text-align: center;
}
table.minimalistBlack tfoot td {
font-size: 14px;
}
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
select {
width: auto;
padding: 5px 5px;
border: none;
border-radius: 4px;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<div class="center">
<div class="content">
<h1 id="centertext">Matrix Display</h1>
<table class="minimalistBlack">
<thead>
<tr>
<th>Special string</th>
<th>Replacement</th>
</tr>
</thead>
<tbody>
<tr>
<td>%date%</td>
<td>The selected date (dd/mm/yy)</td>
</tr>
<tr>
<td>%shortdate%</td>
<td>The selected date short (20 Jan)</td>
</tr>
<tr>
<td>%time12% or %time12s%</td>
<td>time in 12 hour format HH:MM or HH:MM:SS</td>
</tr>
<tr>
<td>%time24% or %time24s%</td>
<td>time in 24 hour format HH:MM or HH:MM:SS</td>
</tr>
<!--
<tr>
<td>%weeks%</td>
<td>Weeks until the selected date</td>
</tr>
<tr>
<td>%days%</td>
<td>Days until the selected date</td>
</tr>
<tr>
<td>%hours%</td>
<td>Hours until the selected date</td>
</tr>
<tr>
<td>%minutes%</td>
<td>Minutes until the selected date</td>
</tr>
<tr>
<td>%seconds%</td>
<td>Seconds until the selected date</td>
</tr>
-->
</tr>
</tbody>
</table>
<form id="saveform">
<fieldset>
<legend>Customisation:</legend>
<button type="button" id="toggledisplay" onclick="sendPostRequest('matrix', 'toggle')">Toggle Display</button>
<button type="button" id="restart" onclick="sendPostRequest('restart', '')">Restart Sign</button><br>
Wireless (required for time sync):<br>
<input type="text" id="cssid" name="cssid" placeholder="ssid"> <input type="password" id="cpassword"
name="cpassword" placeholder="password">
<p id="wifistatus">No data</p>
<label for="start">Countdown date:</label>
<input type="date" id="datep" name="datep"><br>
<label for="brightness">Brightness:</label>
<input type="range" min="0" max="15" value="3" class="slider" name="brightness" id="brightness">
<label for="autoBrightness">Auto Brightness:</label>
<input type="checkbox" id="autoBrightness" name="autoBrightness" value="autoBrightness"><br><br>
<input class="block" type="submit" value="Save">
<br>
<div style="overflow-y: scroll; height:400px;">
<script>
var html = `
<input type="text" id="m%d" name="m%d" placeholder="Message %d">
<input type="checkbox" id="m%denabled" name="m%denabled" value="Enabled">
<label for="m%dinvert">Enabled</label> <br>
<label for="m%deffect2">Start:</label>
<select name="m%deffect" id="m%deffect">
<option selected="selected" value="4">Scroll right to left</option>
<option value="5">Scroll left to right</option>
<option value="0">No effect</option>
<option value="1">Static</option>
<option value="2">Scroll up</option>
<option value="3">Scroll down</option>
<option value="7">Slice</option>
<option value="8">Mesh</option>
<option value="9">Fade</option>
<option value="10">Dissolve</option>
<option value="11">Blinds</option>
<option value="12">Random</option>
<option value="13">Wipe</option>
<option value="14">Wipe (with bar)</option>
<option value="19">Curtains (from center)</option>
<option value="20">Curtains (c/with bar)</option>
<option value="21">Curtains (from ends)</option>
<option value="22">Curtains (e/with bar)</option>
<option value="23">Scroll up+left</option>
<option value="24">Scroll up+right</option>
<option value="25">Scroll down+left</option>
<option value="26">Scroll down+right</option>
<option value="27">Grow up</option>
<option value="28">Grow down</option>
</select>
<label for="m%deffect2">End:</label>
<select name="m%deffect2" id="m%deffect2">
<option selected="selected" value="4">Scroll right to left</option>
<option value="5">Scroll left to right</option>
<option value="0">No effect</option>
<option value="1">Static</option>
<option value="2">Scroll up</option>
<option value="3">Scroll down</option>
<option value="7">Slice</option>
<option value="8">Mesh</option>
<option value="9">Fade</option>
<option value="10">Dissolve</option>
<option value="11">Blinds</option>
<option value="12">Random</option>
<option value="13">Wipe</option>
<option value="14">Wipe (with bar)</option>
<option value="19">Curtains (from center)</option>
<option value="20">Curtains (c/with bar)</option>
<option value="21">Curtains (from ends)</option>
<option value="22">Curtains (e/with bar)</option>
<option value="23">Scroll up+left</option>
<option value="24">Scroll up+right</option>
<option value="25">Scroll down+left</option>
<option value="26">Scroll down+right</option>
<option value="27">Grow up</option>
<option value="28">Grow down</option>
</select> <br>
<label for="m%dspeed">Speed:</label>
<select name="m%dspeed" id="m%dspeed">
<option value="slow">Slow</option>
<option selected="selected" value="medium">Medium</option>
<option value="fast">Fast</option>
</select>
<label for="m%dpause">Pause in seconds:</label>
<input type="number" style="width: 30px;" id="m%dpause" name="m%dpause" min="0" max="34600">
<input type="checkbox" id="m%dinvert" name="m%dinvert" value="Invert">
<label for="m%dinvert">Invert</label>
<hr>
`;
for (i = 0; i < 20; i++) {
document.write(html.replaceAll('%d', i + 1));
}
</script>
</div><br>
<input class="block" type="submit" value="Save">
</fieldset>
</form>
</div>
</div>
<script>
const ajax = async (config) => {
const request = await fetch(config.url, {
method: config.method,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(config.payload)
});
response = await request.json();
console.log('response', response)
return response
}
function handleSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);
const value = Object.fromEntries(data.entries());
console.log({ value });
response = ajax({
method: 'POST',
url: '/msg',
payload: value
})
}
var getJSON = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function () {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
window.addEventListener("load", (event) => {
console.log("running loadconfig");
getJSON('/config',
function (err, data) {
if (err !== null) {
alert('Something went wrong: ' + err);
} else {
console.log({ data });
/*
switch (data.brightness)
{
case 3:
console.log("brightness low");
document.getElementById("Low").checked = true;
break;
case 7:
console.log("brightness medium");
document.getElementById("Medium").checked = true;
break;
case 15:
console.log("brightness high");
document.getElementById("High").checked = true;
break;
default:
console.log("Default brightness");
document.getElementById("Medium").checked = true;
break;
}
*/
document.getElementById("brightness").value = data.brightness;
document.getElementById("autoBrightness").checked = data.autoBrightness;
document.getElementById("cssid").value = data["cssid"];
document.getElementById("cpassword").value = data["cpassword"];
document.getElementById("datep").valueAsDate = new Date(data["datep"]);
if (data["wifistatus"] == "Not connected") {
document.getElementById("wifistatus").innerText = "Not connected to a network";
}
else {
document.getElementById("wifistatus").innerText = "Access this page through the network above: http://" + data["wifistatus"];
}
// 1
for (i = 0; i < 20; i++) {
n = i + 1;
document.getElementById("m" + n).value = data["m" + n];
document.getElementById("m" + n + "enabled").checked = data["m" + n + "enabled"];
/*
switch (data["m"+n+"effect"])
{case 5:document.getElementById("m"+n+"effect").value = "ltr";break;default:case 4:document.getElementById("m"+n+"effect").value = "rtl";break;}
*/
switch (data["m" + n + "speed"]) { case 60: document.getElementById("m" + n + "speed").value = "slow"; break; default: case 40: document.getElementById("m" + n + "speed").value = "medium"; break; case 20: document.getElementById("m" + n + "speed").value = "fast"; break; }
document.getElementById("m" + n + "pause").value = data["m" + n + "pause"];
document.getElementById("m" + n + "invert").checked = data["m" + n + "invert"];
document.getElementById("m" + n + "effect").value = data["m" + n + "effect"];
document.getElementById("m" + n + "effect2").value = data["m" + n + "effect2"];
}
}
});
});
const form = document.getElementById('saveform');
form.addEventListener('submit', handleSubmit);
document.getElementById("datep").valueAsDate = new Date();
function sendPostRequest(key, value) {
const data = {
[key]: value
};
fetch('/cmd', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}
</script>
</body>
</html>
|