-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
429 lines (393 loc) · 21.1 KB
/
Copy pathindex.html
File metadata and controls
429 lines (393 loc) · 21.1 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bossman Gentleman's Club Barbershop</title>
<link rel="stylesheet" href="brand.css">
<style>
body { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; }
.wrap { width: 100%; max-width: 380px; }
.topclock { position: fixed; top: 0; left: 0; right: 0; text-align: center; padding: 0.5rem; font-size: 0.78rem; letter-spacing: 0.1em; color: var(--gold); background: rgba(10,31,20,0.85); backdrop-filter: blur(6px); z-index: 50; border-bottom: 1px solid var(--line); }
.brand .logo { width: 210px; border-radius: 0.5rem; }
.brand .sub { font-size: 0.82rem; margin-top: 1rem; }
.card {
background: var(--moss); border: 1px solid var(--line); border-radius: 1rem;
box-shadow: var(--shadow); padding: 1.1rem 1.25rem; width: 100%;
display: flex; align-items: center; justify-content: space-between;
cursor: pointer; text-align: left; transition: border-color 0.15s, transform 0.05s;
}
.card:hover { border-color: var(--gold); }
.card:active { transform: translateY(1px); }
.card-name { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; color: var(--cream); }
.card-meta { color: var(--cream-dim); font-size: 0.82rem; margin-top: 0.3rem; letter-spacing: 0.02em; }
.arrow { color: var(--gold); font-size: 1.5rem; }
.worker-divider { text-align: center; color: var(--gold); font-size: 0.68rem; letter-spacing: 0.28em; text-transform: uppercase; margin: 0.75rem 0 0.25rem; opacity: 0.85; }
.role-tag { font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--pine); background: var(--gold); padding: 0.12rem 0.45rem; border-radius: 999px; vertical-align: middle; margin-left: 0.4rem; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; margin-top: 1.75rem; }
.panel { background: var(--moss); border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); padding: 1.5rem; width: 100%; }
.panel h2 { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; color: var(--cream); }
.panel .meta { color: var(--gold); font-size: 0.8rem; margin-top: 0.3rem; margin-bottom: 1.25rem; letter-spacing: 0.05em; }
label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--cream-dim); margin-bottom: 0.4rem; letter-spacing: 0.04em; text-transform: uppercase; }
input {
width: 100%; background: var(--pine); border: 1.5px solid var(--fern); border-radius: 0.6rem;
padding: 0.7rem 0.85rem; font-size: 1rem; color: var(--cream); outline: none; margin-bottom: 1rem;
font-family: var(--sans);
}
input::placeholder { color: #5f6b5c; }
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,167,106,0.18); }
.hint { font-size: 0.72rem; color: var(--cream-dim); margin-top: -0.75rem; margin-bottom: 1rem; }
.facial-opt { display: flex; align-items: center; gap: 0.6rem; background: var(--pine); border: 1.5px solid var(--fern); border-radius: 0.6rem; padding: 0.75rem 0.85rem; margin-bottom: 1rem; cursor: pointer; text-transform: none; letter-spacing: 0; }
.facial-opt input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--gold); flex-shrink: 0; }
.facial-opt span { font-size: 0.85rem; color: var(--cream); font-weight: 400; }
.facial-opt strong { color: var(--gold); }
.btn-full { width: 100%; padding: 0.85rem; font-size: 1rem; }
.btn-back { background: none; border: none; color: var(--gold); font-size: 0.85rem; font-weight: 500; cursor: pointer; margin-bottom: 1rem; padding: 0; letter-spacing: 0.05em; }
.error { color: #e88; font-size: 0.85rem; margin-bottom: 0.75rem; }
.done-box { text-align: center; }
.done-icon { font-size: 3.5rem; }
.done-box h2 { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; color: var(--cream); margin-top: 0.75rem; }
.badge { background: var(--pine); border: 1px solid var(--gold); border-radius: 0.75rem; padding: 1.1rem; margin: 1.25rem 0; }
.badge .pos { font-family: var(--serif); font-size: 2.75rem; font-weight: 800; color: var(--gold); }
.badge .pos-label { color: var(--cream-dim); font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase; }
.stats { display: flex; justify-content: space-around; margin: 1.25rem 0; }
.stat-val { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; color: var(--cream); }
.stat-label { font-size: 0.7rem; color: var(--cream-dim); letter-spacing: 0.06em; text-transform: uppercase; margin-top: 0.15rem; }
.closed { text-align: center; padding: 2.5rem 0; }
.closed .ico { font-size: 2.5rem; }
.closed .ttl { font-family: var(--serif); font-weight: 700; color: var(--cream); margin-top: 0.75rem; font-size: 1.15rem; }
.closed .txt { color: var(--cream-dim); font-size: 0.85rem; margin-top: 0.4rem; line-height: 1.5; }
#loading { color: var(--cream-dim); text-align: center; padding: 2rem 0; letter-spacing: 0.05em; }
</style>
</head>
<body>
<div class="topclock" id="clock">🕐 --:--:-- MYT</div>
<div class="wrap">
<!-- Step 1: Pick barber -->
<div id="step-pick">
<div class="brand">
<img src="logo.png" alt="Bossman Gentleman's Club Barbershop" class="logo" onerror="this.style.display='none'">
<div class="sub">Choose your barber to join the queue</div>
</div>
<div class="stack" id="barber-list">
<p id="loading">Loading barbers…</p>
</div>
</div>
<!-- Step 2: Enter details -->
<div id="step-form" class="hidden">
<div class="panel">
<button class="btn-back" onclick="showPick()">← Back</button>
<h2 id="form-title">Join queue</h2>
<p class="meta" id="form-meta"></p>
<p class="error hidden" id="form-error"></p>
<label>Your Name</label>
<input type="text" id="inp-name" placeholder="e.g. Ahmad">
<label>WhatsApp Number</label>
<input type="tel" id="inp-phone" placeholder="e.g. 60123456789">
<p class="hint">Include country code, no spaces or dashes</p>
<label class="facial-opt hidden" id="facial-row" for="inp-facial">
<input type="checkbox" id="inp-facial">
<span>My service includes a <strong>facial</strong> (with Jassy)</span>
</label>
<button class="btn-gold btn-full" id="btn-join" onclick="joinQueue()">Join Queue</button>
</div>
</div>
<!-- Step 3: Confirmation -->
<div id="step-done" class="hidden">
<div class="panel done-box">
<div class="done-icon" id="conf-icon">✅</div>
<h2 id="conf-title">You're in the queue!</h2>
<p style="color:var(--cream-dim);margin-top:0.5rem;">Barber: <strong style="color:var(--cream)" id="conf-barber"></strong></p>
<div class="badge" id="conf-badge">
<div class="pos" id="conf-pos">#1</div>
<div class="pos-label">your position</div>
</div>
<div class="stats" id="conf-stats">
<div><div class="stat-val" id="conf-ahead">0</div><div class="stat-label">ahead of you</div></div>
<div><div class="stat-val" id="conf-wait">~0m</div><div class="stat-label">est. wait</div></div>
</div>
<p style="font-size:0.78rem;color:var(--gold);margin-top:0.75rem;letter-spacing:0.08em;" id="conf-clock">🕐 --:--:-- MYT</p>
<p style="font-size:0.7rem;color:var(--cream-dim);margin-top:0.25rem;letter-spacing:0.05em;" id="conf-refresh">Updates automatically every 30 seconds</p>
<button class="btn-back" id="btn-leave" onclick="leaveQueue()" style="margin-top:1.25rem;display:block;width:100%;color:var(--cream-dim);">Leave Queue</button>
</div>
</div>
</div>
<script src="api.js"></script>
<script>
var barbers = [];
var selectedBarber = null;
var queueCounts = {};
var myEntryId = null;
var myBarberId = null;
var refreshInterval = null;
var facialTherapist = null;
var myFacialEntryId = null;
var myFacialBarberId = null;
// Minutes left on the current cut, counting down with real elapsed time
function remainingCut(serving, avg) {
if (!serving) return 0;
var duration = serving.durationMinutes || avg;
if (!serving.calledAt) return duration;
var elapsedMin = (Date.now() - new Date(serving.calledAt).getTime()) / 60000;
return Math.max(0, Math.round(duration - elapsedMin));
}
// Live Malaysia clock (updates both the top bar and confirmation screen)
function tickClock() {
var t = new Date().toLocaleTimeString("en-GB", { timeZone: "Asia/Kuala_Lumpur", hour: "2-digit", minute: "2-digit", second: "2-digit" });
var label = "🕐 " + t + " MYT";
var top = document.getElementById("clock");
var conf = document.getElementById("conf-clock");
if (top) top.textContent = label;
if (conf) conf.textContent = label;
}
setInterval(tickClock, 1000);
tickClock();
var STORE_KEY = "bossman_queue";
function saveEntry(barber) {
localStorage.setItem(STORE_KEY, JSON.stringify({ entryId: myEntryId, id: barber.id, name: barber.name, avgMinutes: AVG, facialEntryId: myFacialEntryId, facialBarberId: myFacialBarberId }));
}
function clearEntry() { localStorage.removeItem(STORE_KEY); }
// On load, if the customer already joined earlier, jump back to their status
function resumeEntry() {
var raw = localStorage.getItem(STORE_KEY);
if (!raw) { loadBarbers(); return; }
var saved;
try { saved = JSON.parse(raw); } catch (e) { clearEntry(); loadBarbers(); return; }
call({ action: "getQueue", barberId: saved.id }).then(function(queue) {
var entry = (queue || []).find(function(e) { return e.id === saved.entryId; });
if (!entry) { clearEntry(); loadBarbers(); return; }
selectedBarber = { id: saved.id, name: saved.name, avgMinutes: AVG };
myEntryId = saved.entryId;
myBarberId = saved.id;
myFacialEntryId = saved.facialEntryId || null;
myFacialBarberId = saved.facialBarberId || null;
document.getElementById("conf-barber").textContent = saved.name;
document.getElementById("step-pick").classList.add("hidden");
document.getElementById("step-done").classList.remove("hidden");
refreshPosition();
if (refreshInterval) clearInterval(refreshInterval);
refreshInterval = setInterval(refreshPosition, 30000);
}).catch(function() { loadBarbers(); });
}
function showPick() {
document.getElementById("step-pick").classList.remove("hidden");
document.getElementById("step-form").classList.add("hidden");
document.getElementById("step-done").classList.add("hidden");
}
function showForm(barber) {
selectedBarber = barber;
var count = queueCounts[barber.id] || 0;
var therapist = isTherapist(barber);
document.getElementById("form-title").textContent = "Join " + barber.name + "'s queue";
document.getElementById("form-meta").textContent = therapist
? (count + " waiting · facial treatments")
: (count + " waiting · ~" + (count * AVG) + " min");
// Facial add-on checkbox only for barbers, and only if a therapist is available
var facialRow = document.getElementById("facial-row");
if (!therapist && facialTherapist) facialRow.classList.remove("hidden");
else facialRow.classList.add("hidden");
document.getElementById("inp-facial").checked = false;
document.getElementById("step-pick").classList.add("hidden");
document.getElementById("step-form").classList.remove("hidden");
document.getElementById("form-error").classList.add("hidden");
document.getElementById("inp-name").value = "";
document.getElementById("inp-phone").value = "";
}
var AVG = 35; // flat average wait estimate per customer (minutes)
function loadBarbers() {
call({ action: "getBarbers" }).then(function(data) {
barbers = data || [];
barbers.forEach(function(b) { b.avgMinutes = AVG; });
var done = 0;
if (barbers.length === 0) { renderBarbers(); return; }
barbers.forEach(function(b) {
call({ action: "getQueue", barberId: b.id }).then(function(q) {
queueCounts[b.id] = (q || []).length;
done++;
if (done === barbers.length) renderBarbers();
}).catch(function() { done++; if (done === barbers.length) renderBarbers(); });
});
}).catch(function() {
document.getElementById("barber-list").innerHTML = "<p style='color:#e88;text-align:center'>Failed to load. Please refresh.</p>";
});
}
// A worker is a facial therapist by role, or by known id/name (fallback if the
// backend hasn't been redeployed with the role column yet).
function isTherapist(b) {
return (b.role || "").toLowerCase() === "therapist"
|| (b.id || "").toLowerCase() === "jassy"
|| (b.name || "").toLowerCase() === "jassy";
}
function makeCard(b, therapist) {
var count = queueCounts[b.id] || 0;
var btn = document.createElement("button");
btn.className = "card";
var meta = therapist
? (count + ' waiting · facial treatments')
: (count + ' waiting · ~' + (count * AVG) + ' min');
var tag = therapist ? ' <span class="role-tag">Facial Therapist</span>' : '';
btn.innerHTML = '<div><div class="card-name">' + b.name + tag + '</div><div class="card-meta">' + meta + '</div></div><div class="arrow">›</div>';
btn.onclick = function() { showForm(b); };
return btn;
}
function renderBarbers() {
var list = document.getElementById("barber-list");
list.innerHTML = "";
var realBarbers = barbers.filter(function(b) { return !isTherapist(b); });
var therapists = barbers.filter(function(b) { return isTherapist(b); });
facialTherapist = therapists[0] || null;
if (barbers.length === 0) {
list.innerHTML = "<div class='closed'><div class='ico'>🚫</div><div class='ttl'>We're closed right now</div><div class='txt'>All workers are currently unavailable.<br>Please come back later.</div></div>";
return;
}
realBarbers.forEach(function(b) { list.appendChild(makeCard(b, false)); });
if (therapists.length) {
var div = document.createElement("div");
div.className = "worker-divider";
div.textContent = "Facial Treatments";
list.appendChild(div);
therapists.forEach(function(b) { list.appendChild(makeCard(b, true)); });
}
}
var THROTTLE_MIN = 30; // a device may only join once every 30 minutes
var LAST_JOIN_KEY = "bossman_last_join";
var QR_TOKEN = new URLSearchParams(window.location.search).get("t") || "";
// ── Geofencing ── Bossman, Taipan Business Centre, USJ 10/1, Subang Jaya ──
var GEOFENCE_ENABLED = true;
var SHOP_LAT = 3.0454;
var SHOP_LNG = 101.5852;
var GEOFENCE_RADIUS_M = 250; // metres — covers the Taipan block, blocks remote joins
function distanceM(la1, lo1, la2, lo2) {
var R = 6371000, t = Math.PI / 180;
var dLa = (la2 - la1) * t, dLo = (lo2 - lo1) * t;
var a = Math.sin(dLa / 2) * Math.sin(dLa / 2) +
Math.cos(la1 * t) * Math.cos(la2 * t) * Math.sin(dLo / 2) * Math.sin(dLo / 2);
return 2 * R * Math.asin(Math.sqrt(a));
}
function checkGeofence(cb) {
if (!GEOFENCE_ENABLED) { cb(true); return; }
if (!navigator.geolocation) { cb(false, "Your device can't share location. Please ask our staff."); return; }
var btn = document.getElementById("btn-join");
btn.disabled = true; btn.textContent = "Checking location…";
navigator.geolocation.getCurrentPosition(function(pos) {
btn.disabled = false; btn.textContent = "Join Queue";
var d = distanceM(pos.coords.latitude, pos.coords.longitude, SHOP_LAT, SHOP_LNG);
if (d <= GEOFENCE_RADIUS_M) cb(true);
else cb(false, "You must be at Bossman to join the queue.");
}, function() {
btn.disabled = false; btn.textContent = "Join Queue";
cb(false, "Please allow location — you must be at the shop to join.");
}, { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 });
}
function joinQueue() {
var name = document.getElementById("inp-name").value.trim();
var phone = document.getElementById("inp-phone").value.trim();
var errEl = document.getElementById("form-error");
if (!name || !phone) { errEl.textContent = "Please enter your name and phone number."; errEl.classList.remove("hidden"); return; }
// Device throttle: block re-joining within 30 minutes of the last join
var last = parseInt(localStorage.getItem(LAST_JOIN_KEY) || "0");
var minsSince = (Date.now() - last) / 60000;
if (last && minsSince < THROTTLE_MIN) {
var wait = Math.ceil(THROTTLE_MIN - minsSince);
errEl.textContent = "This device already joined recently. Please wait " + wait + " more minute" + (wait === 1 ? "" : "s") + ", or see our staff.";
errEl.classList.remove("hidden");
return;
}
errEl.classList.add("hidden");
// Geofence gate, then submit
checkGeofence(function(ok, msg) {
if (!ok) { errEl.textContent = msg; errEl.classList.remove("hidden"); return; }
doJoin(name, phone, errEl);
});
}
function expiredMsg(errEl) {
errEl.textContent = "This QR has expired. Please scan the latest code at the counter.";
errEl.classList.remove("hidden");
}
function doJoin(name, phone, errEl) {
var btn = document.getElementById("btn-join");
btn.disabled = true; btn.textContent = "Joining…";
call({ action: "joinQueue", barberId: selectedBarber.id, barberName: selectedBarber.name, customerName: name, phone: phone, t: QR_TOKEN })
.then(function(res) {
btn.disabled = false; btn.textContent = "Join Queue";
if (res && res.error === "expired_qr") { expiredMsg(errEl); return; }
if (!res || res.error) { errEl.textContent = res.error || "Something went wrong."; errEl.classList.remove("hidden"); return; }
myEntryId = res.id;
myBarberId = selectedBarber.id;
localStorage.setItem(LAST_JOIN_KEY, Date.now()); // start the 30-min device lock
// Parallel facial booking → drop the customer into Jassy's queue immediately
var wantsFacial = !document.getElementById("facial-row").classList.contains("hidden")
&& document.getElementById("inp-facial").checked;
if (wantsFacial && facialTherapist) {
call({ action: "joinQueue", barberId: facialTherapist.id, barberName: facialTherapist.name, customerName: name + " (facial)", phone: phone, t: QR_TOKEN })
.then(function(r2) {
if (r2 && r2.id) { myFacialEntryId = r2.id; myFacialBarberId = facialTherapist.id; saveEntry(selectedBarber); }
}).catch(function() {});
}
saveEntry(selectedBarber);
document.getElementById("conf-barber").textContent = selectedBarber.name + (wantsFacial ? " + Facial (Jassy)" : "");
document.getElementById("conf-pos").textContent = "#" + res.position;
document.getElementById("conf-ahead").textContent = res.ahead;
document.getElementById("conf-wait").textContent = "~" + (res.ahead * AVG) + "m";
document.getElementById("step-form").classList.add("hidden");
document.getElementById("step-done").classList.remove("hidden");
tickClock();
refreshPosition();
if (refreshInterval) clearInterval(refreshInterval);
refreshInterval = setInterval(refreshPosition, 30000);
}).catch(function() {
btn.disabled = false; btn.textContent = "Join Queue";
errEl.textContent = "Something went wrong. Please try again.";
errEl.classList.remove("hidden");
});
}
function refreshPosition() {
if (!myEntryId || !myBarberId) return;
call({ action: "getQueue", barberId: myBarberId }).then(function(queue) {
var entry = (queue || []).find(function(e) { return e.id === myEntryId; });
if (!entry) {
clearInterval(refreshInterval);
clearEntry();
document.getElementById("conf-icon").textContent = "💈";
document.getElementById("conf-title").textContent = "It's your turn!";
document.getElementById("conf-pos").textContent = "Go!";
document.getElementById("conf-stats").classList.add("hidden");
document.getElementById("conf-refresh").classList.add("hidden");
document.getElementById("btn-leave").classList.add("hidden");
return;
}
var avg = selectedBarber ? selectedBarber.avgMinutes || 30 : 30;
var ahead = (queue || []).filter(function(e) { return e.status === "waiting" && e.position < entry.position; }).length;
var called = (queue || []).find(function(e) { return e.status === "called"; });
var waitMins = remainingCut(called, avg) + ahead * avg;
document.getElementById("conf-ahead").textContent = ahead;
document.getElementById("conf-wait").textContent = "~" + waitMins + "m";
var pos = (queue || []).filter(function(e) { return e.status === "waiting" && e.position <= entry.position; }).length;
document.getElementById("conf-pos").textContent = "#" + pos;
}).catch(function() {});
}
function leaveQueue() {
if (!myEntryId) return;
if (!confirm("Are you sure you want to leave the queue?")) return;
document.getElementById("btn-leave").textContent = "Leaving…";
var calls = [ call({ action: "leaveQueue", id: myEntryId }) ];
if (myFacialEntryId) calls.push(call({ action: "leaveQueue", id: myFacialEntryId }));
Promise.all(calls).then(function() {
clearInterval(refreshInterval);
clearEntry();
document.getElementById("conf-icon").textContent = "👋";
document.getElementById("conf-title").textContent = "You've left the queue";
document.getElementById("conf-badge").classList.add("hidden");
document.getElementById("conf-stats").classList.add("hidden");
document.getElementById("conf-refresh").classList.add("hidden");
var b = document.getElementById("btn-leave");
b.textContent = "← Choose a barber";
b.onclick = function() { location.reload(); };
}).catch(function() {
document.getElementById("btn-leave").textContent = "Leave Queue";
});
}
resumeEntry();
</script>
</body>
</html>