Refresh updates active tasks from TaskManager.
()
| 159 | |
| 160 | // Refresh updates active tasks from TaskManager. |
| 161 | func (tl *TasksList) Refresh() { |
| 162 | if tl.app == nil || tl.app.TaskManager() == nil { |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | tasks := tl.app.TaskManager().GetAllTasks() |
| 167 | |
| 168 | // Update active table |
| 169 | tl.activeTable.Clear() |
| 170 | |
| 171 | // Headers |
| 172 | for i, column := range activeTasksColumns { |
| 173 | tc := tview.NewTableCell(column.title). |
| 174 | SetTextColor(theme.Colors.HeaderText). |
| 175 | SetAlign(tview.AlignLeft). |
| 176 | SetExpansion(column.expansion) |
| 177 | tl.activeTable.SetCell(0, i, tc) |
| 178 | } |
| 179 | |
| 180 | if len(tasks) > 0 { |
| 181 | // Sort by created at |
| 182 | sort.Slice(tasks, func(i, j int) bool { |
| 183 | return tasks[i].CreatedAt.After(tasks[j].CreatedAt) |
| 184 | }) |
| 185 | |
| 186 | for i, task := range tasks { |
| 187 | row := i + 1 |
| 188 | |
| 189 | // Operation |
| 190 | tl.activeTable.SetCell(row, 0, tview.NewTableCell(task.Description). |
| 191 | SetTextColor(theme.Colors.Primary). |
| 192 | SetExpansion(activeTasksColumns[0].expansion)) |
| 193 | |
| 194 | // Target |
| 195 | tl.activeTable.SetCell(row, 1, tview.NewTableCell(fmt.Sprintf("%s (%s)", task.TargetName, task.TargetNode)). |
| 196 | SetTextColor(theme.Colors.Secondary). |
| 197 | SetExpansion(activeTasksColumns[1].expansion)) |
| 198 | |
| 199 | // Status |
| 200 | statusColor := theme.Colors.Info |
| 201 | if task.Status == taskmanager.StatusRunning { |
| 202 | statusColor = theme.Colors.Success |
| 203 | } else if task.Status == taskmanager.StatusFailed || task.Status == taskmanager.StatusCancelled { |
| 204 | statusColor = theme.Colors.Error |
| 205 | } |
| 206 | |
| 207 | tl.activeTable.SetCell(row, 2, tview.NewTableCell(string(task.Status)). |
| 208 | SetTextColor(statusColor). |
| 209 | SetExpansion(activeTasksColumns[2].expansion)) |
| 210 | |
| 211 | // Started |
| 212 | started := "Pending" |
| 213 | if !task.StartedAt.IsZero() { |
| 214 | started = task.StartedAt.Format("15:04:05") |
| 215 | } |
| 216 | tl.activeTable.SetCell(row, 3, tview.NewTableCell(started). |
| 217 | SetTextColor(theme.Colors.Secondary). |
| 218 | SetExpansion(activeTasksColumns[3].expansion)) |
no test coverage detected