package components import ( "context" "fmt" "time" ) type BackupFile struct { Name string Size string ModTime time.Time } type AdminToolsData struct { JobHistoryCount int DatabaseSize string LastBackupTime *time.Time BackupCount int SystemUptime string ActiveJobs int TotalConfigs int TotalJobs int TotalUsers int DatabasePath string BackupPath string MaintenanceMessage string BackupFiles []BackupFile } // Dialog component for confirmation dialogs templ Dialog(id string, title string, message string, confirmClass string, confirmText string, formId string, targetAction string) { } script hideDialog(id string) { document.getElementById(id).classList.add("hidden"); } script submitFormAndHideDialog(formId string, dialogId string) { document.getElementById(formId).submit(); document.getElementById(dialogId).classList.add("hidden"); } script showDialog(id string) { document.getElementById(id).classList.remove("hidden"); } // Backup dialog component specifically for restore and delete actions templ BackupActionDialog(id string, title string, message string, confirmClass string, confirmText string, action string, backupName string) { } templ AdminTools(ctx context.Context, data AdminToolsData) { @LayoutWithContext("Admin Tools", ctx) {

Admin Tools

if data.MaintenanceMessage != "" {

{ data.MaintenanceMessage }

}

System Overview

Database Size
{ data.DatabaseSize }
Job History Records
{ fmt.Sprint(data.JobHistoryCount) }
System Uptime
{ data.SystemUptime }
Active Jobs
{ fmt.Sprint(data.ActiveJobs) }

Backup & Restore

if data.LastBackupTime != nil { Last backup: { data.LastBackupTime.Format("Jan 02, 2006 15:04:05") } } else { Last backup: Never }

Restore Database

Warning: This will replace your current database. Make sure to backup first!

Maintenance Tools

@Dialog("clear-job-dialog", "Clear Job History", "Are you sure you want to clear all job history? This cannot be undone.", "btn-danger", "Clear History", "purge-form", "")

Runs VACUUM to optimize the database and reclaim unused space.

@BackupsList(data)

System Information

Database Path
{ data.DatabasePath }
Backup Directory
{ data.BackupPath }
Total Users
{ fmt.Sprint(data.TotalUsers) }
Total Configurations
{ fmt.Sprint(data.TotalConfigs) }
Total Jobs
{ fmt.Sprint(data.TotalJobs) }
} } // BackupsList is a separate component for the backups list that can be refreshed via HTMX templ BackupsList(data AdminToolsData) { if len(data.BackupFiles) > 0 {

Available Backups

for _, backup := range data.BackupFiles { }
Name Size Date Action
{ backup.Name } { backup.Size } { backup.ModTime.Format("Jan 02, 2006 15:04:05") } @BackupActionDialog( fmt.Sprintf("restore-dialog-%s", backup.Name), "RESTORE BACKUP", fmt.Sprintf("Are you sure you want to restore the backup '%s'? This will replace your current database.", backup.Name), "btn-warning", "Restore", "restore", backup.Name, ) @BackupActionDialog( fmt.Sprintf("delete-dialog-%s", backup.Name), "DELETE BACKUP", fmt.Sprintf("Are you sure you want to delete the backup '%s'? This cannot be undone.", backup.Name), "btn-danger", "Delete", "delete", backup.Name, )
} else {

Available Backups

No Backups Available

Create a backup using the "Backup Database" button.

} }