Tea_room / teapot /frontend /admin.html
Мурад Гаджимагомедов
update name
cc9c63d
Raw History Blame Contribute Delete
4.64 kB
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bdшка</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: sans-serif; background: #fdf6ec; color: #3d2b1f; max-width: 480px; margin: 0 auto; padding: 20px; }
h1, h2 { margin-bottom: 16px; }
h2 { margin-top: 24px; font-size: 1.1rem; color: #8b5e3c; }
.participant { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: #fff; border-radius: 10px; margin-bottom: 8px; border: 1px solid #e8d5b7; flex-wrap: wrap; }
.name { flex: 1; min-width: 80px; font-weight: bold; }
.tickets-input { width: 50px; padding: 4px 6px; border: 1px solid #e8d5b7; border-radius: 6px; font-size: 0.9rem; text-align: center; }
.pass-checkbox { display: flex; align-items: center; gap: 4px; font-size: 0.85rem; }
.save-btn { padding: 4px 10px; background: #8b5e3c; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.del-btn { padding: 4px 10px; background: #c0392b; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.add-form { display: flex; gap: 8px; margin-bottom: 8px; }
.add-form input { flex: 1; padding: 10px; border: 1px solid #e8d5b7; border-radius: 8px; font-size: 1rem; background: #fff; }
.add-form button { padding: 10px 16px; background: #8b5e3c; color: white; border: none; border-radius: 8px; cursor: pointer; }
.history-item { padding: 10px 12px; background: #fff; border-radius: 10px; margin-bottom: 8px; border: 1px solid #e8d5b7; font-size: 0.9rem; }
.history-winner { font-weight: bold; color: #8b5e3c; }
a { display: block; text-align: center; margin-top: 20px; color: #8b5e3c; }
.saved { color: green; font-size: 0.8rem; }
</style>
</head>
<body>
<h1>bdшка</h1>
<h2>Участники</h2>
<div class="add-form">
<input id="newName" placeholder="Имя участника">
<button onclick="addParticipant()">Добавить</button>
</div>
<div id="list"></div>
<h2>История</h2>
<div id="history"></div>
<a href="/">Назад</a>
<script>
async function load() {
const [pRes, hRes] = await Promise.all([
fetch('/api/participants'),
fetch('/api/history')
]);
const participants = await pRes.json();
const history = await hRes.json();
const list = document.getElementById('list');
list.innerHTML = participants.map(p => `
<div class="participant" data-id="${p.id}">
<span class="name">${p.name}</span>
<label style="font-size:0.8rem">жетоны:
<input class="tickets-input" type="number" min="0" value="${p.tickets}" data-field="tickets">
</label>
<label class="pass-checkbox">
<input type="checkbox" ${p.pass_point ? 'checked' : ''} data-field="pass_point"> пропуск
</label>
<button class="save-btn" onclick="save(${p.id}, this)">Сохранить</button>
<button class="del-btn" onclick="del(${p.id})">Удалить</button>
</div>
`).join('');
const hist = document.getElementById('history');
hist.innerHTML = history.slice(0, 10).map(h => `
<div class="history-item">
<span>${h.date}</span> —
<span class="history-winner">${h.winner}</span> помыл чайник
<div style="font-size:0.8rem;color:#aaa">${JSON.parse(h.present).join(', ')}</div>
</div>
`).join('') || '<div style="color:#aaa">История пуста</div>';
}
async function save(id, btn) {
const row = btn.closest('.participant');
const tickets = parseInt(row.querySelector('[data-field="tickets"]').value);
const pass_point = row.querySelector('[data-field="pass_point"]').checked;
await fetch('/api/participants/' + id, {
method: 'PATCH',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({tickets, pass_point})
});
const saved = document.createElement('span');
saved.className = 'saved';
saved.textContent = 'Сохранено';
btn.after(saved);
setTimeout(() => saved.remove(), 1500);
}
async function addParticipant() {
const name = document.getElementById('newName').value.trim();
if (!name) return;
await fetch('/api/participants', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name})
});
document.getElementById('newName').value = '';
load();
}
async function del(id) {
await fetch('/api/participants/' + id, {method: 'DELETE'});
load();
}
document.getElementById('newName').addEventListener('keydown', e => {
if (e.key === 'Enter') addParticipant();
});
load();
</script>
</body>
</html>