mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-20 13:30:51 +02:00
feat: Update dependencies and enhance admin role management
- Upgraded `golang.org/x/crypto` to v0.36.0 and other indirect dependencies to their latest versions. - Added functionality to assign admin roles to users upon creation in the main application logic. - Introduced new templates for admin role management, including forms for creating and editing roles. - Removed deprecated admin tools template to streamline the admin interface. - Added audit logging for role changes to improve tracking and accountability.
This commit is contained in:
+196
-106
@@ -16,84 +16,29 @@ type BackupFile struct {
|
||||
// AdminDatabaseTools renders the database tools page with backup and restore functionality
|
||||
templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
@LayoutWithContext("Database Tools", ctx) {
|
||||
<div class="flex flex-col md:flex-row bg-gray-50 dark:bg-gray-900 min-h-screen">
|
||||
<!-- Sidebar Navigation -->
|
||||
<nav class="md:w-64 md:min-h-screen bg-white border-r border-gray-200 dark:bg-gray-800 dark:border-gray-700">
|
||||
<div class="p-4 overflow-y-auto">
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Admin Console</h2>
|
||||
<ul class="space-y-2">
|
||||
<li>
|
||||
<a href="/admin" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
|
||||
<i class="fas fa-tachometer-alt w-5 h-5 text-gray-500 dark:text-gray-400 mr-3"></i>
|
||||
Dashboard
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/users" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
|
||||
<i class="fas fa-users w-5 h-5 text-gray-500 dark:text-gray-400 mr-3"></i>
|
||||
User Management
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/roles" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
|
||||
<i class="fas fa-user-shield w-5 h-5 text-gray-500 dark:text-gray-400 mr-3"></i>
|
||||
Role Management
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/audit" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
|
||||
<i class="fas fa-clipboard-list w-5 h-5 text-gray-500 dark:text-gray-400 mr-3"></i>
|
||||
Audit Logs
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/database" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white bg-gray-100 dark:bg-gray-700 group">
|
||||
<i class="fas fa-database w-5 h-5 text-gray-500 dark:text-gray-400 mr-3"></i>
|
||||
Database Tools
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/settings" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
|
||||
<i class="fas fa-cog w-5 h-5 text-gray-500 dark:text-gray-400 mr-3"></i>
|
||||
System Settings
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="flex-1 p-8">
|
||||
<!-- Header -->
|
||||
<div class="mb-6">
|
||||
<div id="database-tools-container" style="min-height: 100vh;" class="database-tools-page bg-gray-50 dark:bg-gray-900">
|
||||
<div class="pb-8 w-full">
|
||||
<!-- Page Header -->
|
||||
<div class="mb-6 flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||||
<h1 class="text-2xl font-bold text-gray-900 dark:text-white flex items-center">
|
||||
<i class="fas fa-database w-6 h-6 mr-2 text-blue-500 dark:text-blue-400"></i>
|
||||
Database Management
|
||||
Database Tools
|
||||
</h1>
|
||||
<p class="mt-2 text-gray-600 dark:text-gray-400">Manage database backups, restoration and maintenance</p>
|
||||
<form id="backup-form" method="POST" action="/admin/database/backup-database">
|
||||
<button type="submit" class="flex items-center justify-center text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg px-5 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
|
||||
<i class="fas fa-download w-4 h-4 mr-2"></i>
|
||||
Create Backup
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Database Actions Cards -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
|
||||
<!-- Backup Database Card -->
|
||||
<div class="bg-white p-6 rounded-lg shadow-sm dark:bg-gray-800">
|
||||
<div class="flex items-center mb-4">
|
||||
<div class="bg-blue-100 p-3 rounded-full dark:bg-blue-900 mr-4">
|
||||
<i class="fas fa-save text-blue-500 w-6 h-6 dark:text-blue-300"></i>
|
||||
</div>
|
||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Backup Database</h3>
|
||||
</div>
|
||||
<p class="text-gray-600 dark:text-gray-400 mb-4">Create a backup of the current database state.</p>
|
||||
<form method="POST" action="/admin/backup-database">
|
||||
<button type="submit" class="w-full px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-blue-700 dark:hover:bg-blue-800">
|
||||
<i class="fas fa-download mr-2"></i>
|
||||
Create Backup
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<!-- Status and Error Messages -->
|
||||
<div id="toast-container" class="fixed top-5 right-5 z-50 flex flex-col gap-2"></div>
|
||||
|
||||
<!-- Vacuum Database Card -->
|
||||
<div class="bg-white p-6 rounded-lg shadow-sm dark:bg-gray-800">
|
||||
<!-- Action Cards Grid -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
|
||||
<!-- Optimize Database Card -->
|
||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6 dark:bg-gray-800 dark:border-gray-700">
|
||||
<div class="flex items-center mb-4">
|
||||
<div class="bg-purple-100 p-3 rounded-full dark:bg-purple-900 mr-4">
|
||||
<i class="fas fa-broom text-purple-500 w-6 h-6 dark:text-purple-300"></i>
|
||||
@@ -101,7 +46,7 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Optimize Database</h3>
|
||||
</div>
|
||||
<p class="text-gray-600 dark:text-gray-400 mb-4">Vacuum the database to reclaim space and optimize performance.</p>
|
||||
<form method="POST" action="/admin/vacuum-database">
|
||||
<form id="vacuum-form" method="POST" action="/admin/database/vacuum-database">
|
||||
<button type="submit" class="w-full px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 dark:bg-purple-700 dark:hover:bg-purple-800">
|
||||
<i class="fas fa-magic mr-2"></i>
|
||||
Optimize Database
|
||||
@@ -110,7 +55,7 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
</div>
|
||||
|
||||
<!-- Clear Job History Card -->
|
||||
<div class="bg-white p-6 rounded-lg shadow-sm dark:bg-gray-800">
|
||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6 dark:bg-gray-800 dark:border-gray-700">
|
||||
<div class="flex items-center mb-4">
|
||||
<div class="bg-orange-100 p-3 rounded-full dark:bg-orange-900 mr-4">
|
||||
<i class="fas fa-eraser text-orange-500 w-6 h-6 dark:text-orange-300"></i>
|
||||
@@ -118,7 +63,7 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Clear Job History</h3>
|
||||
</div>
|
||||
<p class="text-gray-600 dark:text-gray-400 mb-4">Remove old job history records to free up database space.</p>
|
||||
<form method="POST" action="/admin/clear-job-history">
|
||||
<form id="clear-job-form" method="POST" action="/admin/database/clear-job-history">
|
||||
<button type="submit" class="w-full px-4 py-2 bg-orange-600 text-white rounded-lg hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-orange-500 dark:bg-orange-700 dark:hover:bg-orange-800">
|
||||
<i class="fas fa-trash-alt mr-2"></i>
|
||||
Clear Job History
|
||||
@@ -127,7 +72,7 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
</div>
|
||||
|
||||
<!-- Export Configuration Card -->
|
||||
<div class="bg-white p-6 rounded-lg shadow-sm dark:bg-gray-800">
|
||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-6 dark:bg-gray-800 dark:border-gray-700">
|
||||
<div class="flex items-center mb-4">
|
||||
<div class="bg-green-100 p-3 rounded-full dark:bg-green-900 mr-4">
|
||||
<i class="fas fa-file-export text-green-500 w-6 h-6 dark:text-green-300"></i>
|
||||
@@ -149,10 +94,10 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
</div>
|
||||
|
||||
<!-- Database Backup List -->
|
||||
<div class="bg-white rounded-lg shadow-sm dark:bg-gray-800 mt-8">
|
||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 dark:bg-gray-800">
|
||||
<div class="p-6 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center">
|
||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Database Backups</h3>
|
||||
<a href="/admin/refresh-backups" class="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300">
|
||||
<a href="/admin/database/refresh-backups" class="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300">
|
||||
<i class="fas fa-sync-alt mr-1"></i>
|
||||
Refresh
|
||||
</a>
|
||||
@@ -182,22 +127,17 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">{ backup.Created.Format("2006-01-02 15:04:05") }</td>
|
||||
<td class="px-6 py-4 text-sm text-right">
|
||||
<div class="flex items-center justify-end space-x-2">
|
||||
<!-- Restore Button -->
|
||||
<button type="button"
|
||||
data-modal-target="confirm-restore-modal"
|
||||
data-modal-toggle="confirm-restore-modal"
|
||||
data-backup-name={ backup.Name }
|
||||
class="text-green-600 hover:text-green-900 dark:text-green-400 dark:hover:text-green-300">
|
||||
class="text-yellow-600 hover:text-yellow-900 dark:text-yellow-400 dark:hover:text-yellow-300">
|
||||
<i class="fas fa-undo-alt"></i>
|
||||
</button>
|
||||
|
||||
<!-- Download Button -->
|
||||
<a href={ templ.SafeURL("/admin/download-backup/" + backup.Name) }
|
||||
<a href={ templ.SafeURL("/admin/database/download-backup/" + backup.Name) }
|
||||
class="text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300">
|
||||
<i class="fas fa-download"></i>
|
||||
</a>
|
||||
|
||||
<!-- Delete Button -->
|
||||
<button type="button"
|
||||
data-modal-target="confirm-delete-modal"
|
||||
data-modal-toggle="confirm-delete-modal"
|
||||
@@ -215,13 +155,13 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Upload Backup File -->
|
||||
<div class="bg-white rounded-lg shadow-sm dark:bg-gray-800 mt-8">
|
||||
<!-- Upload Backup Section -->
|
||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 dark:bg-gray-800 mt-8">
|
||||
<div class="p-6 border-b border-gray-200 dark:border-gray-700">
|
||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Restore from Backup File</h3>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<form method="POST" action="/admin/restore-database" enctype="multipart/form-data">
|
||||
<form id="upload-backup-form" method="POST" action="/admin/database/restore-database" enctype="multipart/form-data">
|
||||
<div class="mb-4">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Upload Backup File</label>
|
||||
<div class="flex items-center justify-center w-full">
|
||||
@@ -245,13 +185,15 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Warning Section -->
|
||||
<div class="p-4 mt-8 bg-yellow-50 border border-yellow-200 rounded-lg text-yellow-800 dark:bg-yellow-900/30 dark:border-yellow-800 dark:text-yellow-300">
|
||||
<div class="flex">
|
||||
<i class="fas fa-exclamation-triangle flex-shrink-0 w-5 h-5 mr-3"></i>
|
||||
<div>
|
||||
<h3 class="text-sm font-medium mb-2">Important Safety Information</h3>
|
||||
<ul class="text-sm space-y-1 list-disc list-inside">
|
||||
<!-- Help Section -->
|
||||
<div class="bg-gray-50 dark:bg-gray-800 rounded-lg shadow-sm mt-8 p-4 border border-gray-200 dark:border-gray-700">
|
||||
<div class="flex items-start mb-2">
|
||||
<div class="flex items-center h-5">
|
||||
<i class="fas fa-info-circle w-4 h-4 text-blue-500 dark:text-blue-400 mr-2"></i>
|
||||
</div>
|
||||
<div class="ml-2 text-sm">
|
||||
<h4 class="font-medium text-gray-900 dark:text-white">Important Safety Information</h4>
|
||||
<ul class="mt-2 text-gray-600 dark:text-gray-400 space-y-1 list-disc list-inside">
|
||||
<li>Always create a backup before making significant changes</li>
|
||||
<li>Restoring a backup will overwrite all current data</li>
|
||||
<li>Database optimization may take time for large databases</li>
|
||||
@@ -264,13 +206,13 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
</div>
|
||||
|
||||
<!-- Restore Confirmation Modal -->
|
||||
<div id="confirm-restore-modal" tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
||||
<div class="relative p-4 w-full max-w-md max-h-full">
|
||||
<div id="confirm-restore-modal" tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full bg-gray-900/50 dark:bg-gray-900/80 backdrop-blur-sm">
|
||||
<div class="relative p-4 w-full max-w-md max-h-full mx-auto">
|
||||
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
||||
<div class="p-4 md:p-5 text-center">
|
||||
<i class="fas fa-exclamation-triangle mx-auto mb-4 text-yellow-400 text-3xl"></i>
|
||||
<div class="p-6 text-center">
|
||||
<i class="fas fa-exclamation-triangle text-yellow-400 text-3xl mb-4"></i>
|
||||
<h3 class="mb-5 text-lg font-normal text-gray-500 dark:text-gray-400">Are you sure you want to restore this backup? This will overwrite your current database.</h3>
|
||||
<form method="POST" id="restore-form" action="/admin/restore-database">
|
||||
<form method="POST" id="restore-form" action="/admin/database/restore-database">
|
||||
<input type="hidden" name="filename" id="restore-filename" value="" />
|
||||
<button type="submit" class="text-white bg-yellow-600 hover:bg-yellow-800 focus:ring-4 focus:outline-none focus:ring-yellow-300 dark:focus:ring-yellow-800 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center mr-2">
|
||||
Yes, restore it
|
||||
@@ -285,11 +227,11 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div id="confirm-delete-modal" tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
||||
<div class="relative p-4 w-full max-w-md max-h-full">
|
||||
<div id="confirm-delete-modal" tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full bg-gray-900/50 dark:bg-gray-900/80 backdrop-blur-sm">
|
||||
<div class="relative p-4 w-full max-w-md max-h-full mx-auto">
|
||||
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
||||
<div class="p-4 md:p-5 text-center">
|
||||
<i class="fas fa-trash-alt mx-auto mb-4 text-red-400 text-3xl"></i>
|
||||
<div class="p-6 text-center">
|
||||
<i class="fas fa-trash-alt text-red-400 text-3xl mb-4"></i>
|
||||
<h3 class="mb-5 text-lg font-normal text-gray-500 dark:text-gray-400">Are you sure you want to delete this backup file?</h3>
|
||||
<form method="POST" id="delete-form" action="">
|
||||
<button type="submit" class="text-white bg-red-600 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 dark:focus:ring-red-800 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center mr-2">
|
||||
@@ -307,12 +249,104 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
<script>
|
||||
// Handle restore modal
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Parse URL parameters for error and status messages
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const errorParam = urlParams.get('error');
|
||||
const detailsParam = urlParams.get('details');
|
||||
const statusParam = urlParams.get('status');
|
||||
|
||||
// Function to create and show a toast
|
||||
function showToast(message, type) {
|
||||
const toastContainer = document.getElementById('toast-container');
|
||||
|
||||
// Create toast element
|
||||
const toast = document.createElement('div');
|
||||
toast.id = 'toast-' + type + '-' + Date.now();
|
||||
toast.className = 'flex items-center w-full max-w-xs p-4 mb-4 rounded-lg shadow text-gray-500 bg-white dark:text-gray-400 dark:bg-gray-800';
|
||||
toast.role = 'alert';
|
||||
|
||||
// Set toast content based on type
|
||||
let iconClass, bgColorClass, textColorClass;
|
||||
|
||||
if (type === 'success') {
|
||||
iconClass = 'text-green-500 bg-green-100 dark:bg-green-800 dark:text-green-200';
|
||||
bgColorClass = 'text-green-500 dark:text-green-200';
|
||||
textColorClass = 'text-green-500 dark:text-green-200';
|
||||
} else if (type === 'error') {
|
||||
iconClass = 'text-red-500 bg-red-100 dark:bg-red-800 dark:text-red-200';
|
||||
bgColorClass = 'text-red-500 dark:text-red-200';
|
||||
textColorClass = 'text-red-500 dark:text-red-200';
|
||||
} else {
|
||||
iconClass = 'text-blue-500 bg-blue-100 dark:bg-blue-800 dark:text-blue-200';
|
||||
bgColorClass = 'text-blue-500 dark:text-blue-200';
|
||||
textColorClass = 'text-blue-500 dark:text-blue-200';
|
||||
}
|
||||
|
||||
// Set inner HTML with appropriate icon and message
|
||||
toast.innerHTML = `
|
||||
<div class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 rounded-lg ${iconClass}">
|
||||
${type === 'success'
|
||||
? '<i class="fas fa-check"></i>'
|
||||
: type === 'error'
|
||||
? '<i class="fas fa-exclamation-circle"></i>'
|
||||
: '<i class="fas fa-info-circle"></i>'}
|
||||
</div>
|
||||
<div class="ml-3 text-sm font-normal">${message}</div>
|
||||
<button type="button" class="ml-auto -mx-1.5 -my-1.5 bg-white text-gray-400 hover:text-gray-900 rounded-lg focus:ring-2 focus:ring-gray-300 p-1.5 hover:bg-gray-100 inline-flex h-8 w-8 dark:text-gray-500 dark:hover:text-white dark:bg-gray-800 dark:hover:bg-gray-700" data-dismiss-target="#${toast.id}" aria-label="Close">
|
||||
<span class="sr-only">Close</span>
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
`;
|
||||
|
||||
// Add toast to container
|
||||
toastContainer.appendChild(toast);
|
||||
|
||||
// Add event listener to close button
|
||||
const closeButton = toast.querySelector('button[data-dismiss-target]');
|
||||
closeButton.addEventListener('click', function() {
|
||||
toast.remove();
|
||||
});
|
||||
|
||||
// Auto-remove toast after 5 seconds
|
||||
setTimeout(() => {
|
||||
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
|
||||
setTimeout(() => {
|
||||
toast.remove();
|
||||
}, 300);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// Display error message if present
|
||||
if (errorParam) {
|
||||
const errorMessage = decodeURIComponent(errorParam).replace(/\+/g, ' ');
|
||||
let details = '';
|
||||
|
||||
if (detailsParam) {
|
||||
details = decodeURIComponent(detailsParam).replace(/\+/g, ' ');
|
||||
}
|
||||
|
||||
const fullMessage = details ? `${errorMessage}: ${details}` : errorMessage;
|
||||
showToast(fullMessage, 'error');
|
||||
}
|
||||
|
||||
// Display status message if present
|
||||
if (statusParam) {
|
||||
const statusMessage = decodeURIComponent(statusParam).replace(/\+/g, ' ');
|
||||
showToast(statusMessage, 'success');
|
||||
}
|
||||
|
||||
// Display modals when buttons are clicked
|
||||
const restoreButtons = document.querySelectorAll('[data-modal-target="confirm-restore-modal"]');
|
||||
restoreButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const backupName = this.getAttribute('data-backup-name');
|
||||
document.getElementById('restore-filename').value = backupName;
|
||||
document.getElementById('restore-form').action = `/admin/restore-database/${backupName}`;
|
||||
document.getElementById('restore-form').action = `/admin/database/restore-database/${backupName}`;
|
||||
|
||||
// Show the modal
|
||||
const modal = document.getElementById('confirm-restore-modal');
|
||||
modal.classList.remove('hidden');
|
||||
modal.classList.add('flex');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -321,7 +355,23 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
deleteButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const backupName = this.getAttribute('data-backup-name');
|
||||
document.getElementById('delete-form').action = `/admin/delete-backup/${backupName}`;
|
||||
document.getElementById('delete-form').action = `/admin/database/delete-backup/${backupName}`;
|
||||
|
||||
// Show the modal
|
||||
const modal = document.getElementById('confirm-delete-modal');
|
||||
modal.classList.remove('hidden');
|
||||
modal.classList.add('flex');
|
||||
});
|
||||
});
|
||||
|
||||
// Handle modal hide buttons
|
||||
const hideButtons = document.querySelectorAll('[data-modal-hide]');
|
||||
hideButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const modalId = this.getAttribute('data-modal-hide');
|
||||
const modal = document.getElementById(modalId);
|
||||
modal.classList.add('hidden');
|
||||
modal.classList.remove('flex');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -336,6 +386,46 @@ templ AdminDatabaseTools(ctx context.Context, backups []BackupFile) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add form submission events
|
||||
const backupForm = document.getElementById('backup-form');
|
||||
if (backupForm) {
|
||||
backupForm.addEventListener('submit', function(e) {
|
||||
console.log('Backup form submitted');
|
||||
});
|
||||
}
|
||||
|
||||
const vacuumForm = document.getElementById('vacuum-form');
|
||||
if (vacuumForm) {
|
||||
vacuumForm.addEventListener('submit', function(e) {
|
||||
console.log('Vacuum form submitted');
|
||||
});
|
||||
}
|
||||
|
||||
const clearJobForm = document.getElementById('clear-job-form');
|
||||
if (clearJobForm) {
|
||||
clearJobForm.addEventListener('submit', function(e) {
|
||||
console.log('Clear job form submitted');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Set dark background color if in dark mode
|
||||
if (document.documentElement.classList.contains('dark')) {
|
||||
document.getElementById('database-tools-container').style.backgroundColor = '#111827';
|
||||
}
|
||||
|
||||
// Add event listener for theme changes
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const themeToggle = document.getElementById('theme-toggle');
|
||||
if (themeToggle) {
|
||||
themeToggle.addEventListener('click', function() {
|
||||
setTimeout(function() {
|
||||
const isDark = document.documentElement.classList.contains('dark');
|
||||
document.getElementById('database-tools-container').style.backgroundColor = isDark ? '#111827' : 'rgb(249, 250, 251)';
|
||||
}, 50);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user