231 lines
9.5 KiB
HTML
231 lines
9.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>Что мы узнали на занятии</title>
|
|
<style>
|
|
*{margin:0;padding:0;box-sizing:border-box}
|
|
:root{--bg:#f5f5f5;--card:#fff;--border:#e5e5e5;--accent:#2563eb;--text:#171717;--muted:#737373;--radius:12px}
|
|
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:var(--bg);color:var(--text);min-height:100dvh;display:flex;flex-direction:column;align-items:center;padding:24px 16px}
|
|
h1{font-size:1.5rem;font-weight:600;margin-bottom:8px;letter-spacing:-.02em}
|
|
.sub{color:var(--muted);font-size:.85rem;margin-bottom:32px}
|
|
.form{width:100%;max-width:480px;display:flex;flex-direction:column;gap:20px}
|
|
.field{display:flex;flex-direction:column;gap:6px}
|
|
label{font-size:.8rem;font-weight:500;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}
|
|
input,select,textarea{background:var(--card);border:1px solid var(--border);color:var(--text);border-radius:var(--radius);padding:14px 16px;font-size:.95rem;outline:none;transition:border .15s}
|
|
input:focus,select:focus,textarea:focus{border-color:var(--accent)}
|
|
.fixed-name{background:var(--card);border:1px solid var(--border);color:var(--text);border-radius:var(--radius);padding:14px 16px;font-size:.95rem;font-weight:600;text-align:center}
|
|
textarea{resize:vertical;min-height:160px;font-family:inherit;line-height:1.5}
|
|
|
|
.photo-btns{display:flex;gap:8px}
|
|
.photo-btns button{flex:1;border-radius:var(--radius);padding:12px;font-size:.85rem;font-weight:500;cursor:pointer;border:1px solid var(--border);background:var(--card);color:var(--text);transition:border .15s}
|
|
.photo-btns button:hover{border-color:var(--accent)}
|
|
.photo-btns .cam{background:var(--accent);color:#fff;border-color:var(--accent)}
|
|
.photo-btns .cam:hover{opacity:.85}
|
|
|
|
.preview{max-width:200px;border-radius:var(--radius);margin-top:8px;display:none}
|
|
.remove-photo{background:none;border:none;color:#ef4444;font-size:.8rem;cursor:pointer;margin-top:4px;display:none}
|
|
|
|
.btn{background:var(--accent);color:#fff;border:none;border-radius:var(--radius);padding:16px;font-size:1rem;font-weight:600;cursor:pointer;transition:opacity .15s}
|
|
.btn:hover{opacity:.85}
|
|
.btn:disabled{opacity:.4;cursor:not-allowed}
|
|
.toast{position:fixed;bottom:24px;left:50%;transform:translateX(-50%);background:#16a34a;color:#fff;padding:12px 24px;border-radius:var(--radius);font-size:.9rem;opacity:0;transition:opacity .3s;pointer-events:none;z-index:200}
|
|
.toast.show{opacity:1}
|
|
.toast.error{background:#dc2626}
|
|
nav{position:fixed;top:16px;right:16px;display:flex;gap:8px}
|
|
nav a{color:var(--muted);text-decoration:none;font-size:.8rem;padding:6px 12px;border-radius:8px;transition:color .15s}
|
|
nav a:hover{color:var(--text)}
|
|
|
|
.modal{position:fixed;inset:0;background:rgba(0,0,0,.7);display:flex;align-items:center;justify-content:center;z-index:100;display:none}
|
|
.modal.open{display:flex}
|
|
.modal-box{background:var(--card);border-radius:16px;padding:16px;max-width:400px;width:90%;display:flex;flex-direction:column;gap:12px}
|
|
.modal-box video{width:100%;border-radius:var(--radius);background:#000;transform:scaleX(-1)}
|
|
.modal-actions{display:flex;gap:8px}
|
|
.modal-actions button{flex:1;padding:12px;border:none;border-radius:var(--radius);font-size:.9rem;font-weight:600;cursor:pointer}
|
|
.modal-actions .capture{background:var(--accent);color:#fff}
|
|
.modal-actions .cancel{background:var(--border);color:var(--text)}
|
|
.modal-actions button:hover{opacity:.85}
|
|
#camCanvas{display:none}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav>
|
|
<a href="admin.html">Админка</a>
|
|
</nav>
|
|
<h1 id="title">Что мы узнали на занятии</h1>
|
|
<p class="sub">Отметь, что ты делал(а) на занятии</p>
|
|
|
|
<form class="form" id="form">
|
|
<div class="field">
|
|
<label>Фото</label>
|
|
<div class="photo-btns">
|
|
<button type="button" class="cam" onclick="openCam()">Камера</button>
|
|
</div>
|
|
<img class="preview" id="preview">
|
|
<button type="button" class="remove-photo" id="removePhotoBtn" onclick="removePhoto()">Убрать фото</button>
|
|
</div>
|
|
|
|
<div class="field" id="nameField">
|
|
<label>Фамилия и имя</label>
|
|
<input type="text" id="nameInput" list="studentList" placeholder="Например, Иванов Иван" required>
|
|
</div>
|
|
<datalist id="studentList"></datalist>
|
|
|
|
<div class="field">
|
|
<label>Группа</label>
|
|
<select id="groupInput" required>
|
|
<option value="" disabled selected>Выбери группу</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label>Что сделал</label>
|
|
<textarea id="descInput" placeholder="Опиши, что проходил, что делал на занятии..." required></textarea>
|
|
</div>
|
|
|
|
<button class="btn" type="submit" id="submitBtn">Отправить</button>
|
|
</form>
|
|
|
|
<div class="modal" id="camModal">
|
|
<div class="modal-box">
|
|
<video id="camVideo" autoplay playsinline></video>
|
|
<canvas id="camCanvas"></canvas>
|
|
<div class="modal-actions">
|
|
<button class="cancel" onclick="closeCam()">Отмена</button>
|
|
<button class="capture" onclick="capture()">Снять</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="toast" id="toast">Готово!</div>
|
|
|
|
<script>
|
|
const API = location.origin;
|
|
const form = document.getElementById('form');
|
|
const preview = document.getElementById('preview');
|
|
const removePhotoBtn = document.getElementById('removePhotoBtn');
|
|
const groupInput = document.getElementById('groupInput');
|
|
const toast = document.getElementById('toast');
|
|
const camVideo = document.getElementById('camVideo');
|
|
const camCanvas = document.getElementById('camCanvas');
|
|
const camModal = document.getElementById('camModal');
|
|
let capturedBlob = null;
|
|
let stream = null;
|
|
const descInput = document.getElementById('descInput');
|
|
|
|
const params = new URLSearchParams(location.search);
|
|
let studentName = '';
|
|
function escName(s) { const d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
|
|
if (params.get('nameInput')) {
|
|
studentName = params.get('nameInput');
|
|
document.getElementById('nameInput').value = studentName;
|
|
const field = document.getElementById('nameField');
|
|
field.innerHTML = `<label>Фамилия и имя</label><div class="fixed-name" id="fixedName">${escName(studentName)}</div>`;
|
|
}
|
|
|
|
(async () => {
|
|
const res = await fetch(`${API}/api/students`);
|
|
const students = await res.json();
|
|
const dl = document.getElementById('studentList');
|
|
students.forEach(s => {
|
|
const o = document.createElement('option');
|
|
o.value = s.name;
|
|
dl.appendChild(o);
|
|
});
|
|
const me = studentName ? students.find(s => s.name === studentName) : null;
|
|
if (me && me.group_id) {
|
|
groupInput.innerHTML = `<option value="${me.group_id}" selected>${escName(me.group_name || `Группа ${me.group_id}`)}</option>`;
|
|
groupInput.value = String(me.group_id);
|
|
} else {
|
|
const groupsRes = await fetch(`${API}/api/groups/active`);
|
|
const groups = await groupsRes.json();
|
|
groups.forEach(g => {
|
|
const opt = document.createElement('option');
|
|
opt.value = g.id;
|
|
opt.textContent = g.name;
|
|
groupInput.appendChild(opt);
|
|
});
|
|
if (!groups.length) {
|
|
groupInput.innerHTML = '<option value="" disabled selected>Нет активных групп</option>';
|
|
}
|
|
}
|
|
})();
|
|
|
|
function showPreview(src) {
|
|
preview.src = src;
|
|
preview.style.display = 'block';
|
|
removePhotoBtn.style.display = 'block';
|
|
}
|
|
|
|
function removePhoto() {
|
|
preview.style.display = 'none';
|
|
removePhotoBtn.style.display = 'none';
|
|
capturedBlob = null;
|
|
}
|
|
|
|
async function openCam() {
|
|
try {
|
|
stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user', width: { ideal: 640 }, height: { ideal: 480 } } });
|
|
camVideo.srcObject = stream;
|
|
camModal.classList.add('open');
|
|
} catch (e) {
|
|
alert('Не удалось открыть камеру: ' + e.message);
|
|
}
|
|
}
|
|
|
|
function closeCam() {
|
|
camModal.classList.remove('open');
|
|
if (stream) { stream.getTracks().forEach(t => t.stop()); stream = null; }
|
|
}
|
|
|
|
function capture() {
|
|
camCanvas.width = camVideo.videoWidth;
|
|
camCanvas.height = camVideo.videoHeight;
|
|
camCanvas.getContext('2d').drawImage(camVideo, 0, 0);
|
|
camCanvas.toBlob(blob => {
|
|
capturedBlob = blob;
|
|
showPreview(URL.createObjectURL(blob));
|
|
closeCam();
|
|
}, 'image/jpeg', 0.85);
|
|
}
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const btn = document.getElementById('submitBtn');
|
|
btn.disabled = true;
|
|
btn.textContent = 'Отправка...';
|
|
|
|
const fd = new FormData();
|
|
if (capturedBlob) fd.append('photo', capturedBlob, 'photo.jpg');
|
|
fd.append('student_name', studentName || document.getElementById('nameInput').value);
|
|
fd.append('group_id', groupInput.value);
|
|
fd.append('description', document.getElementById('descInput').value);
|
|
|
|
try {
|
|
const res = await fetch(`${API}/api/entries`, { method: 'POST', body: fd });
|
|
if (res.status === 429) {
|
|
const e = await res.json().catch(() => ({}));
|
|
toast.textContent = e.error || 'Уже ответили: подождите';
|
|
toast.classList.add('show', 'error');
|
|
setTimeout(() => toast.classList.remove('show', 'error'), 3200);
|
|
return;
|
|
}
|
|
if (!res.ok) throw new Error(await res.text());
|
|
form.reset();
|
|
removePhoto();
|
|
toast.textContent = 'Готово!';
|
|
toast.classList.remove('error');
|
|
toast.classList.add('show');
|
|
setTimeout(() => toast.classList.remove('show'), 2500);
|
|
} catch (err) {
|
|
alert('Ошибка: ' + err.message);
|
|
} finally {
|
|
btn.disabled = false;
|
|
btn.textContent = 'Отправить';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|