vumichien's picture
Up
4e2a6d5
raw
history blame
10.8 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel - Signal Tracker</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h1>Admin Panel</h1>
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Is Admin</th>
<th>Last Login</th>
<th>Is Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.username }}</td>
<td>{{ user.email }}</td>
<td>{{ user.is_admin }}</td>
<td>{{ user.last_login.strftime('%Y-%m-%d %H:%M:%S') if user.last_login else 'Never' }}</td>
<td>{{ user.is_active }}</td>
<td>
<button class="btn btn-sm btn-primary" onclick="editUser('{{ user.username }}', '{{ user.email }}', {{ user.is_admin | tojson }}, {{ user.is_active | tojson }})">Edit</button>
<form method="post" action="/admin/delete/{{ user.username }}" style="display: inline;">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<h2>Devices</h2>
<button class="btn btn-success mb-3" onclick="addDevice()">Add Device</button>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Device ID</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for device in devices %}
<tr>
<td>{{ device.name }}</td>
<td>{{ device.description }}</td>
<td>{{ device.device_id }}</td>
<td>
<button class="btn btn-sm btn-primary" onclick="editDevice('{{ device.name }}', '{{ device.description }}', '{{ device.device_id }}')">Edit</button>
<form method="post" action="/admin/delete_device/{{ device.device_id }}" style="display: inline;">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="/" class="btn btn-secondary">Back to Map</a>
</div>
<!-- Edit User Modal -->
<div class="modal fade" id="editUserModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="editUserForm" method="post">
<div class="modal-body">
<div class="mb-3">
<label for="editUsername" class="form-label">Username</label>
<input type="text" class="form-control" id="editUsername" name="new_username" required>
</div>
<div class="mb-3">
<label for="editEmail" class="form-label">Email</label>
<input type="email" class="form-control" id="editEmail" name="email" required>
</div>
<div class="mb-3 form-check">
<input type="hidden" name="is_admin" value="false">
<input type="checkbox" class="form-check-input" id="editIsAdmin" name="is_admin" value="true">
<label class="form-check-label" for="editIsAdmin">Is Admin</label>
</div>
<div class="mb-3 form-check">
<input type="hidden" name="is_active" value="false">
<input type="checkbox" class="form-check-input" id="editIsActive" name="is_active" value="true">
<label class="form-check-label" for="editIsActive">Is Active</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<!-- Add Device Modal -->
<div class="modal fade" id="addDeviceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add Device</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="addDeviceForm" method="post" action="/admin/add_device">
<div class="modal-body">
<div class="mb-3">
<label for="deviceName" class="form-label">Name</label>
<input type="text" class="form-control" id="deviceName" name="name" required>
</div>
<div class="mb-3">
<label for="deviceDescription" class="form-label">Description</label>
<input type="text" class="form-control" id="deviceDescription" name="description" required>
</div>
<div class="mb-3">
<label for="deviceId" class="form-label">Device ID</label>
<input type="text" class="form-control" id="deviceId" name="device_id" required>
</div>
<div class="mb-3">
<label for="devicePassword" class="form-label">Password</label>
<input type="password" class="form-control" id="devicePassword" name="password" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add Device</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Device Modal -->
<div class="modal fade" id="editDeviceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Device</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="editDeviceForm" method="post">
<div class="modal-body">
<div class="mb-3">
<label for="editDeviceName" class="form-label">Name</label>
<input type="text" class="form-control" id="editDeviceName" name="name" required>
</div>
<div class="mb-3">
<label for="editDeviceDescription" class="form-label">Description</label>
<input type="text" class="form-control" id="editDeviceDescription" name="description" required>
</div>
<div class="mb-3">
<label for="editDeviceId" class="form-label">Device ID</label>
<input type="text" class="form-control" id="editDeviceId" name="new_device_id" required>
</div>
<div class="mb-3">
<label for="editDevicePassword" class="form-label">Password</label>
<input type="password" class="form-control" id="editDevicePassword" name="password" placeholder="Leave blank to keep current password">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
function editUser(username, email, isAdmin, isActive) {
document.getElementById('editUserForm').action = `/admin/edit/${username}`;
document.getElementById('editUsername').value = username;
document.getElementById('editEmail').value = email;
document.getElementById('editIsAdmin').checked = isAdmin;
document.getElementById('editIsActive').checked = isActive;
var editUserModal = new bootstrap.Modal(document.getElementById('editUserModal'));
editUserModal.show();
}
function addDevice() {
var addDeviceModal = new bootstrap.Modal(document.getElementById('addDeviceModal'));
addDeviceModal.show();
}
function editDevice(name, description, deviceId) {
document.getElementById('editDeviceForm').action = `/admin/edit_device/${deviceId}`;
document.getElementById('editDeviceName').value = name;
document.getElementById('editDeviceDescription').value = description;
document.getElementById('editDeviceId').value = deviceId;
document.getElementById('editDevicePassword').value = ''; // Clear password field for security
var editDeviceModal = new bootstrap.Modal(document.getElementById('editDeviceModal'));
editDeviceModal.show();
}
</script>
</body>
</html>