Files
2026-10-07 17:31:08 +05:30

179 lines
4.8 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Admin Dashboard – AI Infinite</title>
<!-- Google Font -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap"
rel="stylesheet"
/>
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"
rel="stylesheet"
/>
<!-- DataTables CSS -->
<link
href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css"
rel="stylesheet"
/>
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #f0f2f5;
padding: 2rem;
}
h2 {
color: #007BFF;
margin-bottom: 1.5rem;
font-weight: 700;
}
.dataTables_wrapper .dataTables_filter input {
width: 250px;
margin-left: 0.5rem;
}
.alert-fixed {
position: fixed;
top: 1rem;
right: 1rem;
z-index: 1050;
}
</style>
</head>
<body>
<div class="container-fluid">
<h2>Admin Dashboard</h2>
<!-- Alert placeholder -->
<div id="alert-area"></div>
<table
id="users-table"
class="table table-striped table-bordered align-middle"
style="width:100%"
>
<thead class="table-primary">
<tr>
<th>Username</th>
<th>Email</th>
<th>Phone</th>
<th>Invoices<br>Extracted</th>
<th>API Key</th>
<th>Account Limit</th>
<th>Update</th>
</tr>
</thead>
<tbody>
{% for user in user_activity %}
<tr>
<td>{{ user.username }}</td>
<td>{{ user.email }}</td>
<td>{{ user.phone or '—' }}</td>
<td>{{ user.invoices_extracted }}</td>
<td>
{% if user.api_keys %}
<code>{{ user.api_keys[0].api_key }}</code>
{% else %}
<em>N/A</em>
{% endif %}
</td>
<td>
<input
type="number"
id="limit-{{ user.user_id }}"
class="form-control form-control-sm text-center"
value="{{ user.account_limit }}"
min="1"
/>
</td>
<td class="text-center">
<button
class="btn btn-sm btn-success"
onclick="updateUserLimit('{{ user.user_id }}')"
>
Update
</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ url_for('logout') }}" class="btn btn-danger mt-3">
<i class="fas fa-sign-out-alt"></i> Logout
</a>
</div>
<!-- JS dependencies -->
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
></script>
<script
src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"
></script>
<script
src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"
></script>
<script>
// Initialize DataTable
$(document).ready(function() {
$('#users-table').DataTable({
pageLength: 10,
lengthChange: false,
language: {
search: "<strong>Filter:</strong>"
},
columnDefs: [
{ orderable: false, targets: [2,5,6] } // disable sort on Phone, Limit, Update
]
});
});
// Show bootstrap alert
function showAlert(type, message) {
const html = `
<div class="alert alert-${type} alert-dismissible fade show alert-fixed" role="alert">
${message}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>`;
$('#alert-area').append(html);
setTimeout(() => {
$('.alert-fixed').alert('close');
}, 3000);
}
// AJAX update
function updateUserLimit(userId) {
const newLimit = $('#limit-' + userId).val();
if (newLimit < 1) {
showAlert('danger', 'Limit must be ≥ 1');
return;
}
fetch('/admin/update-user-limit', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: userId, new_account_limit: newLimit })
})
.then(res => res.json())
.then(data => {
if (data.message) {
showAlert('success', data.message);
} else {
showAlert('danger', data.error || 'Update failed');
}
})
.catch(err => {
console.error(err);
showAlert('danger', 'Network error');
});
}
</script>
</body>
</html>