General Changes
This commit is contained in:
@@ -51,6 +51,7 @@ public partial class TaskDetailViewModel : ViewModelBase
|
||||
public ObservableCollection<SubtaskItemViewModel> Subtasks { get; } = new();
|
||||
|
||||
private string? _taskId;
|
||||
public string? CurrentTaskId => _taskId;
|
||||
private string? _listId;
|
||||
private bool _isLoading;
|
||||
// Cancels an in-flight LoadAsync when a new TaskUpdated event arrives
|
||||
@@ -267,11 +268,13 @@ public partial class TaskDetailViewModel : ViewModelBase
|
||||
var vm = SubtaskItemViewModel.From(entity);
|
||||
vm.PropertyChanged += OnSubtaskPropertyChanged;
|
||||
Subtasks.Add(vm);
|
||||
TaskChanged?.Invoke(_taskId);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task RemoveSubtask(SubtaskItemViewModel item)
|
||||
{
|
||||
if (_taskId is null) return;
|
||||
if (!string.IsNullOrEmpty(item.Id))
|
||||
{
|
||||
using var context = _dbFactory.CreateDbContext();
|
||||
@@ -280,6 +283,7 @@ public partial class TaskDetailViewModel : ViewModelBase
|
||||
}
|
||||
item.PropertyChanged -= OnSubtaskPropertyChanged;
|
||||
Subtasks.Remove(item);
|
||||
TaskChanged?.Invoke(_taskId);
|
||||
}
|
||||
|
||||
private async void OnSubtaskPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
@@ -301,6 +305,8 @@ public partial class TaskDetailViewModel : ViewModelBase
|
||||
OrderNum = Subtasks.IndexOf(vm),
|
||||
CreatedAt = orig?.CreatedAt ?? DateTime.UtcNow,
|
||||
});
|
||||
if (e.PropertyName == nameof(SubtaskItemViewModel.Completed))
|
||||
TaskChanged?.Invoke(_taskId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -309,6 +315,35 @@ public partial class TaskDetailViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RefreshSubtasksFromDbAsync()
|
||||
{
|
||||
if (_taskId is null) return;
|
||||
|
||||
List<SubtaskEntity> subtasks;
|
||||
using (var context = _dbFactory.CreateDbContext())
|
||||
{
|
||||
var subtaskRepo = new SubtaskRepository(context);
|
||||
subtasks = await subtaskRepo.GetByTaskIdAsync(_taskId);
|
||||
}
|
||||
|
||||
_isLoading = true;
|
||||
try
|
||||
{
|
||||
foreach (var old in Subtasks) old.PropertyChanged -= OnSubtaskPropertyChanged;
|
||||
Subtasks.Clear();
|
||||
foreach (var s in subtasks)
|
||||
{
|
||||
var vm = SubtaskItemViewModel.From(s);
|
||||
vm.PropertyChanged += OnSubtaskPropertyChanged;
|
||||
Subtasks.Add(vm);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAgentFromPath(string path)
|
||||
{
|
||||
var existing = AvailableAgents.FirstOrDefault(a => a.Path == path);
|
||||
|
||||
Reference in New Issue
Block a user