+87
-14
@@ -30,22 +30,25 @@ let editingNodeId = null;
|
||||
let editingShapeId = null;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
canvas = document.getElementById('networkCanvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
resizeCanvas();
|
||||
// Check auth first
|
||||
checkSession().then(() => {
|
||||
canvas = document.getElementById('networkCanvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
resizeCanvas();
|
||||
|
||||
loadTeams().then(() => loadEvents());
|
||||
loadNetworkData();
|
||||
loadTeams().then(() => loadEvents());
|
||||
loadNetworkData();
|
||||
|
||||
document.getElementById('saveEvent').addEventListener('click', saveEvent);
|
||||
document.getElementById('saveNode').addEventListener('click', saveNode);
|
||||
document.getElementById('saveLink').addEventListener('click', saveLink);
|
||||
document.getElementById('saveShape').addEventListener('click', saveShape);
|
||||
document.getElementById('teamFilter').addEventListener('change', renderTimeline);
|
||||
document.getElementById('searchEvents').addEventListener('input', renderTimeline);
|
||||
document.getElementById('shapeOpacity').addEventListener('input', (e) => {
|
||||
document.getElementById('opacityVal').textContent = parseFloat(e.target.value).toFixed(2);
|
||||
});
|
||||
document.getElementById('saveEvent').addEventListener('click', saveEvent);
|
||||
document.getElementById('saveNode').addEventListener('click', saveNode);
|
||||
document.getElementById('saveLink').addEventListener('click', saveLink);
|
||||
document.getElementById('saveShape').addEventListener('click', saveShape);
|
||||
document.getElementById('addUserBtn').addEventListener('click', addUser);
|
||||
document.getElementById('teamFilter').addEventListener('change', renderTimeline);
|
||||
document.getElementById('searchEvents').addEventListener('input', renderTimeline);
|
||||
document.getElementById('shapeOpacity').addEventListener('input', (e) => {
|
||||
document.getElementById('opacityVal').textContent = parseFloat(e.target.value).toFixed(2);
|
||||
});
|
||||
|
||||
canvas.addEventListener('mousedown', onMouseDown);
|
||||
canvas.addEventListener('mousemove', onMouseMove);
|
||||
@@ -882,6 +885,76 @@ function esc(s) {
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// ==================== AUTH / SESSION ====================
|
||||
let currentUser = null;
|
||||
let currentRole = null;
|
||||
|
||||
async function checkSession() {
|
||||
try {
|
||||
const res = await fetch('/api/session');
|
||||
const data = await res.json();
|
||||
if (data.loggedin) {
|
||||
currentUser = data.username;
|
||||
currentRole = data.role;
|
||||
document.getElementById('userDisplay').textContent = data.username;
|
||||
if (data.role === 'admin' || data.admin_count === 0) {
|
||||
document.getElementById('settingsBtn').classList.remove('d-none');
|
||||
}
|
||||
} else {
|
||||
window.location.href = '/login.php';
|
||||
}
|
||||
} catch (e) {
|
||||
window.location.href = '/login.php';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
const list = document.getElementById('userList');
|
||||
try {
|
||||
const users = await apiFetch('settings');
|
||||
list.innerHTML = users.map(u => `
|
||||
<div class="d-flex justify-content-between align-items-center py-1 border-bottom border-secondary">
|
||||
<div>
|
||||
<strong class="small">${esc(u.username)}</strong>
|
||||
<span class="badge bg-${u.role === 'admin' ? 'warning' : 'secondary'} ms-1" style="font-size:.6rem;">${u.role}</span>
|
||||
<div class="text-secondary" style="font-size:.7rem;">${u.user_token.substring(0, 16)}...</div>
|
||||
</div>
|
||||
${u.role !== 'admin' ? `<button class="btn btn-outline-danger btn-sm py-0 px-1" onclick="removeUser(${u.id})"><i class="fas fa-times" style="font-size:.7rem;"></i></button>` : ''}
|
||||
</div>
|
||||
`).join('');
|
||||
} catch (e) {
|
||||
list.innerHTML = '<div class="text-danger small">Failed to load users</div>';
|
||||
}
|
||||
}
|
||||
|
||||
async function addUser() {
|
||||
const token = document.getElementById('addUserToken').value.trim();
|
||||
if (!token) return;
|
||||
try {
|
||||
const res = await apiFetch('settings', { method: 'POST', body: JSON.stringify({ user_token: token }) });
|
||||
if (res.status === 'success') {
|
||||
document.getElementById('addUserToken').value = '';
|
||||
loadUsers();
|
||||
} else {
|
||||
alert(res.error || 'Failed to add user');
|
||||
}
|
||||
} catch (e) {
|
||||
alert('Failed to add user');
|
||||
}
|
||||
}
|
||||
|
||||
async function removeUser(id) {
|
||||
if (!confirm('Remove this user?')) return;
|
||||
try {
|
||||
await apiFetch('settings', { method: 'DELETE', body: JSON.stringify({ id }) });
|
||||
loadUsers();
|
||||
} catch (e) {
|
||||
alert('Failed to remove user');
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('settingsModal').addEventListener('show.bs.modal', loadUsers);
|
||||
|
||||
if (!CanvasRenderingContext2D.prototype.roundRect) {
|
||||
CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
|
||||
if (r > w / 2) r = w / 2;
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="ms-auto d-flex align-items-center">
|
||||
<span class="text-secondary small me-2" id="userDisplay"></span>
|
||||
<button class="btn btn-outline-secondary btn-sm me-2 d-none" id="settingsBtn" data-bs-toggle="modal" data-bs-target="#settingsModal" title="Settings"><i class="fas fa-cog"></i></button>
|
||||
<a href="/logout.php" class="btn btn-outline-secondary btn-sm"><i class="fas fa-sign-out-alt"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -329,6 +334,31 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ==================== SETTINGS MODAL ==================== -->
|
||||
<div class="modal fade" id="settingsModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header border-secondary">
|
||||
<h5 class="modal-title"><i class="fas fa-cog text-primary me-1"></i> Settings</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h6 class="text-secondary mb-2"><i class="fas fa-users me-1"></i> Authorized Users</h6>
|
||||
<div id="userList" class="mb-3">
|
||||
<div class="text-secondary small">Loading...</div>
|
||||
</div>
|
||||
<hr class="border-secondary">
|
||||
<h6 class="text-secondary mb-2"><i class="fas fa-user-plus me-1"></i> Add User by Token</h6>
|
||||
<div class="input-group input-group-sm mb-2">
|
||||
<input type="text" class="form-control" id="addUserToken" placeholder="Paste user token here">
|
||||
<button class="btn btn-primary" id="addUserBtn"><i class="fas fa-plus"></i> Add</button>
|
||||
</div>
|
||||
<small class="text-secondary">Get the user token from the user's Jakach Auth profile or ask them to log in once.</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ==================== CONFIRM MODAL ==================== -->
|
||||
<div class="modal fade" id="confirmModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-sm modal-dialog-centered">
|
||||
|
||||
Reference in New Issue
Block a user