package components import ( "context" "fmt" "github.com/starfleetcptn/gomft/internal/db" ) type HistoryData struct { History []db.JobHistory CurrentPage int TotalPages int SearchTerm string PageSize int Total int Configs map[uint]db.TransferConfig // Map of config IDs to configs for quick lookup } // min returns the smaller of x or y func min(x, y int) int { if x < y { return x } return y } // getConfigNameForHistory returns the appropriate name for the config used in a job history entry func getConfigNameForHistory(history db.JobHistory, configs map[uint]db.TransferConfig) string { // If ConfigID is set in the history record, use that to get the config name if history.ConfigID > 0 { if config, exists := configs[history.ConfigID]; exists { return config.Name } } // Fallback to the Job's default Config if it exists if history.Job.Config.ID > 0 { return history.Job.Config.Name } // If we can't determine the config name, show a default with the job name if history.Job.Name != "" { return fmt.Sprintf("%s (unknown config)", history.Job.Name) } return "Unknown Configuration" } // HistoryContent renders only the content part of the history page for HTMX requests templ HistoryContent(ctx context.Context, data HistoryData) { if len(data.History) == 0 {

No transfer history

if data.SearchTerm != "" {

No results found for "{ data.SearchTerm }". Try a different search term or .

} else if data.CurrentPage > 1 {

No more results on this page. .

} else {

Transfer history will appear here once jobs have run.

}
} else {
if data.TotalPages > 1 {
if data.CurrentPage > 1 { } else { Previous } if data.CurrentPage < data.TotalPages { } else { Next }
} } } templ History(ctx context.Context, data HistoryData) { @LayoutWithContext("Transfer History", ctx) {

Transfer History

Total: { fmt.Sprint(data.Total) } transfers
if data.SearchTerm != "" { }
Show entries
@HistoryContent(ctx, data)
} } templ pageNumbers(currentPage int, totalPages int, pageSize int, searchTerm string) { // Show at most 5 page numbers with the current page in the middle when possible for i := 1; i <= totalPages; i++ { if i == currentPage { { fmt.Sprint(i) } } else if i == 1 || i == totalPages || (i >= currentPage-2 && i <= currentPage+2) { } else if i == currentPage-3 || i == currentPage+3 { ... } } } func formatBytes(bytes int64) string { const unit = 1024 if bytes < unit { return fmt.Sprintf("%d B", bytes) } div, exp := int64(unit), 0 for n := bytes / unit; n >= unit; n /= unit { div *= unit exp++ } return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp]) } func max(x, y int) int { if x > y { return x } return y }