1311 lines
38 KiB
HTML
1311 lines
38 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="nl">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>Koffie Roulette</title>
|
||
|
|
<style>
|
||
|
|
:root {
|
||
|
|
--bg-primary: #0f172a;
|
||
|
|
--bg-secondary: #1e293b;
|
||
|
|
--bg-tertiary: #334155;
|
||
|
|
--text-main: #f8fafc;
|
||
|
|
--text-muted: #94a3b8;
|
||
|
|
--accent: #38bdf8;
|
||
|
|
--accent-hover: #0284c7;
|
||
|
|
--accent-active: #0369a1;
|
||
|
|
--danger: #ef4444;
|
||
|
|
--danger-hover: #dc2626;
|
||
|
|
--success: #10b981;
|
||
|
|
--success-hover: #059669;
|
||
|
|
--border-color: #334155;
|
||
|
|
--card-radius: 12px;
|
||
|
|
--transition: all 0.2s ease;
|
||
|
|
}
|
||
|
|
|
||
|
|
* {
|
||
|
|
box-sizing: border-box;
|
||
|
|
margin: 0;
|
||
|
|
padding: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
body {
|
||
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||
|
|
background-color: var(--bg-primary);
|
||
|
|
color: var(--text-main);
|
||
|
|
line-height: 1.5;
|
||
|
|
padding: 24px;
|
||
|
|
min-height: 100vh;
|
||
|
|
}
|
||
|
|
|
||
|
|
.container {
|
||
|
|
max-width: 1280px;
|
||
|
|
margin: 0 auto;
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
gap: 24px;
|
||
|
|
}
|
||
|
|
|
||
|
|
header {
|
||
|
|
display: flex;
|
||
|
|
justify-content: space-between;
|
||
|
|
align-items: center;
|
||
|
|
border-bottom: 1px solid var(--border-color);
|
||
|
|
padding-bottom: 16px;
|
||
|
|
flex-wrap: wrap;
|
||
|
|
gap: 12px;
|
||
|
|
}
|
||
|
|
|
||
|
|
header h1 {
|
||
|
|
font-size: 1.75rem;
|
||
|
|
font-weight: 700;
|
||
|
|
letter-spacing: -0.025em;
|
||
|
|
color: var(--text-main);
|
||
|
|
}
|
||
|
|
|
||
|
|
header p {
|
||
|
|
color: var(--text-muted);
|
||
|
|
font-size: 0.9rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.header-actions {
|
||
|
|
display: flex;
|
||
|
|
gap: 8px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.main-grid {
|
||
|
|
display: grid;
|
||
|
|
grid-template-columns: 1fr;
|
||
|
|
gap: 24px;
|
||
|
|
}
|
||
|
|
|
||
|
|
@media (min-width: 992px) {
|
||
|
|
.main-grid {
|
||
|
|
grid-template-columns: 480px 1fr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
.card {
|
||
|
|
background-color: var(--bg-secondary);
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
border-radius: var(--card-radius);
|
||
|
|
padding: 20px;
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
gap: 16px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.card-title {
|
||
|
|
font-size: 1.15rem;
|
||
|
|
font-weight: 600;
|
||
|
|
display: flex;
|
||
|
|
justify-content: space-between;
|
||
|
|
align-items: center;
|
||
|
|
color: var(--text-main);
|
||
|
|
border-bottom: 1px solid var(--border-color);
|
||
|
|
padding-bottom: 10px;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Knoppen & inputs */
|
||
|
|
button {
|
||
|
|
font-family: inherit;
|
||
|
|
cursor: pointer;
|
||
|
|
display: inline-flex;
|
||
|
|
align-items: center;
|
||
|
|
justify-content: center;
|
||
|
|
gap: 6px;
|
||
|
|
font-weight: 600;
|
||
|
|
border-radius: 6px;
|
||
|
|
border: none;
|
||
|
|
transition: var(--transition);
|
||
|
|
padding: 8px 14px;
|
||
|
|
font-size: 0.875rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
button:disabled {
|
||
|
|
opacity: 0.4;
|
||
|
|
cursor: not-allowed;
|
||
|
|
}
|
||
|
|
|
||
|
|
.btn-primary {
|
||
|
|
background-color: var(--accent);
|
||
|
|
color: #0f172a;
|
||
|
|
}
|
||
|
|
.btn-primary:hover:not(:disabled) {
|
||
|
|
background-color: var(--accent-hover);
|
||
|
|
color: #ffffff;
|
||
|
|
}
|
||
|
|
|
||
|
|
.btn-secondary {
|
||
|
|
background-color: var(--bg-tertiary);
|
||
|
|
color: var(--text-main);
|
||
|
|
}
|
||
|
|
.btn-secondary:hover:not(:disabled) {
|
||
|
|
background-color: #475569;
|
||
|
|
}
|
||
|
|
|
||
|
|
.btn-success {
|
||
|
|
background-color: var(--success);
|
||
|
|
color: #ffffff;
|
||
|
|
}
|
||
|
|
.btn-success:hover:not(:disabled) {
|
||
|
|
background-color: var(--success-hover);
|
||
|
|
}
|
||
|
|
|
||
|
|
.btn-danger {
|
||
|
|
background-color: transparent;
|
||
|
|
color: var(--danger);
|
||
|
|
border: 1px solid var(--danger);
|
||
|
|
padding: 4px 8px;
|
||
|
|
}
|
||
|
|
.btn-danger:hover:not(:disabled) {
|
||
|
|
background-color: var(--danger);
|
||
|
|
color: #ffffff;
|
||
|
|
}
|
||
|
|
|
||
|
|
.btn-sm {
|
||
|
|
padding: 4px 8px;
|
||
|
|
font-size: 0.75rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.btn-spin {
|
||
|
|
width: 100%;
|
||
|
|
padding: 16px;
|
||
|
|
font-size: 1.2rem;
|
||
|
|
background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
|
||
|
|
color: #ffffff;
|
||
|
|
border-radius: 8px;
|
||
|
|
box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4);
|
||
|
|
letter-spacing: 0.02em;
|
||
|
|
}
|
||
|
|
.btn-spin:hover:not(:disabled) {
|
||
|
|
background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
|
||
|
|
box-shadow: 0 6px 20px rgba(2, 132, 199, 0.6);
|
||
|
|
}
|
||
|
|
|
||
|
|
input[type="text"] {
|
||
|
|
font-family: inherit;
|
||
|
|
background-color: var(--bg-primary);
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
color: var(--text-main);
|
||
|
|
padding: 8px 12px;
|
||
|
|
border-radius: 6px;
|
||
|
|
font-size: 0.875rem;
|
||
|
|
outline: none;
|
||
|
|
transition: var(--transition);
|
||
|
|
}
|
||
|
|
|
||
|
|
input[type="text"]:focus {
|
||
|
|
border-color: var(--accent);
|
||
|
|
box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Roulettewiel container */
|
||
|
|
.wheel-wrapper {
|
||
|
|
position: relative;
|
||
|
|
width: 100%;
|
||
|
|
max-width: 440px;
|
||
|
|
aspect-ratio: 1 / 1;
|
||
|
|
margin: 0 auto;
|
||
|
|
display: flex;
|
||
|
|
justify-content: center;
|
||
|
|
align-items: center;
|
||
|
|
}
|
||
|
|
|
||
|
|
canvas {
|
||
|
|
width: 100%;
|
||
|
|
height: 100%;
|
||
|
|
display: block;
|
||
|
|
border-radius: 50%;
|
||
|
|
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
|
||
|
|
}
|
||
|
|
|
||
|
|
.wheel-pointer {
|
||
|
|
position: absolute;
|
||
|
|
top: -12px;
|
||
|
|
left: 50%;
|
||
|
|
transform: translateX(-50%);
|
||
|
|
width: 0;
|
||
|
|
height: 0;
|
||
|
|
border-left: 14px solid transparent;
|
||
|
|
border-right: 14px solid transparent;
|
||
|
|
border-top: 24px solid #f43f5e;
|
||
|
|
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
|
||
|
|
z-index: 10;
|
||
|
|
pointer-events: none;
|
||
|
|
}
|
||
|
|
|
||
|
|
.wheel-hub {
|
||
|
|
position: absolute;
|
||
|
|
top: 50%;
|
||
|
|
left: 50%;
|
||
|
|
transform: translate(-50%, -50%);
|
||
|
|
width: 50px;
|
||
|
|
height: 50px;
|
||
|
|
background: radial-gradient(circle, #334155 0%, #0f172a 100%);
|
||
|
|
border: 3px solid var(--accent);
|
||
|
|
border-radius: 50%;
|
||
|
|
z-index: 5;
|
||
|
|
pointer-events: none;
|
||
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.6);
|
||
|
|
}
|
||
|
|
|
||
|
|
.algorithm-info {
|
||
|
|
font-size: 0.8rem;
|
||
|
|
color: var(--text-muted);
|
||
|
|
background-color: rgba(15, 23, 42, 0.6);
|
||
|
|
padding: 10px 12px;
|
||
|
|
border-radius: 6px;
|
||
|
|
border-left: 3px solid var(--accent);
|
||
|
|
line-height: 1.4;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Formulier nieuw lid */
|
||
|
|
.add-form {
|
||
|
|
display: grid;
|
||
|
|
grid-template-columns: 1fr 1fr auto;
|
||
|
|
gap: 10px;
|
||
|
|
background-color: var(--bg-primary);
|
||
|
|
padding: 12px;
|
||
|
|
border-radius: 8px;
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
}
|
||
|
|
|
||
|
|
@media (max-width: 600px) {
|
||
|
|
.add-form {
|
||
|
|
grid-template-columns: 1fr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Deelnemerstabel */
|
||
|
|
.table-controls {
|
||
|
|
display: flex;
|
||
|
|
justify-content: space-between;
|
||
|
|
align-items: center;
|
||
|
|
flex-wrap: wrap;
|
||
|
|
gap: 8px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.table-container {
|
||
|
|
overflow-x: auto;
|
||
|
|
}
|
||
|
|
|
||
|
|
table {
|
||
|
|
width: 100%;
|
||
|
|
border-collapse: collapse;
|
||
|
|
font-size: 0.875rem;
|
||
|
|
text-align: left;
|
||
|
|
}
|
||
|
|
|
||
|
|
th {
|
||
|
|
background-color: var(--bg-tertiary);
|
||
|
|
color: var(--text-muted);
|
||
|
|
font-weight: 600;
|
||
|
|
padding: 10px 12px;
|
||
|
|
font-size: 0.75rem;
|
||
|
|
text-transform: uppercase;
|
||
|
|
letter-spacing: 0.05em;
|
||
|
|
}
|
||
|
|
|
||
|
|
td {
|
||
|
|
padding: 10px 12px;
|
||
|
|
border-bottom: 1px solid var(--border-color);
|
||
|
|
vertical-align: middle;
|
||
|
|
}
|
||
|
|
|
||
|
|
tr:hover td {
|
||
|
|
background-color: rgba(51, 65, 85, 0.25);
|
||
|
|
}
|
||
|
|
|
||
|
|
.cell-checkbox {
|
||
|
|
width: 40px;
|
||
|
|
text-align: center;
|
||
|
|
}
|
||
|
|
|
||
|
|
input[type="checkbox"] {
|
||
|
|
width: 16px;
|
||
|
|
height: 16px;
|
||
|
|
cursor: pointer;
|
||
|
|
accent-color: var(--accent);
|
||
|
|
}
|
||
|
|
|
||
|
|
.badge {
|
||
|
|
display: inline-block;
|
||
|
|
padding: 2px 6px;
|
||
|
|
font-size: 0.75rem;
|
||
|
|
font-weight: 600;
|
||
|
|
border-radius: 4px;
|
||
|
|
background-color: var(--bg-tertiary);
|
||
|
|
color: var(--text-main);
|
||
|
|
}
|
||
|
|
|
||
|
|
.badge-protected {
|
||
|
|
background-color: #854d0e;
|
||
|
|
color: #fef08a;
|
||
|
|
}
|
||
|
|
|
||
|
|
.counter-group {
|
||
|
|
display: inline-flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 4px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.counter-btn {
|
||
|
|
width: 22px;
|
||
|
|
height: 22px;
|
||
|
|
padding: 0;
|
||
|
|
background-color: var(--bg-tertiary);
|
||
|
|
color: var(--text-main);
|
||
|
|
font-size: 0.75rem;
|
||
|
|
border-radius: 4px;
|
||
|
|
line-height: 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
.counter-val {
|
||
|
|
min-width: 20px;
|
||
|
|
text-align: center;
|
||
|
|
font-weight: 600;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Modal / Resultaat Overlay */
|
||
|
|
.modal-backdrop {
|
||
|
|
position: fixed;
|
||
|
|
inset: 0;
|
||
|
|
background-color: rgba(15, 23, 42, 0.85);
|
||
|
|
backdrop-filter: blur(4px);
|
||
|
|
display: none;
|
||
|
|
justify-content: center;
|
||
|
|
align-items: center;
|
||
|
|
padding: 20px;
|
||
|
|
z-index: 100;
|
||
|
|
}
|
||
|
|
|
||
|
|
.modal-backdrop.active {
|
||
|
|
display: flex;
|
||
|
|
}
|
||
|
|
|
||
|
|
.modal-window {
|
||
|
|
background-color: var(--bg-secondary);
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
border-radius: var(--card-radius);
|
||
|
|
width: 100%;
|
||
|
|
max-width: 580px;
|
||
|
|
padding: 24px;
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
gap: 18px;
|
||
|
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
|
||
|
|
max-height: 90vh;
|
||
|
|
overflow-y: auto;
|
||
|
|
}
|
||
|
|
|
||
|
|
.modal-header {
|
||
|
|
border-bottom: 1px solid var(--border-color);
|
||
|
|
padding-bottom: 12px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.modal-header h2 {
|
||
|
|
font-size: 1.4rem;
|
||
|
|
color: var(--text-main);
|
||
|
|
}
|
||
|
|
|
||
|
|
.modal-header .sub {
|
||
|
|
color: var(--text-muted);
|
||
|
|
font-size: 0.875rem;
|
||
|
|
margin-top: 4px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.winner-highlight {
|
||
|
|
background-color: rgba(56, 189, 248, 0.1);
|
||
|
|
border: 1px solid var(--accent);
|
||
|
|
border-radius: 8px;
|
||
|
|
padding: 16px;
|
||
|
|
text-align: center;
|
||
|
|
}
|
||
|
|
|
||
|
|
.winner-name {
|
||
|
|
font-size: 1.8rem;
|
||
|
|
font-weight: 700;
|
||
|
|
color: var(--accent);
|
||
|
|
margin: 4px 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.winner-task {
|
||
|
|
font-size: 0.95rem;
|
||
|
|
color: var(--text-main);
|
||
|
|
font-weight: 500;
|
||
|
|
}
|
||
|
|
|
||
|
|
.order-box {
|
||
|
|
background-color: var(--bg-primary);
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
border-radius: 8px;
|
||
|
|
padding: 14px;
|
||
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||
|
|
font-size: 0.85rem;
|
||
|
|
color: #e2e8f0;
|
||
|
|
white-space: pre-wrap;
|
||
|
|
line-height: 1.5;
|
||
|
|
}
|
||
|
|
|
||
|
|
.modal-actions {
|
||
|
|
display: flex;
|
||
|
|
justify-content: flex-end;
|
||
|
|
gap: 10px;
|
||
|
|
flex-wrap: wrap;
|
||
|
|
}
|
||
|
|
|
||
|
|
.sound-toggle {
|
||
|
|
background-color: transparent;
|
||
|
|
color: var(--text-muted);
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
padding: 6px 10px;
|
||
|
|
}
|
||
|
|
.sound-toggle.active {
|
||
|
|
color: var(--accent);
|
||
|
|
border-color: var(--accent);
|
||
|
|
}
|
||
|
|
|
||
|
|
.empty-state {
|
||
|
|
text-align: center;
|
||
|
|
padding: 24px;
|
||
|
|
color: var(--text-muted);
|
||
|
|
font-size: 0.9rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.toast {
|
||
|
|
position: fixed;
|
||
|
|
bottom: 24px;
|
||
|
|
right: 24px;
|
||
|
|
background-color: var(--success);
|
||
|
|
color: #ffffff;
|
||
|
|
padding: 10px 16px;
|
||
|
|
border-radius: 6px;
|
||
|
|
font-size: 0.875rem;
|
||
|
|
font-weight: 600;
|
||
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||
|
|
display: none;
|
||
|
|
z-index: 200;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
|
||
|
|
<div class="container">
|
||
|
|
<header>
|
||
|
|
<div>
|
||
|
|
<h1>Koffie Roulette</h1>
|
||
|
|
<p>Eerlijk gewogen roulettesysteem voor de docentenkamer — Zonder toevalsoneerlijkheid</p>
|
||
|
|
</div>
|
||
|
|
<div class="header-actions">
|
||
|
|
<button id="soundToggleBtn" class="sound-toggle active" title="Geluidssignaal aan of uit">
|
||
|
|
Geluid: Aan
|
||
|
|
</button>
|
||
|
|
<button id="exportBtn" class="btn-secondary btn-sm" title="Exporteer gegevens als JSON">
|
||
|
|
Exporteer
|
||
|
|
</button>
|
||
|
|
<button id="importBtn" class="btn-secondary btn-sm" title="Importeer gegevens uit JSON">
|
||
|
|
Importeer
|
||
|
|
</button>
|
||
|
|
<button id="resetStatsBtn" class="btn-secondary btn-sm" title="Zet alle tellers terug naar nul">
|
||
|
|
Reset Tellers
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</header>
|
||
|
|
|
||
|
|
<div class="main-grid">
|
||
|
|
<!-- Linkerkolom: Roulettewiel & Besturing -->
|
||
|
|
<section class="card">
|
||
|
|
<div class="card-title">
|
||
|
|
<span>Roulettewiel</span>
|
||
|
|
<span id="activeCountBadge" class="badge">0 actief</span>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="wheel-wrapper">
|
||
|
|
<div class="wheel-pointer"></div>
|
||
|
|
<canvas id="wheelCanvas" width="800" height="800"></canvas>
|
||
|
|
<div class="wheel-hub"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<button id="spinBtn" class="btn-spin" disabled>
|
||
|
|
Draai aan het rad
|
||
|
|
</button>
|
||
|
|
|
||
|
|
<div class="algorithm-info">
|
||
|
|
<strong>Hoe de weging werkt:</strong><br>
|
||
|
|
Collega's met de hoogste koffieschuld (vaak meegedronken, weinig gehaald) hebben een groter vak op het rad.
|
||
|
|
Degene die de vorige ronde heeft gehaald, is automatisch beschermd (0% kans) voor de eerstvolgende ronde.
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
|
||
|
|
<!-- Rechterkolom: Deelnemersbeheer & Voorkeuren -->
|
||
|
|
<section class="card">
|
||
|
|
<div class="card-title">
|
||
|
|
<span>Deelnemers & Koffievoorkeuren</span>
|
||
|
|
<div class="table-controls">
|
||
|
|
<button id="selectAllBtn" class="btn-secondary btn-sm">Alles aan</button>
|
||
|
|
<button id="deselectAllBtn" class="btn-secondary btn-sm">Alles uit</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Formulier: Nieuwe collega toevoegen -->
|
||
|
|
<form id="addPersonForm" class="add-form">
|
||
|
|
<input type="text" id="newNameInput" placeholder="Naam collega" required>
|
||
|
|
<input type="text" id="newPrefInput" placeholder="Koffievoorkeur (bijv. Cappuccino)" required>
|
||
|
|
<button type="submit" class="btn-primary">Toevoegen</button>
|
||
|
|
</form>
|
||
|
|
|
||
|
|
<!-- Tabel met deelnemers -->
|
||
|
|
<div class="table-container">
|
||
|
|
<table>
|
||
|
|
<thead>
|
||
|
|
<tr>
|
||
|
|
<th class="cell-checkbox">Mee</th>
|
||
|
|
<th>Naam</th>
|
||
|
|
<th>Voorkeur</th>
|
||
|
|
<th title="Aantal rondes meegedronken">Gedronken</th>
|
||
|
|
<th title="Aantal keren koffie gehaald">Gehaald</th>
|
||
|
|
<th title="Berekende kans op basis van koffieschuld">Kans</th>
|
||
|
|
<th>Acties</th>
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
<tbody id="colleaguesTableBody">
|
||
|
|
<!-- Dynamisch gevuld -->
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
<div id="emptyTableMessage" class="empty-state" style="display: none;">
|
||
|
|
Nog geen collega's toegevoegd. Gebruik het bovenstaande formulier.
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Resultaat & Besteloverzicht Modal -->
|
||
|
|
<div id="resultModal" class="modal-backdrop">
|
||
|
|
<div class="modal-window">
|
||
|
|
<div class="modal-header">
|
||
|
|
<h2>Ronde Afgerond</h2>
|
||
|
|
<div class="sub">Het rad heeft gesproken. Controleer hieronder de bestelling.</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="winner-highlight">
|
||
|
|
<div class="winner-task">De beurt is aan:</div>
|
||
|
|
<div id="modalWinnerName" class="winner-name">...</div>
|
||
|
|
<div class="winner-task">om koffie te halen voor de aanwezigen!</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div>
|
||
|
|
<label style="font-weight: 600; font-size: 0.85rem; display: block; margin-bottom: 6px; color: var(--text-muted);">
|
||
|
|
Besteloverzicht voor de bar / automaat:
|
||
|
|
</label>
|
||
|
|
<div id="modalOrderSummary" class="order-box"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="modal-actions">
|
||
|
|
<button id="copyOrderBtn" class="btn-secondary">
|
||
|
|
Kopieer Bestelling
|
||
|
|
</button>
|
||
|
|
<button id="respinBtn" class="btn-secondary">
|
||
|
|
Opnieuw Draaien
|
||
|
|
</button>
|
||
|
|
<button id="confirmRoundBtn" class="btn-success">
|
||
|
|
Bevestig & Update Stand
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Verborgen file input voor JSON import -->
|
||
|
|
<input type="file" id="importFileInput" accept=".json" style="display: none;">
|
||
|
|
|
||
|
|
<!-- Melding / Toast -->
|
||
|
|
<div id="toastMessage" class="toast">Bestellijst gekopieerd naar klembord</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
// Applicatie State
|
||
|
|
const STORAGE_KEY = 'koffie_roulette_data_v1';
|
||
|
|
|
||
|
|
// Standaard startset met herkenbare Scalda voorbeelden als er nog geen data is
|
||
|
|
const DEFAULT_COLLEAGUES = [
|
||
|
|
{ id: '1', name: 'Steef', preference: 'Zwarte koffie (groot)', drank: 6, gehaald: 2, active: true },
|
||
|
|
{ id: '2', name: 'Mark', preference: 'Cappuccino met havermelk', drank: 5, gehaald: 1, active: true },
|
||
|
|
{ id: '3', name: 'Anouk', preference: 'Dubbele Espresso', drank: 6, gehaald: 0, active: true },
|
||
|
|
{ id: '4', name: 'Dennis', preference: 'Zwarte koffie met melk', drank: 4, gehaald: 2, active: true },
|
||
|
|
{ id: '5', name: 'Lisa', preference: 'Thee (Earl Grey)', drank: 5, gehaald: 1, active: true }
|
||
|
|
];
|
||
|
|
|
||
|
|
let state = {
|
||
|
|
colleagues: [],
|
||
|
|
lastWinnerId: null,
|
||
|
|
soundEnabled: true
|
||
|
|
};
|
||
|
|
|
||
|
|
// Kleurenpalet voor de taartpunten (duidelijk contrast, professioneel)
|
||
|
|
const SLICE_COLORS = [
|
||
|
|
'#0284c7', '#0d9488', '#d97706', '#4f46e5',
|
||
|
|
'#e11d48', '#059669', '#ca8a04', '#7c3aed',
|
||
|
|
'#2563eb', '#16a34a', '#ea580c', '#9333ea'
|
||
|
|
];
|
||
|
|
|
||
|
|
// Geluidseffect met Web Audio API (zuivere tik zonder audiobestanden)
|
||
|
|
let audioCtx = null;
|
||
|
|
function playTickSound() {
|
||
|
|
if (!state.soundEnabled) return;
|
||
|
|
try {
|
||
|
|
if (!audioCtx) {
|
||
|
|
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||
|
|
}
|
||
|
|
if (audioCtx.state === 'suspended') {
|
||
|
|
audioCtx.resume();
|
||
|
|
}
|
||
|
|
const osc = audioCtx.createOscillator();
|
||
|
|
const gain = audioCtx.createGain();
|
||
|
|
osc.type = 'triangle';
|
||
|
|
osc.frequency.setValueAtTime(580, audioCtx.currentTime);
|
||
|
|
osc.frequency.exponentialRampToValueAtTime(140, audioCtx.currentTime + 0.04);
|
||
|
|
gain.gain.setValueAtTime(0.12, audioCtx.currentTime);
|
||
|
|
gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + 0.04);
|
||
|
|
osc.connect(gain);
|
||
|
|
gain.connect(audioCtx.destination);
|
||
|
|
osc.start();
|
||
|
|
osc.stop(audioCtx.currentTime + 0.04);
|
||
|
|
} catch (e) {
|
||
|
|
// Audio mogelijk geblokkeerd door browser autoplay restrictie
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function playWinSound() {
|
||
|
|
if (!state.soundEnabled) return;
|
||
|
|
try {
|
||
|
|
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||
|
|
const now = audioCtx.currentTime;
|
||
|
|
const freqs = [330, 440, 660];
|
||
|
|
freqs.forEach((freq, idx) => {
|
||
|
|
const osc = audioCtx.createOscillator();
|
||
|
|
const gain = audioCtx.createGain();
|
||
|
|
osc.type = 'sine';
|
||
|
|
osc.frequency.setValueAtTime(freq, now + idx * 0.1);
|
||
|
|
gain.gain.setValueAtTime(0.15, now + idx * 0.1);
|
||
|
|
gain.gain.exponentialRampToValueAtTime(0.001, now + idx * 0.1 + 0.25);
|
||
|
|
osc.connect(gain);
|
||
|
|
gain.connect(audioCtx.destination);
|
||
|
|
osc.start(now + idx * 0.1);
|
||
|
|
osc.stop(now + idx * 0.1 + 0.25);
|
||
|
|
});
|
||
|
|
} catch (e) {}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Canvas & Animatie Variabelen
|
||
|
|
const canvas = document.getElementById('wheelCanvas');
|
||
|
|
const ctx = canvas.getContext('2d');
|
||
|
|
let currentAngle = 0; // radialen
|
||
|
|
let isSpinning = false;
|
||
|
|
let pendingWinner = null;
|
||
|
|
let lastTickedSliceIndex = -1;
|
||
|
|
|
||
|
|
// Initialisatie
|
||
|
|
function init() {
|
||
|
|
loadData();
|
||
|
|
setupEventListeners();
|
||
|
|
renderAll();
|
||
|
|
}
|
||
|
|
|
||
|
|
function loadData() {
|
||
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
||
|
|
if (stored) {
|
||
|
|
try {
|
||
|
|
const parsed = JSON.parse(stored);
|
||
|
|
state.colleagues = parsed.colleagues || [];
|
||
|
|
state.lastWinnerId = parsed.lastWinnerId || null;
|
||
|
|
state.soundEnabled = parsed.soundEnabled !== false;
|
||
|
|
} catch (e) {
|
||
|
|
state.colleagues = [...DEFAULT_COLLEAGUES];
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
state.colleagues = [...DEFAULT_COLLEAGUES];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function saveData() {
|
||
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Bereken gewichten en kansen
|
||
|
|
function getCalculatedParticipants() {
|
||
|
|
const activeList = state.colleagues.filter(c => c.active);
|
||
|
|
if (activeList.length === 0) return [];
|
||
|
|
|
||
|
|
const canProtectLastWinner = activeList.length > 1 && state.lastWinnerId !== null;
|
||
|
|
|
||
|
|
// Bereken individueel gewicht Wi
|
||
|
|
const withWeights = activeList.map(c => {
|
||
|
|
const isProtected = canProtectLastWinner && c.id === state.lastWinnerId;
|
||
|
|
let weight = 0;
|
||
|
|
if (!isProtected) {
|
||
|
|
// Relatieve schuld: (drank + 1) / (gehaald + 1)
|
||
|
|
const ratio = (Number(c.drank) + 1) / (Number(c.gehaald) + 1);
|
||
|
|
weight = Math.max(1, Math.round(ratio * 10));
|
||
|
|
}
|
||
|
|
return {
|
||
|
|
...c,
|
||
|
|
isProtected,
|
||
|
|
weight
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
const totalWeight = withWeights.reduce((sum, item) => sum + item.weight, 0);
|
||
|
|
|
||
|
|
return withWeights.map(c => {
|
||
|
|
const percentage = totalWeight > 0 ? (c.weight / totalWeight) * 100 : 0;
|
||
|
|
return {
|
||
|
|
...c,
|
||
|
|
percentage
|
||
|
|
};
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Teken het roulettewiel
|
||
|
|
function drawWheel() {
|
||
|
|
const width = canvas.width;
|
||
|
|
const height = canvas.height;
|
||
|
|
const centerX = width / 2;
|
||
|
|
const centerY = height / 2;
|
||
|
|
const radius = width / 2 - 20;
|
||
|
|
|
||
|
|
ctx.clearRect(0, 0, width, height);
|
||
|
|
|
||
|
|
const participants = getCalculatedParticipants().filter(p => p.weight > 0);
|
||
|
|
|
||
|
|
if (participants.length === 0) {
|
||
|
|
// Lege toestand
|
||
|
|
ctx.save();
|
||
|
|
ctx.beginPath();
|
||
|
|
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
|
||
|
|
ctx.fillStyle = '#1e293b';
|
||
|
|
ctx.fill();
|
||
|
|
ctx.strokeStyle = '#334155';
|
||
|
|
ctx.lineWidth = 4;
|
||
|
|
ctx.stroke();
|
||
|
|
|
||
|
|
ctx.fillStyle = '#94a3b8';
|
||
|
|
ctx.font = 'bold 24px -apple-system, sans-serif';
|
||
|
|
ctx.textAlign = 'center';
|
||
|
|
ctx.textBaseline = 'middle';
|
||
|
|
ctx.fillText('Selecteer minimaal 1 actieve collega', centerX, centerY);
|
||
|
|
ctx.restore();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const totalWeight = participants.reduce((sum, p) => sum + p.weight, 0);
|
||
|
|
let startAngle = currentAngle;
|
||
|
|
|
||
|
|
participants.forEach((p, idx) => {
|
||
|
|
const sliceAngle = (p.weight / totalWeight) * (2 * Math.PI);
|
||
|
|
const endAngle = startAngle + sliceAngle;
|
||
|
|
const color = SLICE_COLORS[idx % SLICE_COLORS.length];
|
||
|
|
|
||
|
|
// Taartpunt tekenen
|
||
|
|
ctx.beginPath();
|
||
|
|
ctx.moveTo(centerX, centerY);
|
||
|
|
ctx.arc(centerX, centerY, radius, startAngle, endAngle);
|
||
|
|
ctx.closePath();
|
||
|
|
ctx.fillStyle = color;
|
||
|
|
ctx.fill();
|
||
|
|
|
||
|
|
ctx.strokeStyle = '#0f172a';
|
||
|
|
ctx.lineWidth = 3;
|
||
|
|
ctx.stroke();
|
||
|
|
|
||
|
|
// Tekstlabel tekenen
|
||
|
|
ctx.save();
|
||
|
|
ctx.translate(centerX, centerY);
|
||
|
|
const textAngle = startAngle + sliceAngle / 2;
|
||
|
|
ctx.rotate(textAngle);
|
||
|
|
|
||
|
|
ctx.textAlign = 'right';
|
||
|
|
ctx.fillStyle = '#ffffff';
|
||
|
|
ctx.shadowColor = 'rgba(0,0,0,0.6)';
|
||
|
|
ctx.shadowBlur = 4;
|
||
|
|
|
||
|
|
// Pas lettergrootte aan op basis van het aantal graden
|
||
|
|
const arcDegrees = (sliceAngle / (2 * Math.PI)) * 360;
|
||
|
|
let fontSize = 22;
|
||
|
|
if (arcDegrees < 20) fontSize = 16;
|
||
|
|
if (arcDegrees < 12) fontSize = 13;
|
||
|
|
|
||
|
|
ctx.font = `bold ${fontSize}px -apple-system, sans-serif`;
|
||
|
|
const label = `${p.name} (${Math.round(p.percentage)}%)`;
|
||
|
|
ctx.fillText(label, radius - 30, fontSize / 3);
|
||
|
|
|
||
|
|
ctx.restore();
|
||
|
|
|
||
|
|
startAngle = endAngle;
|
||
|
|
});
|
||
|
|
|
||
|
|
// Buitenste sierrand
|
||
|
|
ctx.beginPath();
|
||
|
|
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
|
||
|
|
ctx.strokeStyle = '#334155';
|
||
|
|
ctx.lineWidth = 8;
|
||
|
|
ctx.stroke();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Bepaal de winnaar op basis van de huidige hoek (bovenzijde = -PI/2)
|
||
|
|
function determineWinnerFromAngle(angle) {
|
||
|
|
const participants = getCalculatedParticipants().filter(p => p.weight > 0);
|
||
|
|
if (participants.length === 0) return null;
|
||
|
|
|
||
|
|
const totalWeight = participants.reduce((sum, p) => sum + p.weight, 0);
|
||
|
|
|
||
|
|
// De pijl wijst naar boven: hoek = 3*PI/2 (of -PI/2)
|
||
|
|
const pointerAngle = (1.5 * Math.PI);
|
||
|
|
|
||
|
|
// Bereken relatieve hoek binnen de cirkel [0, 2*PI)
|
||
|
|
let normalized = (pointerAngle - (angle % (2 * Math.PI))) % (2 * Math.PI);
|
||
|
|
if (normalized < 0) normalized += 2 * Math.PI;
|
||
|
|
|
||
|
|
let accumulatedAngle = 0;
|
||
|
|
for (let i = 0; i < participants.length; i++) {
|
||
|
|
const sliceAngle = (participants[i].weight / totalWeight) * (2 * Math.PI);
|
||
|
|
if (normalized >= accumulatedAngle && normalized < accumulatedAngle + sliceAngle) {
|
||
|
|
return { participant: participants[i], index: i };
|
||
|
|
}
|
||
|
|
accumulatedAngle += sliceAngle;
|
||
|
|
}
|
||
|
|
return { participant: participants[participants.length - 1], index: participants.length - 1 };
|
||
|
|
}
|
||
|
|
|
||
|
|
// Draai-animatie
|
||
|
|
function spinWheel() {
|
||
|
|
if (isSpinning) return;
|
||
|
|
const participants = getCalculatedParticipants().filter(p => p.weight > 0);
|
||
|
|
if (participants.length === 0) return;
|
||
|
|
|
||
|
|
isSpinning = true;
|
||
|
|
document.getElementById('spinBtn').disabled = true;
|
||
|
|
lastTickedSliceIndex = -1;
|
||
|
|
|
||
|
|
// Bepaal totale draaiafstand: minimaal 5 volledige rondes + willekeurig surplus
|
||
|
|
const minRotations = 5;
|
||
|
|
const randomExtra = Math.random() * (2 * Math.PI);
|
||
|
|
const targetRotation = currentAngle + (minRotations * 2 * Math.PI) + randomExtra;
|
||
|
|
|
||
|
|
const startTime = performance.now();
|
||
|
|
const duration = 4500; // 4.5 seconden voor spanning
|
||
|
|
const initialAngle = currentAngle;
|
||
|
|
|
||
|
|
// Easing functie: sterke afremming (cubic ease out)
|
||
|
|
function easeOutCubic(t) {
|
||
|
|
return (--t) * t * t + 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
function animate(time) {
|
||
|
|
const elapsed = time - startTime;
|
||
|
|
const progress = Math.min(elapsed / duration, 1);
|
||
|
|
const easedProgress = easeOutCubic(progress);
|
||
|
|
|
||
|
|
currentAngle = initialAngle + (targetRotation - initialAngle) * easedProgress;
|
||
|
|
|
||
|
|
// Detecteer passage van een segmentgrens voor tiktik-geluid
|
||
|
|
const currentResult = determineWinnerFromAngle(currentAngle);
|
||
|
|
if (currentResult && currentResult.index !== lastTickedSliceIndex) {
|
||
|
|
playTickSound();
|
||
|
|
lastTickedSliceIndex = currentResult.index;
|
||
|
|
}
|
||
|
|
|
||
|
|
drawWheel();
|
||
|
|
|
||
|
|
if (progress < 1) {
|
||
|
|
requestAnimationFrame(animate);
|
||
|
|
} else {
|
||
|
|
isSpinning = false;
|
||
|
|
const finalResult = determineWinnerFromAngle(currentAngle);
|
||
|
|
pendingWinner = finalResult.participant;
|
||
|
|
playWinSound();
|
||
|
|
showResultModal(pendingWinner);
|
||
|
|
updateSpinButtonState();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
requestAnimationFrame(animate);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Modal & Bestelling
|
||
|
|
function showResultModal(winner) {
|
||
|
|
document.getElementById('modalWinnerName').textContent = winner.name;
|
||
|
|
|
||
|
|
const activeList = state.colleagues.filter(c => c.active);
|
||
|
|
|
||
|
|
// Bestelling groeperen
|
||
|
|
const counts = {};
|
||
|
|
activeList.forEach(c => {
|
||
|
|
const item = (c.preference || 'Zwarte koffie').trim();
|
||
|
|
counts[item] = (counts[item] || 0) + 1;
|
||
|
|
});
|
||
|
|
|
||
|
|
let summaryText = `BESTELLIJST KOFFIE RONDJE\n`;
|
||
|
|
summaryText += `Haler: ${winner.name}\n`;
|
||
|
|
summaryText += `Totaal aantal consumpties: ${activeList.length}\n\n`;
|
||
|
|
summaryText += `VERZAMELLIJST (VOOR DE MACHINE / BAR):\n`;
|
||
|
|
|
||
|
|
for (const [bev, count] of Object.entries(counts)) {
|
||
|
|
summaryText += `- ${count}x ${bev}\n`;
|
||
|
|
}
|
||
|
|
|
||
|
|
summaryText += `\nSPECIFICATIE PER PERSOON:\n`;
|
||
|
|
activeList.forEach(c => {
|
||
|
|
summaryText += `- ${c.name}: ${c.preference || 'Standaard'}\n`;
|
||
|
|
});
|
||
|
|
|
||
|
|
document.getElementById('modalOrderSummary').textContent = summaryText;
|
||
|
|
document.getElementById('resultModal').classList.add('active');
|
||
|
|
}
|
||
|
|
|
||
|
|
function hideResultModal() {
|
||
|
|
document.getElementById('resultModal').classList.remove('active');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Klembord kopiëren
|
||
|
|
function copyOrderSummary() {
|
||
|
|
const text = document.getElementById('modalOrderSummary').textContent;
|
||
|
|
navigator.clipboard.writeText(text).then(() => {
|
||
|
|
showToast('Bestellijst gekopieerd naar klembord');
|
||
|
|
}).catch(() => {
|
||
|
|
showToast('Kopiëren mislukt');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function showToast(msg) {
|
||
|
|
const toast = document.getElementById('toastMessage');
|
||
|
|
toast.textContent = msg;
|
||
|
|
toast.style.display = 'block';
|
||
|
|
setTimeout(() => {
|
||
|
|
toast.style.display = 'none';
|
||
|
|
}, 2500);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Bevestig ronde
|
||
|
|
function confirmRound() {
|
||
|
|
if (!pendingWinner) return;
|
||
|
|
|
||
|
|
// Update tellers van alle actieve deelnemers
|
||
|
|
state.colleagues = state.colleagues.map(c => {
|
||
|
|
if (!c.active) return c;
|
||
|
|
const wasWinner = c.id === pendingWinner.id;
|
||
|
|
return {
|
||
|
|
...c,
|
||
|
|
drank: Number(c.drank) + 1,
|
||
|
|
gehaald: wasWinner ? Number(c.gehaald) + 1 : Number(c.gehaald)
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
// Stel bescherming in voor de volgende ronde
|
||
|
|
state.lastWinnerId = pendingWinner.id;
|
||
|
|
pendingWinner = null;
|
||
|
|
|
||
|
|
saveData();
|
||
|
|
hideResultModal();
|
||
|
|
renderAll();
|
||
|
|
showToast('Stand succesvol bijgewerkt');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Render functies
|
||
|
|
function renderTable() {
|
||
|
|
const tbody = document.getElementById('colleaguesTableBody');
|
||
|
|
const emptyMsg = document.getElementById('emptyTableMessage');
|
||
|
|
tbody.innerHTML = '';
|
||
|
|
|
||
|
|
if (state.colleagues.length === 0) {
|
||
|
|
emptyMsg.style.display = 'block';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
emptyMsg.style.display = 'none';
|
||
|
|
|
||
|
|
const calculated = getCalculatedParticipants();
|
||
|
|
const calcMap = new Map(calculated.map(p => [p.id, p]));
|
||
|
|
|
||
|
|
state.colleagues.forEach(colleague => {
|
||
|
|
const calcData = calcMap.get(colleague.id);
|
||
|
|
const tr = document.createElement('tr');
|
||
|
|
|
||
|
|
// Checkbox meedoen
|
||
|
|
const tdCheck = document.createElement('td');
|
||
|
|
tdCheck.className = 'cell-checkbox';
|
||
|
|
const checkbox = document.createElement('input');
|
||
|
|
checkbox.type = 'checkbox';
|
||
|
|
checkbox.checked = colleague.active;
|
||
|
|
checkbox.onchange = () => {
|
||
|
|
colleague.active = checkbox.checked;
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
};
|
||
|
|
tdCheck.appendChild(checkbox);
|
||
|
|
|
||
|
|
// Naam + evt beschermingsbadge
|
||
|
|
const tdName = document.createElement('td');
|
||
|
|
tdName.style.fontWeight = '600';
|
||
|
|
tdName.textContent = colleague.name + ' ';
|
||
|
|
if (calcData && calcData.isProtected) {
|
||
|
|
const badge = document.createElement('span');
|
||
|
|
badge.className = 'badge badge-protected';
|
||
|
|
badge.textContent = 'Beschermd (0%)';
|
||
|
|
badge.title = 'Heeft net gehaald en kan deze ronde niet worden gekozen';
|
||
|
|
tdName.appendChild(badge);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Voorkeur (klik om te bewerken)
|
||
|
|
const tdPref = document.createElement('td');
|
||
|
|
const prefSpan = document.createElement('span');
|
||
|
|
prefSpan.textContent = colleague.preference || 'Geen';
|
||
|
|
prefSpan.style.cursor = 'pointer';
|
||
|
|
prefSpan.title = 'Dubbelklik om voorkeur aan te passen';
|
||
|
|
prefSpan.ondblclick = () => {
|
||
|
|
const newPref = prompt(`Pas koffievoorkeur aan voor ${colleague.name}:`, colleague.preference);
|
||
|
|
if (newPref !== null && newPref.trim() !== '') {
|
||
|
|
colleague.preference = newPref.trim();
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
tdPref.appendChild(prefSpan);
|
||
|
|
|
||
|
|
// Gedronken teller
|
||
|
|
const tdDrank = document.createElement('td');
|
||
|
|
tdDrank.appendChild(createCounterElement(colleague.drank, (val) => {
|
||
|
|
colleague.drank = Math.max(0, val);
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
}));
|
||
|
|
|
||
|
|
// Gehaald teller
|
||
|
|
const tdGehaald = document.createElement('td');
|
||
|
|
tdGehaald.appendChild(createCounterElement(colleague.gehaald, (val) => {
|
||
|
|
colleague.gehaald = Math.max(0, val);
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
}));
|
||
|
|
|
||
|
|
// Berekende kans
|
||
|
|
const tdChance = document.createElement('td');
|
||
|
|
if (colleague.active && calcData) {
|
||
|
|
tdChance.textContent = `${Math.round(calcData.percentage)}%`;
|
||
|
|
tdChance.style.fontWeight = '600';
|
||
|
|
if (calcData.percentage > 40) {
|
||
|
|
tdChance.style.color = '#f87171'; // Hoog risico
|
||
|
|
} else if (calcData.percentage === 0) {
|
||
|
|
tdChance.style.color = '#fef08a';
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
tdChance.textContent = '-';
|
||
|
|
tdChance.style.color = 'var(--text-muted)';
|
||
|
|
}
|
||
|
|
|
||
|
|
// Acties (Verwijderen)
|
||
|
|
const tdActions = document.createElement('td');
|
||
|
|
const delBtn = document.createElement('button');
|
||
|
|
delBtn.className = 'btn-danger btn-sm';
|
||
|
|
delBtn.textContent = 'Verwijder';
|
||
|
|
delBtn.onclick = () => {
|
||
|
|
if (confirm(`Weet je zeker dat je ${colleague.name} wilt verwijderen?`)) {
|
||
|
|
state.colleagues = state.colleagues.filter(c => c.id !== colleague.id);
|
||
|
|
if (state.lastWinnerId === colleague.id) state.lastWinnerId = null;
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
tdActions.appendChild(delBtn);
|
||
|
|
|
||
|
|
tr.appendChild(tdCheck);
|
||
|
|
tr.appendChild(tdName);
|
||
|
|
tr.appendChild(tdPref);
|
||
|
|
tr.appendChild(tdDrank);
|
||
|
|
tr.appendChild(tdGehaald);
|
||
|
|
tr.appendChild(tdChance);
|
||
|
|
tr.appendChild(tdActions);
|
||
|
|
|
||
|
|
tbody.appendChild(tr);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function createCounterElement(initialVal, onChange) {
|
||
|
|
const group = document.createElement('div');
|
||
|
|
group.className = 'counter-group';
|
||
|
|
|
||
|
|
const minusBtn = document.createElement('button');
|
||
|
|
minusBtn.className = 'counter-btn';
|
||
|
|
minusBtn.textContent = '-';
|
||
|
|
minusBtn.type = 'button';
|
||
|
|
minusBtn.onclick = () => onChange(Number(initialVal) - 1);
|
||
|
|
|
||
|
|
const valSpan = document.createElement('span');
|
||
|
|
valSpan.className = 'counter-val';
|
||
|
|
valSpan.textContent = initialVal;
|
||
|
|
|
||
|
|
const plusBtn = document.createElement('button');
|
||
|
|
plusBtn.className = 'counter-btn';
|
||
|
|
plusBtn.textContent = '+';
|
||
|
|
plusBtn.type = 'button';
|
||
|
|
plusBtn.onclick = () => onChange(Number(initialVal) + 1);
|
||
|
|
|
||
|
|
group.appendChild(minusBtn);
|
||
|
|
group.appendChild(valSpan);
|
||
|
|
group.appendChild(plusBtn);
|
||
|
|
return group;
|
||
|
|
}
|
||
|
|
|
||
|
|
function updateSpinButtonState() {
|
||
|
|
const activeList = state.colleagues.filter(c => c.active);
|
||
|
|
const spinBtn = document.getElementById('spinBtn');
|
||
|
|
const badge = document.getElementById('activeCountBadge');
|
||
|
|
|
||
|
|
badge.textContent = `${activeList.length} actief`;
|
||
|
|
|
||
|
|
if (isSpinning) {
|
||
|
|
spinBtn.disabled = true;
|
||
|
|
spinBtn.textContent = 'Rad draait...';
|
||
|
|
} else if (activeList.length === 0) {
|
||
|
|
spinBtn.disabled = true;
|
||
|
|
spinBtn.textContent = 'Selecteer minimaal 1 collega';
|
||
|
|
} else {
|
||
|
|
spinBtn.disabled = false;
|
||
|
|
spinBtn.textContent = 'Draai aan het rad';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderAll() {
|
||
|
|
renderTable();
|
||
|
|
drawWheel();
|
||
|
|
updateSpinButtonState();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Event Listeners
|
||
|
|
function setupEventListeners() {
|
||
|
|
// Formulier nieuw lid
|
||
|
|
document.getElementById('addPersonForm').onsubmit = (e) => {
|
||
|
|
e.preventDefault();
|
||
|
|
const nameInput = document.getElementById('newNameInput');
|
||
|
|
const prefInput = document.getElementById('newPrefInput');
|
||
|
|
const name = nameInput.value.trim();
|
||
|
|
const pref = prefInput.value.trim();
|
||
|
|
|
||
|
|
if (name && pref) {
|
||
|
|
state.colleagues.push({
|
||
|
|
id: Date.now().toString(),
|
||
|
|
name,
|
||
|
|
preference: pref,
|
||
|
|
drank: 0,
|
||
|
|
gehaald: 0,
|
||
|
|
active: true
|
||
|
|
});
|
||
|
|
nameInput.value = '';
|
||
|
|
prefInput.value = '';
|
||
|
|
nameInput.focus();
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// Alles selecteren / deselecteren
|
||
|
|
document.getElementById('selectAllBtn').onclick = () => {
|
||
|
|
state.colleagues.forEach(c => c.active = true);
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
};
|
||
|
|
|
||
|
|
document.getElementById('deselectAllBtn').onclick = () => {
|
||
|
|
state.colleagues.forEach(c => c.active = false);
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
};
|
||
|
|
|
||
|
|
// Draaien knop
|
||
|
|
document.getElementById('spinBtn').onclick = spinWheel;
|
||
|
|
|
||
|
|
// Modal knoppen
|
||
|
|
document.getElementById('copyOrderBtn').onclick = copyOrderSummary;
|
||
|
|
document.getElementById('respinBtn').onclick = () => {
|
||
|
|
hideResultModal();
|
||
|
|
spinWheel();
|
||
|
|
};
|
||
|
|
document.getElementById('confirmRoundBtn').onclick = confirmRound;
|
||
|
|
|
||
|
|
// Geluid toggle
|
||
|
|
const soundBtn = document.getElementById('soundToggleBtn');
|
||
|
|
soundBtn.onclick = () => {
|
||
|
|
state.soundEnabled = !state.soundEnabled;
|
||
|
|
soundBtn.textContent = state.soundEnabled ? 'Geluid: Aan' : 'Geluid: Uit';
|
||
|
|
soundBtn.classList.toggle('active', state.soundEnabled);
|
||
|
|
saveData();
|
||
|
|
};
|
||
|
|
soundBtn.textContent = state.soundEnabled ? 'Geluid: Aan' : 'Geluid: Uit';
|
||
|
|
soundBtn.classList.toggle('active', state.soundEnabled);
|
||
|
|
|
||
|
|
// Reset tellers
|
||
|
|
document.getElementById('resetStatsBtn').onclick = () => {
|
||
|
|
if (confirm('Weet je zeker dat je alle drank- en haaltellers wilt resetten naar 0? Namen en voorkeuren blijven bewaard.')) {
|
||
|
|
state.colleagues.forEach(c => {
|
||
|
|
c.drank = 0;
|
||
|
|
c.gehaald = 0;
|
||
|
|
});
|
||
|
|
state.lastWinnerId = null;
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
showToast('Tellers gereset naar 0');
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// Export JSON
|
||
|
|
document.getElementById('exportBtn').onclick = () => {
|
||
|
|
const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(state, null, 2));
|
||
|
|
const downloadAnchor = document.createElement('a');
|
||
|
|
downloadAnchor.setAttribute('href', dataStr);
|
||
|
|
downloadAnchor.setAttribute('download', `koffie_roulette_backup_${new Date().toISOString().slice(0, 10)}.json`);
|
||
|
|
document.body.appendChild(downloadAnchor);
|
||
|
|
downloadAnchor.click();
|
||
|
|
downloadAnchor.remove();
|
||
|
|
};
|
||
|
|
|
||
|
|
// Import JSON
|
||
|
|
const importInput = document.getElementById('importFileInput');
|
||
|
|
document.getElementById('importBtn').onclick = () => importInput.click();
|
||
|
|
importInput.onchange = (e) => {
|
||
|
|
const file = e.target.files[0];
|
||
|
|
if (!file) return;
|
||
|
|
const reader = new FileReader();
|
||
|
|
reader.onload = (event) => {
|
||
|
|
try {
|
||
|
|
const imported = JSON.parse(event.target.result);
|
||
|
|
if (Array.isArray(imported.colleagues)) {
|
||
|
|
state = {
|
||
|
|
colleagues: imported.colleagues,
|
||
|
|
lastWinnerId: imported.lastWinnerId || null,
|
||
|
|
soundEnabled: imported.soundEnabled !== false
|
||
|
|
};
|
||
|
|
saveData();
|
||
|
|
renderAll();
|
||
|
|
showToast('Gegevens succesvol geïmporteerd');
|
||
|
|
} else {
|
||
|
|
alert('Ongeldig bestandsformaat.');
|
||
|
|
}
|
||
|
|
} catch (err) {
|
||
|
|
alert('Fout bij het inlezen van JSON bestand.');
|
||
|
|
}
|
||
|
|
};
|
||
|
|
reader.readAsText(file);
|
||
|
|
};
|
||
|
|
|
||
|
|
// Sluit modal bij klik buiten window
|
||
|
|
document.getElementById('resultModal').onclick = (e) => {
|
||
|
|
if (e.target.id === 'resultModal') {
|
||
|
|
hideResultModal();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
// Start applicatie
|
||
|
|
window.onload = init;
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|