227 lines
6.5 KiB
HTML
227 lines
6.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Category Tree Viewer</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 2rem;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
background: rgba(255, 255, 255, 0.95);
|
|
border-radius: 16px;
|
|
padding: 2rem;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
h1 {
|
|
color: #667eea;
|
|
margin-bottom: 2rem;
|
|
font-size: 2.5rem;
|
|
text-align: center;
|
|
}
|
|
|
|
.tree {
|
|
list-style: none;
|
|
}
|
|
|
|
.tree ul {
|
|
list-style: none;
|
|
padding-left: 2rem;
|
|
}
|
|
|
|
.category {
|
|
margin: 0.5rem 0;
|
|
padding: 0.75rem;
|
|
background: white;
|
|
border-radius: 8px;
|
|
border-left: 4px solid #667eea;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.category:hover {
|
|
transform: translateX(4px);
|
|
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
|
|
}
|
|
|
|
.category-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.category-image {
|
|
width: 48px;
|
|
height: 48px;
|
|
object-fit: cover;
|
|
border-radius: 6px;
|
|
background: #f0f0f0;
|
|
}
|
|
|
|
.category-info {
|
|
flex: 1;
|
|
}
|
|
|
|
.category-name {
|
|
font-weight: 600;
|
|
color: #333;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.category-count {
|
|
color: #666;
|
|
font-size: 0.9rem;
|
|
margin-top: 0.25rem;
|
|
}
|
|
|
|
.toggle {
|
|
color: #667eea;
|
|
font-weight: bold;
|
|
margin-right: 0.5rem;
|
|
user-select: none;
|
|
}
|
|
|
|
.children {
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
.children.hidden {
|
|
display: none;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 3rem;
|
|
color: #667eea;
|
|
font-size: 1.2rem;
|
|
}
|
|
|
|
.error {
|
|
background: #fee;
|
|
color: #c33;
|
|
padding: 1rem;
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>📦 Category Tree</h1>
|
|
<div id="tree-container">
|
|
<div class="loading">Loading categories...</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
async function loadCategories() {
|
|
try {
|
|
const response = await fetch('/api/categories');
|
|
if (!response.ok) throw new Error('Failed to load categories');
|
|
const categories = await response.json();
|
|
renderTree(categories);
|
|
} catch (err) {
|
|
document.getElementById('tree-container').innerHTML =
|
|
`<div class="error">❌ ${err.message}</div>`;
|
|
}
|
|
}
|
|
|
|
function renderTree(categories) {
|
|
const container = document.getElementById('tree-container');
|
|
container.innerHTML = '';
|
|
const ul = document.createElement('ul');
|
|
ul.className = 'tree';
|
|
categories.forEach(cat => {
|
|
ul.appendChild(renderCategory(cat));
|
|
});
|
|
container.appendChild(ul);
|
|
}
|
|
|
|
function renderCategory(category) {
|
|
const li = document.createElement('li');
|
|
|
|
const div = document.createElement('div');
|
|
div.className = 'category';
|
|
|
|
const header = document.createElement('div');
|
|
header.className = 'category-header';
|
|
|
|
// Toggle for children
|
|
if (category.children && category.children.length > 0) {
|
|
const toggle = document.createElement('span');
|
|
toggle.className = 'toggle';
|
|
toggle.textContent = '▼';
|
|
header.appendChild(toggle);
|
|
}
|
|
|
|
// Image
|
|
if (category.kBild) {
|
|
const img = document.createElement('img');
|
|
img.className = 'category-image';
|
|
img.src = `/img/cat/${category.kBild}.avif`;
|
|
img.alt = category.cName;
|
|
img.onerror = () => img.style.display = 'none';
|
|
header.appendChild(img);
|
|
}
|
|
|
|
// Info
|
|
const info = document.createElement('div');
|
|
info.className = 'category-info';
|
|
|
|
const name = document.createElement('div');
|
|
name.className = 'category-name';
|
|
name.textContent = category.cName;
|
|
info.appendChild(name);
|
|
|
|
const count = document.createElement('div');
|
|
count.className = 'category-count';
|
|
count.textContent = `${category.articleCount} articles`;
|
|
info.appendChild(count);
|
|
|
|
header.appendChild(info);
|
|
div.appendChild(header);
|
|
|
|
// Children
|
|
if (category.children && category.children.length > 0) {
|
|
const childrenUl = document.createElement('ul');
|
|
childrenUl.className = 'children';
|
|
category.children.forEach(child => {
|
|
childrenUl.appendChild(renderCategory(child));
|
|
});
|
|
div.appendChild(childrenUl);
|
|
|
|
// Toggle functionality
|
|
div.addEventListener('click', (e) => {
|
|
if (e.target.closest('.children')) return;
|
|
e.stopPropagation();
|
|
childrenUl.classList.toggle('hidden');
|
|
const toggle = div.querySelector('.toggle');
|
|
if (toggle) {
|
|
toggle.textContent = childrenUl.classList.contains('hidden') ? '▶' : '▼';
|
|
}
|
|
});
|
|
}
|
|
|
|
li.appendChild(div);
|
|
return li;
|
|
}
|
|
|
|
loadCategories();
|
|
</script>
|
|
</body>
|
|
</html>
|