fix: admin panel with vertical split layout (sidebar + content)
This commit is contained in:
parent
d699dd34c4
commit
ee9e533485
1 changed files with 78 additions and 45 deletions
123
main.go
123
main.go
|
|
@ -400,11 +400,17 @@ 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; }
|
||||
header { background: linear-gradient(135deg, #1a1a2e, #16213e); color: #fff; padding: 1.5rem 2rem; display: flex; justify-content: space-between; align-items: center; }
|
||||
header h1 { font-size: 1.5rem; }
|
||||
header a { color: #63b3ed; text-decoration: none; font-size: 0.9rem; }
|
||||
.container { max-width: 1000px; margin: 0 auto; padding: 2rem; }
|
||||
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; }
|
||||
.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 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; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
|
|
@ -412,13 +418,15 @@ const adminHTML = `<!DOCTYPE html>
|
|||
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; }
|
||||
.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; margin-right: 0.5rem; }
|
||||
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; }
|
||||
.hidden { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -426,42 +434,71 @@ const adminHTML = `<!DOCTYPE html>
|
|||
<h1>Admin Panel</h1>
|
||||
<a href="/home/">Back to Launcher</a>
|
||||
</header>
|
||||
<div class="container">
|
||||
{{if .ApiError}}<div class="error">Could not fetch users from authelia-api (is it running on :8080?)</div>{{end}}
|
||||
<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>
|
||||
</nav>
|
||||
<main class="content">
|
||||
{{if .ApiError}}<div class="error">Could not fetch users from authelia-api (is it running on :8080?)</div>{{end}}
|
||||
|
||||
<div class="card">
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
<div id="createResult"></div>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div 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>
|
||||
</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>
|
||||
</div>
|
||||
</form>
|
||||
<div id="createResult"></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>
|
||||
</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>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function showSection(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();
|
||||
return false;
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
const resp = await fetch('/config?format=json');
|
||||
const users = await resp.json();
|
||||
|
|
@ -475,11 +512,7 @@ const adminHTML = `<!DOCTYPE html>
|
|||
const data = Object.fromEntries(new FormData(form));
|
||||
data.groups = Array.from(form.querySelector('[name=groups]').selectedOptions).map(o => o.value);
|
||||
if (!data.groups.length) data.groups = ['users'];
|
||||
const resp = await fetch('/config', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({users: [data]})
|
||||
});
|
||||
const resp = await fetch('/config', {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({users:[data]})});
|
||||
const result = await resp.json();
|
||||
const div = document.getElementById('createResult');
|
||||
if (result.success) {
|
||||
|
|
@ -493,9 +526,9 @@ const adminHTML = `<!DOCTYPE html>
|
|||
|
||||
async function deleteUser(username) {
|
||||
if (!confirm('Delete ' + username + '?')) return;
|
||||
const resp = await fetch('/config?username=' + username, {method: 'DELETE'});
|
||||
if (resp.ok) { loadUsers(); }
|
||||
else { alert('Delete failed: ' + await resp.text()); }
|
||||
const resp = await fetch('/config?username=' + username, {method:'DELETE'});
|
||||
if (resp.ok) loadUsers();
|
||||
else alert('Delete failed: ' + await resp.text());
|
||||
}
|
||||
|
||||
loadUsers();
|
||||
|
|
|
|||
Loading…
Reference in a new issue