feat(ui): add ToggleDone command and checkbox state to TaskItemViewModel
This commit is contained in:
@@ -20,9 +20,10 @@ public partial class TaskItemViewModel : ViewModelBase
|
|||||||
|
|
||||||
private readonly Func<string, Task>? _runNow;
|
private readonly Func<string, Task>? _runNow;
|
||||||
private readonly Func<bool> _canRunNow;
|
private readonly Func<bool> _canRunNow;
|
||||||
|
private readonly Func<string, Task>? _toggleDone;
|
||||||
|
|
||||||
public TaskItemViewModel(TaskEntity entity, IReadOnlyList<TagEntity> tags,
|
public TaskItemViewModel(TaskEntity entity, IReadOnlyList<TagEntity> tags,
|
||||||
Func<string, Task>? runNow, Func<bool> canRunNow)
|
Func<string, Task>? runNow, Func<bool> canRunNow, Func<string, Task>? toggleDone = null)
|
||||||
{
|
{
|
||||||
Entity = entity;
|
Entity = entity;
|
||||||
Id = entity.Id;
|
Id = entity.Id;
|
||||||
@@ -35,8 +36,13 @@ public partial class TaskItemViewModel : ViewModelBase
|
|||||||
_description = entity.Description;
|
_description = entity.Description;
|
||||||
_runNow = runNow;
|
_runNow = runNow;
|
||||||
_canRunNow = canRunNow;
|
_canRunNow = canRunNow;
|
||||||
|
_toggleDone = toggleDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDone => Status == TaskStatus.Done;
|
||||||
|
public bool IsRunning => Status == TaskStatus.Running;
|
||||||
|
public bool CanToggleDone => Status != TaskStatus.Running && Status != TaskStatus.Failed;
|
||||||
|
|
||||||
public void Refresh(TaskEntity entity, IReadOnlyList<TagEntity> tags)
|
public void Refresh(TaskEntity entity, IReadOnlyList<TagEntity> tags)
|
||||||
{
|
{
|
||||||
Entity = entity;
|
Entity = entity;
|
||||||
@@ -47,6 +53,10 @@ public partial class TaskItemViewModel : ViewModelBase
|
|||||||
CommitType = entity.CommitType;
|
CommitType = entity.CommitType;
|
||||||
Description = entity.Description;
|
Description = entity.Description;
|
||||||
RunNowCommand.NotifyCanExecuteChanged();
|
RunNowCommand.NotifyCanExecuteChanged();
|
||||||
|
OnPropertyChanged(nameof(IsDone));
|
||||||
|
OnPropertyChanged(nameof(IsRunning));
|
||||||
|
OnPropertyChanged(nameof(CanToggleDone));
|
||||||
|
ToggleDoneCommand.NotifyCanExecuteChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand(CanExecute = nameof(CanRunNow))]
|
[RelayCommand(CanExecute = nameof(CanRunNow))]
|
||||||
@@ -58,4 +68,11 @@ public partial class TaskItemViewModel : ViewModelBase
|
|||||||
|
|
||||||
private bool CanRunNow() =>
|
private bool CanRunNow() =>
|
||||||
_canRunNow() && Status == TaskStatus.Queued;
|
_canRunNow() && Status == TaskStatus.Queued;
|
||||||
|
|
||||||
|
[RelayCommand(CanExecute = nameof(CanToggleDone))]
|
||||||
|
private async Task ToggleDone()
|
||||||
|
{
|
||||||
|
if (_toggleDone is not null)
|
||||||
|
await _toggleDone(Id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user