Move frontend

This commit is contained in:
Andras Schmelczer 2025-08-31 13:20:31 +01:00
commit 7ea082fecb
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
37 changed files with 2993 additions and 3 deletions

351
backend/public/admin.html Normal file
View file

@ -0,0 +1,351 @@
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fizika Admin - Kérdések és képek kezelése</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background: #003366;
color: white;
padding: 1rem;
margin-bottom: 2rem;
border-radius: 8px;
}
.tabs {
display: flex;
margin-bottom: 2rem;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.tab {
flex: 1;
padding: 1rem;
background: white;
border: none;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.3s;
}
.tab:hover {
background: #f0f0f0;
}
.tab.active {
background: #003366;
color: white;
}
.tab:not(.active) {
color: #333;
}
.tab-content {
display: none;
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.tab-content.active {
display: block;
}
.form-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: bold;
}
input,
textarea,
select {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
textarea {
min-height: 100px;
resize: vertical;
}
button {
background: #003366;
color: white;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.3s;
}
button:hover {
background: #004488;
}
button.secondary {
background: #666;
}
button.danger {
background: #dc3545;
}
button.danger:hover {
background: #c82333;
}
.questions-list {
margin-top: 2rem;
}
.question-item {
background: #f8f9fa;
padding: 1rem;
margin-bottom: 1rem;
border-radius: 4px;
border-left: 4px solid #003366;
}
.question-actions button {
margin-right: 0.5rem;
margin-bottom: 0.5rem;
}
.images-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1rem;
margin-top: 1rem;
}
.image-item {
background: white;
padding: 1rem;
border-radius: 4px;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.image-item img {
max-width: 100%;
height: 150px;
object-fit: cover;
border-radius: 4px;
}
.alert {
padding: 1rem;
margin-bottom: 1rem;
border-radius: 4px;
}
.alert-success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.alert-danger {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: white;
margin: 5% auto;
padding: 2rem;
border-radius: 8px;
width: 80%;
max-width: 600px;
max-height: 80%;
overflow-y: auto;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: black;
}
@media (max-width: 768px) {
.container {
padding: 10px;
}
.tabs {
flex-direction: column;
}
.images-grid {
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Fizika Admin Panel</h1>
<p>Kérdések és képek kezelése</p>
</div>
<!-- Admin Panel -->
<div class="tabs">
<button class="tab active" data-tab="questions">
Kérdések kezelése
</button>
<button class="tab" data-tab="images">Képek kezelése</button>
</div>
<!-- Questions Tab -->
<div id="questionsTab" class="tab-content active">
<h2>Kérdések kezelése</h2>
<div id="questionsAlert"></div>
<button id="addQuestionBtn">Új kérdés hozzáadása</button>
<div id="questionsList" class="questions-list">
<div>Kérdések betöltése...</div>
</div>
</div>
<!-- Images Tab -->
<div id="imagesTab" class="tab-content">
<h2>Képek kezelése</h2>
<div id="imagesAlert"></div>
<div class="form-group">
<label for="imageUpload">Új kép feltöltése:</label>
<input type="file" id="imageUpload" accept="image/*" />
</div>
<div id="imagesList" class="images-grid">
<div>Képek betöltése...</div>
</div>
</div>
</div>
<!-- Question Edit Modal -->
<div id="questionModal" class="modal">
<div class="modal-content">
<span class="close" id="closeModalBtn">&times;</span>
<h2 id="modalTitle">Kérdés szerkesztése</h2>
<form id="questionForm">
<input type="hidden" id="questionId" />
<div class="form-group">
<label for="questionSource">Forrás:</label>
<input type="text" id="questionSource" required />
</div>
<div class="form-group">
<label for="questionDescription">Kérdés szövege:</label>
<textarea id="questionDescription" required></textarea>
</div>
<div class="form-group">
<label for="questionA">A válasz:</label>
<textarea id="questionA" required></textarea>
</div>
<div class="form-group">
<label for="questionB">B válasz:</label>
<textarea id="questionB" required></textarea>
</div>
<div class="form-group">
<label for="questionC">C válasz:</label>
<textarea id="questionC" required></textarea>
</div>
<div class="form-group">
<label for="questionD">D válasz:</label>
<textarea id="questionD" required></textarea>
</div>
<div class="form-group">
<label for="questionCorrect">Helyes válasz:</label>
<select id="questionCorrect" required>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4">D</option>
</select>
</div>
<div class="form-group">
<label for="questionType">Típus:</label>
<select id="questionType" required>
<option value="md">Dinamika</option>
<option value="me">Mechanika</option>
<option value="mf">Folyadékok</option>
</select>
</div>
<div class="form-group">
<label for="questionImage">Kép:</label>
<input
type="text"
id="questionImage"
placeholder="Kép fájlneve (opcionális)"
/>
</div>
<button type="submit">Mentés</button>
<button type="button" class="secondary" id="cancelBtn">Mégse</button>
</form>
</div>
</div>
<script src="admin.js"></script>
</body>
</html>

324
backend/public/admin.js Normal file
View file

@ -0,0 +1,324 @@
const API_BASE = window.location.origin;
// Initialize
document.addEventListener("DOMContentLoaded", function () {
loadQuestions();
loadImages();
// Set up event listeners
setupEventListeners();
});
function setupEventListeners() {
// Tab switching
document.querySelectorAll('.tab[data-tab]').forEach(tab => {
tab.addEventListener('click', (e) => {
switchTab(e.target.dataset.tab);
});
});
// Add question button
document.getElementById('addQuestionBtn').addEventListener('click', showAddQuestionModal);
// Image upload
document.getElementById('imageUpload').addEventListener('change', uploadImage);
// Modal close buttons
document.getElementById('closeModalBtn').addEventListener('click', closeModal);
document.getElementById('cancelBtn').addEventListener('click', closeModal);
// Question form submit
document.getElementById('questionForm').addEventListener('submit', saveQuestion);
// Close modal when clicking outside
document.getElementById('questionModal').addEventListener('click', (e) => {
if (e.target.id === 'questionModal') {
closeModal();
}
});
}
// Tab switching
function switchTab(tabName) {
document
.querySelectorAll(".tab-content")
.forEach((tab) => tab.classList.remove("active"));
document
.querySelectorAll(".tab")
.forEach((tab) => tab.classList.remove("active"));
document.getElementById(tabName + "Tab").classList.add("active");
document.querySelector(`[data-tab="${tabName}"]`).classList.add("active");
if (tabName === "images") loadImages();
}
// Questions management
async function loadQuestions() {
try {
const response = await fetch(`${API_BASE}/api/admin/questions`);
if (response.ok) {
const questions = await response.json();
displayQuestions(questions);
} else {
throw new Error("Failed to load");
}
} catch (error) {
document.getElementById("questionsList").innerHTML =
'<div class="alert alert-danger">Hiba a kérdések betöltésekor</div>';
}
}
function displayQuestions(questions) {
const container = document.getElementById("questionsList");
container.innerHTML = questions
.map(
(q) => `
<div class="question-item">
<h4>ID: ${q.id} - ${q.source}</h4>
<p><strong>Kérdés:</strong> ${q.description.substring(
0,
100
)}...</p>
<p><strong>Típus:</strong> ${
q.type
} | <strong>Helyes válasz:</strong> ${
["A", "B", "C", "D"][q.correct - 1]
}</p>
<div class="question-actions">
<button data-edit-id="${q.id}">Szerkesztés</button>
<button class="danger" data-delete-id="${q.id}">Törlés</button>
</div>
</div>
`
)
.join("");
// Add event listeners for edit and delete buttons
container.querySelectorAll('[data-edit-id]').forEach(btn => {
btn.addEventListener('click', (e) => {
editQuestion(parseInt(e.target.dataset.editId));
});
});
container.querySelectorAll('[data-delete-id]').forEach(btn => {
btn.addEventListener('click', (e) => {
deleteQuestion(parseInt(e.target.dataset.deleteId));
});
});
}
function showAddQuestionModal() {
document.getElementById("modalTitle").textContent =
"Új kérdés hozzáadása";
document.getElementById("questionForm").reset();
document.getElementById("questionId").value = "";
document.getElementById("questionModal").style.display = "block";
}
async function editQuestion(id) {
try {
const response = await fetch(`${API_BASE}/api/admin/questions`);
if (response.ok) {
const questions = await response.json();
const question = questions.find((q) => q.id === id);
if (question) {
document.getElementById("modalTitle").textContent =
"Kérdés szerkesztése";
document.getElementById("questionId").value = question.id;
document.getElementById("questionSource").value = question.source;
document.getElementById("questionDescription").value =
question.description;
document.getElementById("questionA").value = question.a;
document.getElementById("questionB").value = question.b;
document.getElementById("questionC").value = question.c;
document.getElementById("questionD").value = question.d;
document.getElementById("questionCorrect").value =
question.correct;
document.getElementById("questionType").value = question.type;
document.getElementById("questionImage").value =
question.image || "";
document.getElementById("questionModal").style.display = "block";
}
}
} catch (error) {
showAlert("questionsAlert", "Hiba a kérdés betöltésekor", "danger");
}
}
async function saveQuestion(event) {
event.preventDefault();
const data = {
source: document.getElementById("questionSource").value,
description: document.getElementById("questionDescription").value,
a: document.getElementById("questionA").value,
b: document.getElementById("questionB").value,
c: document.getElementById("questionC").value,
d: document.getElementById("questionD").value,
correct: parseInt(document.getElementById("questionCorrect").value),
type: document.getElementById("questionType").value,
image: document.getElementById("questionImage").value || null,
};
const id = document.getElementById("questionId").value;
const isEdit = id !== "";
try {
const response = await fetch(
isEdit
? `${API_BASE}/api/admin/questions/${id}`
: `${API_BASE}/api/admin/questions`,
{
method: isEdit ? "PUT" : "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
}
);
if (response.ok) {
closeModal();
loadQuestions();
showAlert("questionsAlert", "Kérdés sikeresen mentve!", "success");
} else {
const error = await response.json();
showAlert(
"questionsAlert",
error.error || "Hiba a mentés során",
"danger"
);
}
} catch (error) {
showAlert("questionsAlert", "Kapcsolat hiba", "danger");
}
}
async function deleteQuestion(id) {
if (!confirm("Biztosan törölni szeretnéd ezt a kérdést?")) return;
try {
const response = await fetch(
`${API_BASE}/api/admin/questions/${id}`,
{ method: "DELETE" }
);
if (response.ok) {
loadQuestions();
showAlert("questionsAlert", "Kérdés törölve!", "success");
} else {
throw new Error("Delete failed");
}
} catch (error) {
showAlert("questionsAlert", "Hiba a törlés során", "danger");
}
}
// Images management
async function loadImages() {
try {
const response = await fetch(`${API_BASE}/api/images`);
if (response.ok) {
const images = await response.json();
displayImages(images);
} else {
throw new Error("Failed to load");
}
} catch (error) {
document.getElementById("imagesList").innerHTML =
'<div class="alert alert-danger">Hiba a képek betöltésekor</div>';
}
}
function displayImages(images) {
const container = document.getElementById("imagesList");
container.innerHTML = images
.map(
(image) => `
<div class="image-item">
<img src="${API_BASE}/api/pics/${image}" alt="${image}">
<p>${image}</p>
<button class="danger" data-delete-image="${image}">Törlés</button>
</div>
`
)
.join("");
// Add event listeners for delete buttons
container.querySelectorAll('[data-delete-image]').forEach(btn => {
btn.addEventListener('click', (e) => {
deleteImage(e.target.dataset.deleteImage);
});
});
}
async function uploadImage() {
const input = document.getElementById("imageUpload");
const file = input.files[0];
if (!file) return;
const formData = new FormData();
formData.append("image", file);
try {
const response = await fetch(`${API_BASE}/api/admin/images/upload`, {
method: "POST",
body: formData,
});
if (response.ok) {
input.value = "";
loadImages();
showAlert("imagesAlert", "Kép sikeresen feltöltve!", "success");
} else {
const error = await response.json();
showAlert(
"imagesAlert",
error.error || "Hiba a feltöltés során",
"danger"
);
}
} catch (error) {
showAlert("imagesAlert", "Kapcsolat hiba", "danger");
}
}
async function deleteImage(filename) {
if (!confirm(`Biztosan törölni szeretnéd a ${filename} képet?`)) return;
try {
const response = await fetch(
`${API_BASE}/api/admin/images/${encodeURIComponent(filename)}`,
{
method: "DELETE",
}
);
if (response.ok) {
loadImages();
showAlert("imagesAlert", "Kép törölve!", "success");
} else {
throw new Error("Delete failed");
}
} catch (error) {
showAlert("imagesAlert", "Hiba a törlés során", "danger");
}
}
// Utility functions
function closeModal() {
document.getElementById("questionModal").style.display = "none";
}
function showAlert(elementId, message, type) {
const alertDiv = document.getElementById(elementId);
alertDiv.className = `alert alert-${type}`;
alertDiv.textContent = message;
alertDiv.style.display = "block";
setTimeout(() => {
alertDiv.style.display = "none";
}, 5000);
}
// This is now handled in setupEventListeners()