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 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.
}{ getConfigNameForHistory(history, data.Configs) }
if history.Status == "completed" { Completed } else if history.Status == "failed" { Failed } else { { history.Status } }Started: { history.StartTime.Format("Jan 02, 2006 15:04:05") }
if history.EndTime != nil {Duration: { history.EndTime.Sub(history.StartTime).String() }
}{ formatBytes(history.BytesTransferred) } transferred
}Error: { history.ErrorMessage }
Showing { fmt.Sprint((data.CurrentPage-1)*data.PageSize + 1) } to { fmt.Sprint(min((data.CurrentPage)*data.PageSize, data.Total)) } of { fmt.Sprint(data.Total) } results