186 lines
4.5 KiB
HTML
186 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="sk">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>ZKT Guestbook</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background: #f4f7fb;
|
|
color: #1f2937;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
.container {
|
|
max-width: 900px;
|
|
margin: 40px auto;
|
|
background: #ffffff;
|
|
border-radius: 16px;
|
|
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
|
|
padding: 32px;
|
|
}
|
|
h1 {
|
|
margin-top: 0;
|
|
}
|
|
p.note {
|
|
color: #4b5563;
|
|
margin-bottom: 24px;
|
|
}
|
|
form {
|
|
display: grid;
|
|
gap: 12px;
|
|
margin-bottom: 28px;
|
|
}
|
|
input, textarea, button {
|
|
font: inherit;
|
|
padding: 12px;
|
|
border-radius: 10px;
|
|
border: 1px solid #d1d5db;
|
|
}
|
|
textarea {
|
|
min-height: 100px;
|
|
resize: vertical;
|
|
}
|
|
button {
|
|
background: #2563eb;
|
|
color: white;
|
|
border: none;
|
|
cursor: pointer;
|
|
font-weight: bold;
|
|
}
|
|
button:hover {
|
|
opacity: 0.95;
|
|
}
|
|
.status {
|
|
margin-bottom: 18px;
|
|
padding: 10px 12px;
|
|
border-radius: 10px;
|
|
background: #eef2ff;
|
|
}
|
|
.messages {
|
|
display: grid;
|
|
gap: 12px;
|
|
}
|
|
.message {
|
|
border: 1px solid #e5e7eb;
|
|
border-radius: 12px;
|
|
padding: 14px;
|
|
background: #fafafa;
|
|
}
|
|
.meta {
|
|
font-size: 0.9rem;
|
|
color: #6b7280;
|
|
margin-bottom: 8px;
|
|
}
|
|
.empty {
|
|
color: #6b7280;
|
|
font-style: italic;
|
|
}
|
|
code {
|
|
background: #f3f4f6;
|
|
padding: 2px 6px;
|
|
border-radius: 6px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>ZKT Guestbook</h1>
|
|
|
|
<div id="status" class="status">Kontrolujem stav backendu...</div>
|
|
|
|
<form id="messageForm">
|
|
<input id="author" type="text" placeholder="Tvoje meno" required>
|
|
<textarea id="content" placeholder="Napíš správu..." required></textarea>
|
|
<button type="submit">Pridať správu</button>
|
|
</form>
|
|
|
|
<h2>Správy</h2>
|
|
<div id="messages" class="messages"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const statusEl = document.getElementById('status');
|
|
const messagesEl = document.getElementById('messages');
|
|
const form = document.getElementById('messageForm');
|
|
|
|
async function checkHealth() {
|
|
try {
|
|
const response = await fetch('/api/health');
|
|
const data = await response.json();
|
|
if (response.ok) {
|
|
statusEl.textContent = `Backend je dostupný. Databáza: ${data.database}`;
|
|
} else {
|
|
statusEl.textContent = 'Backend nie je dostupný.';
|
|
}
|
|
} catch (error) {
|
|
statusEl.textContent = 'Nepodarilo sa spojiť s backendom.';
|
|
}
|
|
}
|
|
|
|
async function loadMessages() {
|
|
try {
|
|
const response = await fetch('/api/messages');
|
|
const data = await response.json();
|
|
|
|
if (!Array.isArray(data) || data.length === 0) {
|
|
messagesEl.innerHTML = '<div class="empty">Zatiaľ tu nie sú žiadne správy.</div>';
|
|
return;
|
|
}
|
|
|
|
messagesEl.innerHTML = data.map(msg => {
|
|
const date = new Date(msg.created_at).toLocaleString('sk-SK');
|
|
return `
|
|
<div class="message">
|
|
<div class="meta"><strong>${escapeHtml(msg.author)}</strong> • ${date}</div>
|
|
<div>${escapeHtml(msg.content)}</div>
|
|
</div>
|
|
`;
|
|
}).join('');
|
|
} catch (error) {
|
|
messagesEl.innerHTML = '<div class="empty">Nepodarilo sa načítať správy.</div>';
|
|
}
|
|
}
|
|
|
|
form.addEventListener('submit', async (event) => {
|
|
event.preventDefault();
|
|
|
|
const author = document.getElementById('author').value.trim();
|
|
const content = document.getElementById('content').value.trim();
|
|
|
|
if (!author || !content) {
|
|
return;
|
|
}
|
|
|
|
const response = await fetch('/api/messages', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ author, content })
|
|
});
|
|
|
|
if (response.ok) {
|
|
form.reset();
|
|
await loadMessages();
|
|
} else {
|
|
alert('Správu sa nepodarilo uložiť.');
|
|
}
|
|
});
|
|
|
|
function escapeHtml(value) {
|
|
return value
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll("'", ''');
|
|
}
|
|
|
|
checkHealth();
|
|
loadMessages();
|
|
</script>
|
|
</body>
|
|
</html>
|