-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisp.html
218 lines (188 loc) · 4.99 KB
/
disp.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
<!DOCTYPE html>
<head>
<meta content="width=device-width,initial-scale=1" />
<style>
@import url("https://fonts.googleapis.com/icon?family=Material+Icons");
@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap");
* {
font-family: monospace;
}
@media (pointer: coarse) {
body {
zoom: 150%;
}
}
body {
margin: 0;
}
#display {
display: flex;
padding: 30pt 30pt 100pt;
align-content: flex-start;
flex-direction: column;
box-sizing: border-box;
overflow-x: scroll;
flex-wrap: wrap;
position: fixed;
height: 100%;
width: 100%;
}
#display > * {
width: min(calc(36vw - 50pt), 200pt);
box-sizing: border-box;
height: 30pt;
}
.head {
background-image: linear-gradient(green, darkgreen);
padding: 6.4pt 10pt;
}
.head.late {
background-image: linear-gradient(red, darkred);
}
.head.ubmp {
background-image: linear-gradient(lightseagreen, darkcyan);
}
.item.sel {
background-image: linear-gradient(khaki, darkkhaki);
}
.tble {
font-style: italic;
color: white;
font-size: 13pt;
}
.time {
float: right;
color: white;
font-size: 13pt;
}
.item {
font-size: 13pt;
padding: 6pt 10pt;
background-image: linear-gradient(white, #eee);
}
.plte-subb {
margin: 0 0 6pt;
padding: 0 0 6pt;
font-size: 12pt;
}
.plte-subb:not(:last-child) {
border-bottom: solid 1pt lightgrey;
}
#footer {
bottom: 0;
justify-content: space-around;
background-color: #eee;
box-sizing: border-box;
padding: 5pt min(20%, 10pt);
position: fixed;
display: flex;
width: 100%;
height: 40pt;
}
#footer > button {
min-width: fit-content;
font-size: 13pt;
}
</style>
</head>
<body>
<div id="display"></div>
<footer id="footer">
<button message="bump0">Bump #1</button>
<button message="bump1">Bump #2</button>
<button message="bump2">Bump #3</button>
<button message="bump3">Bump #4</button>
<button message="bump4">Bump #5</button>
<button message="unbump">Recall</button>
</footer>
<script>
const pnel_lst = [];
const time_lst = [];
function createPnels(ordr) {
var ps = [];
function clk() {
if (ps[0].classList.contains("sel")) for (let p of ps) p.classList.remove("sel");
else for (let p of ps) p.classList.add("sel");
}
function dbl(event) {
event.stopPropagation();
var i = pnel_lst.indexOf(ps);
ws.send(`bump${i}`);
}
var plte = ordr.plte;
var head = document.createElement("div");
var time = document.createElement("div");
var tble = document.createElement("div");
tble.innerText = `Table #${ordr.tble}`;
head.className = "head";
time.className = "time";
tble.className = "tble";
head.append(time, tble);
head.ondblclick = dbl;
head.onclick = clk;
ps.push(head);
for (let [n, c] of Object.entries(plte)) {
var i = document.createElement("div");
i.innerText = `[${c}] ${n}`;
i.className = "item";
i.ondblclick = dbl;
i.onclick = clk;
ps.push(i);
}
var b = document.createElement("div");
b.className = "bffr";
ps.push(b);
return ps;
}
function tick(lst_idx) {
if (time_lst[lst_idx] === undefined) return;
var e = pnel_lst[lst_idx][0].getElementsByClassName("time")[0];
var t = ++time_lst[lst_idx],
m = ~~(t / 60),
s = ("" + (t % 60)).padStart(2, 0);
if (t == 5 * 60) pnel_lst[lst_idx][0].className.add("late");
e.innerText = `${m}:${s}`;
}
function add(ordr) {
var ps = createPnels(ordr);
var i = pnel_lst.push(ps);
time_lst.push(0);
for (let p of ps) disp.append(p);
tick(i - 1);
}
function bump(idx) {
time_lst.splice(idx, 1);
for (let p of pnel_lst.splice(idx, 1)[0]) p.remove();
}
function ubmp(ordr) {
var ps = createPnels(ordr);
ps[0].classList.add("ubmp");
time_lst.unshift(undefined);
pnel_lst.unshift(ps);
for (let p of ps.reverse()) disp.prepend(p);
tick(0);
}
setInterval(() => {
for (let i in pnel_lst) tick(i);
}, 1000);
const req = new XMLHttpRequest();
const disp = document.getElementById("display");
const foot = document.getElementById("footer");
req.open("GET", document.location, false);
req.send(null);
const code = req.getResponseHeader("auth-code");
const ws = new WebSocket("ws://localhost:8081");
ws.onopen = () => ws.send(code);
ws.onmessage = (e) => {
var d = JSON.parse(e.data);
var adds = d.adds,
idxs = d.idxs;
for (let c = 0; c < adds.length || c < idxs.length; c++) {
if (!adds[c]) bump(idxs[c]);
else if (idxs[c] == undefined) add(adds[c]);
else if (idxs[c] == 0) ubmp(adds[c]);
}
};
for (let n of foot.childNodes) n.onclick = () => ws.send(n.getAttribute("message"));
</script>
</body>