update new defined
All checks were successful
Deploy to Production / deploy (push) Successful in 19s
All checks were successful
Deploy to Production / deploy (push) Successful in 19s
This commit is contained in:
@@ -436,6 +436,10 @@
|
||||
|
||||
const html = `
|
||||
<div class="game-card">
|
||||
<button class="btn btn-secondary" onclick="loadAllGames()" style="margin-bottom: 20px;">
|
||||
← Quay lại danh sách
|
||||
</button>
|
||||
|
||||
<div class="game-info">
|
||||
<img src="${game.thumbnail}" alt="${game.title}" class="game-thumbnail" onerror="this.src='data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22200%22 height=%22200%22%3E%3Crect width=%22200%22 height=%22200%22 fill=%22%23ddd%22/%3E%3Ctext x=%2250%25%22 y=%2250%25%22 text-anchor=%22middle%22 dy=%22.3em%22 fill=%22%23999%22%3ENo Image%3C/text%3E%3C/svg%3E'">
|
||||
<div class="game-details">
|
||||
|
||||
560
public/gametype-manager.html
Normal file
560
public/gametype-manager.html
Normal file
@@ -0,0 +1,560 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="vi">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Game Type Manager - SENA</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #5a6268;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: #c82333;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
background: #218838;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
thead {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
th, td {
|
||||
padding: 15px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
th {
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
tbody tr:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 5px 10px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.badge-active {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.badge-inactive {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.badge-premium {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.form-view {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.form-view.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group select,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group select:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
min-height: 100px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.checkbox-group input[type="checkbox"] {
|
||||
width: auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🎮 Game Type Manager</h1>
|
||||
<p>Quản lý các loại trò chơi giáo dục</p>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<!-- List View -->
|
||||
<div id="listView" class="list-view">
|
||||
<div class="actions">
|
||||
<button class="btn btn-primary" onclick="showCreateForm()">➕ Tạo mới Game Type</button>
|
||||
<button class="btn btn-secondary" onclick="loadGameTypes()">🔄 Làm mới</button>
|
||||
</div>
|
||||
|
||||
<div id="message"></div>
|
||||
|
||||
<div class="table-container">
|
||||
<table id="gameTypesTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Type Code</th>
|
||||
<th>EN Title</th>
|
||||
<th>VI Title</th>
|
||||
<th>Category</th>
|
||||
<th>Thumb</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="gameTypesBody">
|
||||
<tr>
|
||||
<td colspan="7" class="loading">Đang tải dữ liệu...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Form View -->
|
||||
<div id="formView" class="form-view">
|
||||
<div class="actions">
|
||||
<button class="btn btn-secondary" onclick="showListView()">← Quay lại danh sách</button>
|
||||
</div>
|
||||
|
||||
<h2 id="formTitle">Tạo mới Game Type</h2>
|
||||
|
||||
<div id="formMessage"></div>
|
||||
|
||||
<form id="gameTypeForm" onsubmit="saveGameType(event)">
|
||||
<input type="hidden" id="gameTypeId" />
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>Type Code * (Mã định danh)</label>
|
||||
<input type="text" id="type" required placeholder="VD: G1400, counting_quiz">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Category</label>
|
||||
<select id="category">
|
||||
<option value="">-- Chọn category --</option>
|
||||
<option value="Quiz">Quiz</option>
|
||||
<option value="Sort">Sort</option>
|
||||
<option value="Memory">Memory</option>
|
||||
<option value="Lesson">Lesson</option>
|
||||
<option value="Sentence">Sentence</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>English Title *</label>
|
||||
<input type="text" id="en_title" required placeholder="English name">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Vietnamese Title *</label>
|
||||
<input type="text" id="vi_title" required placeholder="Tên tiếng Việt">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>English Description</label>
|
||||
<textarea id="en_desc" placeholder="English description"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Vietnamese Description</label>
|
||||
<textarea id="vi_desc" placeholder="Mô tả tiếng Việt"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Thumbnail URL</label>
|
||||
<input type="text" id="thumb" placeholder="https://example.com/thumb.jpg">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Data (JSON)</label>
|
||||
<textarea id="data" placeholder='{"sample": "data"}' style="font-family: monospace;"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Config (JSON)</label>
|
||||
<textarea id="config" placeholder='{"setting": "value"}' style="font-family: monospace;"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button type="submit" class="btn btn-success">💾 Lưu</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="showListView()">Hủy</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Auto-detect API base URL
|
||||
const API_BASE = window.location.origin + '/api/game-types';
|
||||
|
||||
// Load all game types
|
||||
async function loadGameTypes() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}?limit=100`);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
renderGameTypes(data.data.gameTypes);
|
||||
} else {
|
||||
showMessage('error', 'Không thể tải dữ liệu');
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage('error', 'Lỗi kết nối: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Render game types table
|
||||
function renderGameTypes(gameTypes) {
|
||||
const tbody = document.getElementById('gameTypesBody');
|
||||
|
||||
if (gameTypes.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;">Chưa có game type nào</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = gameTypes.map(gt => `
|
||||
<tr>
|
||||
<td>${gt.id.substring(0, 8)}...</td>
|
||||
<td><strong>${gt.type}</strong></td>
|
||||
<td>${gt.en_title}</td>
|
||||
<td>${gt.vi_title}</td>
|
||||
<td>${gt.category || '-'}</td>
|
||||
<td>${gt.thumb ? '🖼️' : '-'}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary" style="padding:8px 12px; font-size:14px;" onclick="editGameType('${gt.id}')">✏️ Sửa</button>
|
||||
<button class="btn btn-danger" style="padding:8px 12px; font-size:14px;" onclick="deleteGameType('${gt.id}')">🗑️ Xóa</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// Show create form
|
||||
function showCreateForm() {
|
||||
document.getElementById('formTitle').textContent = 'Tạo mới Game Type';
|
||||
document.getElementById('gameTypeForm').reset();
|
||||
document.getElementById('gameTypeId').value = '';
|
||||
showFormView();
|
||||
}
|
||||
|
||||
// Edit game type
|
||||
async function editGameType(id) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/${id}`);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
const gt = data.data;
|
||||
document.getElementById('formTitle').textContent = 'Cập nhật Game Type';
|
||||
document.getElementById('gameTypeId').value = gt.id;
|
||||
document.getElementById('type').value = gt.type;
|
||||
document.getElementById('en_title').value = gt.en_title;
|
||||
document.getElementById('vi_title').value = gt.vi_title;
|
||||
document.getElementById('en_desc').value = gt.en_desc || '';
|
||||
document.getElementById('vi_desc').value = gt.vi_desc || '';
|
||||
document.getElementById('category').value = gt.category || '';
|
||||
document.getElementById('thumb').value = gt.thumb || '';
|
||||
document.getElementById('data').value = gt.data ? JSON.stringify(gt.data, null, 2) : '';
|
||||
document.getElementById('config').value = gt.config ? JSON.stringify(gt.config, null, 2) : '';
|
||||
showFormView();
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage('error', 'Lỗi tải dữ liệu: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Save game type (create or update)
|
||||
async function saveGameType(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const id = document.getElementById('gameTypeId').value;
|
||||
|
||||
// Helper function to convert empty string to null
|
||||
const nullIfEmpty = (value) => value === '' ? null : value;
|
||||
|
||||
// Parse JSON fields
|
||||
let dataJson = null;
|
||||
let configJson = null;
|
||||
|
||||
try {
|
||||
const dataText = document.getElementById('data').value.trim();
|
||||
if (dataText) dataJson = JSON.parse(dataText);
|
||||
} catch (e) {
|
||||
showFormMessage('error', 'Data JSON không hợp lệ: ' + e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const configText = document.getElementById('config').value.trim();
|
||||
if (configText) configJson = JSON.parse(configText);
|
||||
} catch (e) {
|
||||
showFormMessage('error', 'Config JSON không hợp lệ: ' + e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = {
|
||||
type: document.getElementById('type').value,
|
||||
en_title: document.getElementById('en_title').value,
|
||||
vi_title: document.getElementById('vi_title').value,
|
||||
en_desc: nullIfEmpty(document.getElementById('en_desc').value),
|
||||
vi_desc: nullIfEmpty(document.getElementById('vi_desc').value),
|
||||
category: nullIfEmpty(document.getElementById('category').value),
|
||||
thumb: nullIfEmpty(document.getElementById('thumb').value),
|
||||
data: dataJson,
|
||||
config: configJson
|
||||
};
|
||||
|
||||
try {
|
||||
const url = id ? `${API_BASE}/${id}` : API_BASE;
|
||||
const method = id ? 'PUT' : 'POST';
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log('Save result:', result); // Debug log
|
||||
|
||||
if (result.success) {
|
||||
showMessage('success', id ? 'Cập nhật thành công!' : 'Tạo mới thành công!');
|
||||
setTimeout(() => {
|
||||
showListView();
|
||||
loadGameTypes();
|
||||
}, 1500);
|
||||
} else {
|
||||
const errorMsg = result.error || result.message || JSON.stringify(result);
|
||||
showFormMessage('error', errorMsg);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Save error:', error);
|
||||
showFormMessage('error', 'Lỗi kết nối: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete game type
|
||||
async function deleteGameType(id) {
|
||||
if (!confirm('Bạn có chắc chắn muốn xóa game type này?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/${id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showMessage('success', 'Xóa thành công!');
|
||||
loadGameTypes();
|
||||
} else {
|
||||
showMessage('error', result.error || 'Không thể xóa');
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage('error', 'Lỗi kết nối: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Show/hide views
|
||||
function showListView() {
|
||||
document.getElementById('listView').style.display = 'block';
|
||||
document.getElementById('formView').classList.remove('active');
|
||||
document.getElementById('formMessage').innerHTML = '';
|
||||
}
|
||||
|
||||
function showFormView() {
|
||||
document.getElementById('listView').style.display = 'none';
|
||||
document.getElementById('formView').classList.add('active');
|
||||
document.getElementById('message').innerHTML = '';
|
||||
}
|
||||
|
||||
// Show messages
|
||||
function showMessage(type, text) {
|
||||
const messageDiv = document.getElementById('message');
|
||||
messageDiv.innerHTML = `<div class="${type}">${text}</div>`;
|
||||
setTimeout(() => { messageDiv.innerHTML = ''; }, 5000);
|
||||
}
|
||||
|
||||
function showFormMessage(type, text) {
|
||||
const messageDiv = document.getElementById('formMessage');
|
||||
messageDiv.innerHTML = `<div class="${type}">${text}</div>`;
|
||||
setTimeout(() => { messageDiv.innerHTML = ''; }, 5000);
|
||||
}
|
||||
|
||||
// Initial load
|
||||
loadGameTypes();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user