feat: admin panel dashboard layout with sidebar navigation

This commit is contained in:
Claus Lohmar 2026-07-08 14:35:50 +01:00
parent ee9e533485
commit 707eb9ec81

214
main.go
View file

@ -400,110 +400,180 @@ const adminHTML = `<!DOCTYPE html>
<title>Admin Panel NextWorkspace</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f2f5; color: #1a1a2e; display: flex; flex-direction: column; height: 100vh; }
header { background: linear-gradient(135deg, #1a1a2e, #16213e); color: #fff; padding: 1rem 2rem; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
header h1 { font-size: 1.3rem; }
header a { color: #63b3ed; text-decoration: none; font-size: 0.85rem; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f2f5; color: #1a1a2e; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
header { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); color: #fff; padding: 0.75rem 1.5rem; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
header h1 { font-size: 1.1rem; font-weight: 600; }
header .top-nav { display: flex; gap: 1.5rem; align-items: center; }
header .top-nav a { color: #a0aec0; text-decoration: none; font-size: 0.85rem; transition: color .15s; }
header .top-nav a:hover { color: #fff; }
.layout { display: flex; flex: 1; overflow: hidden; }
.sidebar { width: 220px; background: #fff; border-right: 1px solid #e2e8f0; padding: 1rem 0; flex-shrink: 0; overflow-y: auto; }
.sidebar a { display: block; padding: 0.6rem 1.25rem; color: #4a5568; text-decoration: none; font-size: 0.9rem; border-left: 3px solid transparent; }
.sidebar a:hover { background: #edf2f7; border-left-color: #63b3ed; color: #1a1a2e; }
.sidebar { width: 250px; background: #fff; border-right: 1px solid #e2e8f0; display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; }
.sidebar .section-label { padding: 1.25rem 1.25rem 0.4rem; font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #a0aec0; }
.sidebar a { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 1.25rem; color: #4a5568; text-decoration: none; font-size: 0.88rem; border-left: 3px solid transparent; transition: all .12s; }
.sidebar a:hover { background: #f7fafc; border-left-color: #63b3ed; color: #1a1a2e; }
.sidebar a.active { background: #ebf4ff; border-left-color: #1a1a2e; color: #1a1a2e; font-weight: 600; }
.sidebar .section { padding: 0.6rem 1.25rem 0.3rem; font-size: 0.7rem; text-transform: uppercase; color: #a0aec0; letter-spacing: 0.05em; font-weight: 600; }
.content { flex: 1; padding: 1.5rem; overflow-y: auto; }
.card { background: #fff; border-radius: 8px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
h2 { font-size: 1.2rem; margin-bottom: 1rem; color: #2d3748; }
.sidebar a .icon { width: 1.25rem; text-align: center; font-size: 1rem; opacity: .7; }
.sidebar a.disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }
.sidebar .spacer { flex: 1; }
.sidebar .footer { padding: 1rem 1.25rem; border-top: 1px solid #e2e8f0; font-size: 0.75rem; color: #a0aec0; }
.content { flex: 1; padding: 1.5rem 2rem; overflow-y: auto; background: #f8fafc; }
.page-header { margin-bottom: 1.5rem; }
.page-header h2 { font-size: 1.4rem; font-weight: 700; color: #1a1a2e; margin-bottom: 0.25rem; }
.page-header p { color: #718096; font-size: 0.9rem; }
.card { background: #fff; border-radius: 10px; padding: 1.5rem; margin-bottom: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid #edf2f7; }
.card h3 { font-size: 1rem; font-weight: 600; color: #2d3748; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid #e2e8f0; font-size: 0.9rem; }
th { color: #718096; font-weight: 600; }
.btn { display: inline-block; padding: 0.4rem 0.8rem; border-radius: 4px; text-decoration: none; font-size: 0.85rem; cursor: pointer; border: none; }
.btn-danger { background: #fc8181; color: #fff; }
.btn-danger:hover { background: #f56565; }
th { text-align: left; padding: 0.55rem 0.75rem; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #718096; border-bottom: 2px solid #edf2f7; }
td { padding: 0.65rem 0.75rem; font-size: 0.88rem; border-bottom: 1px solid #f7fafc; color: #4a5568; }
tr:hover td { background: #f7fafc; }
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.75rem; font-weight: 500; background: #edf2f7; color: #4a5568; margin-right: 0.2rem; }
.badge-green { background: #c6f6d5; color: #276749; }
.badge-red { background: #fed7d7; color: #c53030; }
.btn { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.45rem 0.9rem; border-radius: 6px; font-size: 0.85rem; font-weight: 500; cursor: pointer; border: none; text-decoration: none; transition: all .12s; }
.btn-primary { background: #1a1a2e; color: #fff; }
.btn-primary:hover { background: #2d3748; }
input, select { padding: 0.4rem 0.6rem; border: 1px solid #e2e8f0; border-radius: 4px; font-size: 0.9rem; }
.form-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.success { background: #c6f6d5; color: #276749; padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; }
.error { background: #fed7d7; color: #c53030; padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; }
.password-box { background: #1a1a2e; color: #63b3ed; padding: 0.75rem; border-radius: 4px; font-family: monospace; margin-top: 0.5rem; }
.btn-danger { background: #fff; color: #e53e3e; border: 1px solid #fed7d7; }
.btn-danger:hover { background: #fff5f5; }
.btn-ghost { background: transparent; color: #718096; border: 1px solid #e2e8f0; }
.btn-ghost:hover { background: #f7fafc; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
input, select { padding: 0.45rem 0.7rem; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 0.88rem; color: #4a5568; background: #fff; outline: none; transition: border .12s; }
input:focus, select:focus { border-color: #63b3ed; box-shadow: 0 0 0 2px rgba(99,179,237,0.15); }
.form-row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.success { background: #c6f6d5; color: #276749; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.88rem; border: 1px solid #9ae6b4; }
.error { background: #fed7d7; color: #c53030; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.88rem; border: 1px solid #feb2b2; }
.password-box { background: #1a1a2e; color: #63b3ed; padding: 0.65rem 1rem; border-radius: 6px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.85rem; margin-top: 0.5rem; display: inline-block; }
.hidden { display: none; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: #a0aec0; }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }
</style>
</head>
<body>
<header>
<h1>Admin Panel</h1>
<a href="/home/">Back to Launcher</a>
<h1>NextWorkspace · Admin</h1>
<div class="top-nav">
<a href="/home/">Launcher</a>
<a href="https://auth.nextwks.eu/logout" style="color:#fc8181;">Logout</a>
</div>
</header>
<div class="layout">
<nav class="sidebar">
<div class="section">Management</div>
<a href="#" class="active" onclick="return showSection('users')">Users</a>
<a href="#" onclick="return showSection('create')">Create User</a>
<div class="section">System</div>
<a href="#" onclick="return showSection('logs')">Logs</a>
<a href="#" onclick="return showSection('about')">About</a>
<div class="section-label">Core Settings</div>
<a href="#" class="active" data-section="global" onclick="return switchSection('global')"><span class="icon">&#9881;</span> Global</a>
<a href="#" data-section="access" onclick="return switchSection('access')"><span class="icon">&#128101;</span> Access</a>
<a href="#" data-section="security" onclick="return switchSection('security')"><span class="icon">&#128274;</span> Security</a>
<a href="#" data-section="domain" onclick="return switchSection('domain')"><span class="icon">&#127760;</span> Domain</a>
<div class="section-label">App Settings</div>
<a href="#" class="disabled"><span class="icon">&#128230;</span> Mail</a>
<a href="#" class="disabled"><span class="icon">&#128196;</span> Docs</a>
<a href="#" class="disabled"><span class="icon">&#128197;</span> Calendar</a>
<div class="spacer"></div>
<div class="footer">NextWorkspace v0.1.0.0011</div>
</nav>
<main class="content">
{{if .ApiError}}<div class="error">Could not fetch users from authelia-api (is it running on :8080?)</div>{{end}}
{{if .ApiError}}<div class="error">Could not connect to authelia-api on :8080</div>{{end}}
<div id="section-users" class="card">
<h2>Users</h2>
<table>
<thead><tr><th>Username</th><th>Display Name</th><th>Email</th><th>Groups</th><th>Action</th></tr></thead>
<tbody id="usersTable"></tbody>
</table>
<!-- Global -->
<div id="page-global" class="page">
<div class="page-header"><h2>Global Settings</h2><p>General system configuration for your workspace.</p></div>
<div class="card"><h3>System Information</h3><p style="color:#718096;font-size:0.9rem;">NextWorkspace is a self-hosted productivity suite powered by Caddy + Authelia.</p></div>
</div>
<div id="section-create" class="card hidden">
<h2>Create User</h2>
<form id="createForm" onsubmit="createUser(event)">
<div class="form-row">
<input name="username" placeholder="Username" required>
<input name="display_name" placeholder="Display Name" required>
<input name="email" placeholder="Email" type="email" required>
<select name="groups" multiple size="3">
<option value="users">users</option>
<option value="drive">drive</option>
<option value="office">office</option>
<option value="erp">erp</option>
<option value="chat">chat</option>
<option value="meet">meet</option>
<option value="mail">mail</option>
<option value="ai">ai</option>
</select>
<button type="submit" class="btn btn-primary">Create</button>
<!-- Access (Users) -->
<div id="page-access" class="page hidden">
<div class="page-header">
<h2>Access Management</h2>
<p>Manage users, groups, and authentication policies.</p>
</div>
<div class="card">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;">
<h3 style="margin:0;">Users</h3>
<button class="btn btn-primary btn-sm" onclick="switchSection('create')">+ Create User</button>
</div>
</form>
<div id="createResult"></div>
<table>
<thead><tr><th>Username</th><th>Display Name</th><th>Email</th><th>Groups</th><th>Status</th><th></th></tr></thead>
<tbody id="usersTable"></tbody>
</table>
<div id="accessEmpty" class="empty-state hidden">
<div class="icon">&#128101;</div>
<p>No users found. Create one to get started.</p>
</div>
</div>
<div id="page-create" class="hidden">
<div class="card">
<h3>Create User</h3>
<form id="createForm" onsubmit="createUser(event)">
<div class="form-row">
<input name="username" placeholder="Username" required style="width:180px;">
<input name="display_name" placeholder="Display Name" required style="width:200px;">
<input name="email" placeholder="Email" type="email" required style="width:220px;">
<select name="groups" multiple size="3" style="width:160px;">
<option value="users">users</option>
<option value="drive">drive</option>
<option value="office">office</option>
<option value="erp">erp</option>
<option value="chat">chat</option>
<option value="meet">meet</option>
<option value="mail">mail</option>
<option value="ai">ai</option>
</select>
<button type="submit" class="btn btn-primary">Create</button>
</div>
</form>
<div id="createResult"></div>
</div>
</div>
</div>
<div id="section-logs" class="card hidden">
<h2>System Logs</h2>
<p style="color:#718096;font-size:0.9rem;">Log viewer coming soon.</p>
<!-- Security -->
<div id="page-security" class="page hidden">
<div class="page-header"><h2>Security</h2><p>Authentication policies, tokens, and session configuration.</p></div>
<div class="card"><h3>Authentication</h3><p style="color:#718096;font-size:0.9rem;">Configured via Authelia. Policies enforced at the proxy level by Caddy.</p></div>
</div>
<div id="section-about" class="card hidden">
<h2>About</h2>
<p style="color:#718096;font-size:0.9rem;">NextWorkspace v0.1.0.0011</p>
<!-- Domain -->
<div id="page-domain" class="page hidden">
<div class="page-header"><h2>Domain</h2><p>Domain mapping, email configuration, and network settings.</p></div>
<div class="card"><h3>Domain Configuration</h3><p style="color:#718096;font-size:0.9rem;">Managed through Caddyfile and Authelia configuration.</p></div>
</div>
</main>
</div>
<script>
function showSection(name) {
let currentSection = 'global';
function switchSection(name) {
currentSection = name;
document.querySelectorAll('.sidebar a').forEach(a => a.classList.remove('active'));
event.target.classList.add('active');
document.querySelectorAll('.content > .card').forEach(c => c.classList.add('hidden'));
document.getElementById('section-' + name).classList.remove('hidden');
if (name === 'users') loadUsers();
document.querySelector('[data-section="' + name + '"]').classList.add('active');
document.querySelectorAll('.page').forEach(p => p.classList.add('hidden'));
const page = document.getElementById('page-' + name);
if (page) page.classList.remove('hidden');
if (name === 'access') loadUsers();
return false;
}
async function loadUsers() {
const resp = await fetch('/config?format=json');
if (!resp.ok) return;
const users = await resp.json();
const tbody = document.getElementById('usersTable');
tbody.innerHTML = users.map(u => '<tr><td>' + u.username + '</td><td>' + (u.display_name||'') + '</td><td>' + (u.email||'') + '</td><td>' + (u.groups||[]).join(', ') + '</td><td><button class="btn btn-danger" onclick="deleteUser(\'' + u.username + '\')">Delete</button></td></tr>').join('');
const empty = document.getElementById('accessEmpty');
if (!users || users.length === 0) {
tbody.innerHTML = '';
empty.classList.remove('hidden');
return;
}
empty.classList.add('hidden');
tbody.innerHTML = users.map(u => {
const groups = (u.groups||[]).map(g => '<span class="badge">' + g + '</span>').join('');
const status = u.disabled ? '<span class="badge badge-red">disabled</span>' : '<span class="badge badge-green">active</span>';
return '<tr><td><strong>' + u.username + '</strong></td><td>' + (u.display_name||'') + '</td><td>' + (u.email||'') + '</td><td>' + groups + '</td><td>' + status + '</td><td><button class="btn btn-danger btn-sm" onclick="deleteUser(\'' + u.username + '\')">Delete</button></td></tr>';
}).join('');
}
async function createUser(e) {
@ -517,7 +587,8 @@ const adminHTML = `<!DOCTYPE html>
const div = document.getElementById('createResult');
if (result.success) {
const pwd = (result.users && result.users[0] && result.users[0].placeholder_password) || 'check email';
div.innerHTML = '<div class="success">User created! <div class="password-box">Password: ' + pwd + '</div></div>';
div.innerHTML = '<div class="success">User created! <div class="password-box">Initial password: ' + pwd + '</div></div>';
setTimeout(() => div.innerHTML = '', 8000);
loadUsers();
} else {
div.innerHTML = '<div class="error">Error: ' + JSON.stringify(result) + '</div>';
@ -525,13 +596,14 @@ const adminHTML = `<!DOCTYPE html>
}
async function deleteUser(username) {
if (!confirm('Delete ' + username + '?')) return;
if (!confirm('Delete user "' + username + '"?')) return;
const resp = await fetch('/config?username=' + username, {method:'DELETE'});
if (resp.ok) loadUsers();
else alert('Delete failed: ' + await resp.text());
}
loadUsers();
// Load users on initial render if Access tab is active
if (document.querySelector('[data-section="access"].active')) loadUsers();
</script>
</body>
</html>`