DisplayBackups displays the backups in the table.
(backups []api.Backup)
| 78 | |
| 79 | // DisplayBackups displays the backups in the table. |
| 80 | func (bt *BackupTable) DisplayBackups(backups []api.Backup) { |
| 81 | bt.backups = backups |
| 82 | |
| 83 | // Clear existing rows (keep headers) |
| 84 | for row := 1; row < bt.GetRowCount(); row++ { |
| 85 | for col := 0; col < bt.GetColumnCount(); col++ { |
| 86 | bt.SetCell(row, col, nil) |
| 87 | } |
| 88 | } |
| 89 | // We might need to reduce row count if it doesn't auto shrink? |
| 90 | // tview Table doesn't automatically shrink row count when setting cells to nil? |
| 91 | // Actually we should create a new table or just reset it properly. |
| 92 | // But `SetCell` to nil doesn't remove the row. |
| 93 | // The `Clear` method removes all content. |
| 94 | // Let's use RemoveRow loop. |
| 95 | for i := bt.GetRowCount() - 1; i >= 1; i-- { |
| 96 | bt.RemoveRow(i) |
| 97 | } |
| 98 | |
| 99 | if len(backups) == 0 { |
| 100 | return |
| 101 | } |
| 102 | |
| 103 | // Sort backups: newest first |
| 104 | sort.Slice(backups, func(i, j int) bool { |
| 105 | return backups[i].Date.After(backups[j].Date) |
| 106 | }) |
| 107 | |
| 108 | for i, backup := range backups { |
| 109 | row := i + 1 |
| 110 | |
| 111 | dateStr := backup.Date.Format("2006-01-02 15:04:05") |
| 112 | bt.SetCell(row, 0, tview.NewTableCell(dateStr).SetTextColor(theme.Colors.Primary)) |
| 113 | |
| 114 | // Show VolID or Name. Name is usually better if derived from VolID |
| 115 | name := backup.Name |
| 116 | if name == "" { |
| 117 | name = backup.VolID |
| 118 | } |
| 119 | bt.SetCell(row, 1, tview.NewTableCell(name).SetTextColor(theme.Colors.Primary)) |
| 120 | |
| 121 | sizeStr := utils.FormatBytes(backup.Size) |
| 122 | bt.SetCell(row, 2, tview.NewTableCell(sizeStr).SetTextColor(theme.Colors.Primary)) |
| 123 | |
| 124 | bt.SetCell(row, 3, tview.NewTableCell(backup.Storage).SetTextColor(theme.Colors.Primary)) |
| 125 | |
| 126 | bt.SetCell(row, 4, tview.NewTableCell(backup.Format).SetTextColor(theme.Colors.Primary)) |
| 127 | |
| 128 | bt.SetCell(row, 5, tview.NewTableCell(backup.Notes).SetTextColor(theme.Colors.Primary)) |
| 129 | } |
| 130 | |
| 131 | bt.Select(1, 0) |
| 132 | } |
| 133 | |
| 134 | // GetSelectedBackup gets the currently selected backup. |
| 135 | func (bt *BackupTable) GetSelectedBackup() *api.Backup { |
no test coverage detected