Compare commits
1 Commits
v1.1.0
...
feat/subta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32bb52875f |
@@ -8,14 +8,21 @@ using ClaudeDo.Ui.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClaudeDo.App;
|
||||
|
||||
sealed class Program
|
||||
{
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int SetCurrentProcessExplicitAppUserModelID(string appId);
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
SetCurrentProcessExplicitAppUserModelID("ClaudeDo.App");
|
||||
|
||||
var services = BuildServices();
|
||||
App.Services = services;
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia.Media;
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
namespace ClaudeDo.Ui.ViewModels;
|
||||
@@ -15,6 +19,11 @@ public partial class TaskItemViewModel : ViewModelBase
|
||||
[ObservableProperty] private string? _description;
|
||||
[ObservableProperty] private TaskStatus _status;
|
||||
[ObservableProperty] private bool _isStarting;
|
||||
[ObservableProperty] private bool _isExpanded;
|
||||
[ObservableProperty] private bool _hasSubtasks;
|
||||
[ObservableProperty] private int _subtaskCount;
|
||||
|
||||
public ObservableCollection<SubtaskItemViewModel> Subtasks { get; } = new();
|
||||
|
||||
public string Id { get; }
|
||||
public string ListId { get; }
|
||||
@@ -23,9 +32,13 @@ public partial class TaskItemViewModel : ViewModelBase
|
||||
private readonly Func<string, Task>? _runNow;
|
||||
private readonly Func<bool> _canRunNow;
|
||||
private readonly Func<string, Task>? _toggleDone;
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private bool _subtasksLoaded;
|
||||
|
||||
public TaskItemViewModel(TaskEntity entity, IReadOnlyList<TagEntity> tags,
|
||||
Func<string, Task>? runNow, Func<bool> canRunNow, Func<string, Task>? toggleDone = null)
|
||||
Func<string, Task>? runNow, Func<bool> canRunNow,
|
||||
IDbContextFactory<ClaudeDoDbContext> dbFactory, int subtaskCount,
|
||||
Func<string, Task>? toggleDone = null)
|
||||
{
|
||||
Entity = entity;
|
||||
Id = entity.Id;
|
||||
@@ -39,6 +52,9 @@ public partial class TaskItemViewModel : ViewModelBase
|
||||
_runNow = runNow;
|
||||
_canRunNow = canRunNow;
|
||||
_toggleDone = toggleDone;
|
||||
_dbFactory = dbFactory;
|
||||
_subtaskCount = subtaskCount;
|
||||
_hasSubtasks = subtaskCount > 0;
|
||||
}
|
||||
|
||||
public bool IsDone => Status == TaskStatus.Done;
|
||||
@@ -104,4 +120,55 @@ public partial class TaskItemViewModel : ViewModelBase
|
||||
if (_toggleDone is not null)
|
||||
await _toggleDone(Id);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ToggleExpanded()
|
||||
{
|
||||
IsExpanded = !IsExpanded;
|
||||
if (IsExpanded && !_subtasksLoaded)
|
||||
await LoadSubtasksAsync();
|
||||
}
|
||||
|
||||
private async Task LoadSubtasksAsync()
|
||||
{
|
||||
using var context = _dbFactory.CreateDbContext();
|
||||
var repo = new SubtaskRepository(context);
|
||||
var entities = await repo.GetByTaskIdAsync(Id);
|
||||
Subtasks.Clear();
|
||||
foreach (var e in entities)
|
||||
Subtasks.Add(SubtaskItemViewModel.From(e));
|
||||
_subtasksLoaded = true;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ToggleSubtaskDone(string subtaskId)
|
||||
{
|
||||
var vm = Subtasks.FirstOrDefault(s => s.Id == subtaskId);
|
||||
if (vm is null) return;
|
||||
vm.Completed = !vm.Completed;
|
||||
|
||||
using var context = _dbFactory.CreateDbContext();
|
||||
var entity = await context.Subtasks.FindAsync(subtaskId);
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Completed = vm.Completed;
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RefreshSubtasksAsync(int newCount)
|
||||
{
|
||||
SubtaskCount = newCount;
|
||||
HasSubtasks = newCount > 0;
|
||||
if (!HasSubtasks)
|
||||
{
|
||||
IsExpanded = false;
|
||||
Subtasks.Clear();
|
||||
_subtasksLoaded = false;
|
||||
}
|
||||
else if (_subtasksLoaded || IsExpanded)
|
||||
{
|
||||
await LoadSubtasksAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,10 +91,17 @@ public partial class TaskListViewModel : ViewModelBase
|
||||
using var context = _dbFactory.CreateDbContext();
|
||||
var taskRepo = new TaskRepository(context);
|
||||
var entities = await taskRepo.GetByListIdAsync(listId);
|
||||
var taskIds = entities.Select(e => e.Id).ToList();
|
||||
var subtaskCounts = await context.Subtasks
|
||||
.Where(s => taskIds.Contains(s.TaskId))
|
||||
.GroupBy(s => s.TaskId)
|
||||
.ToDictionaryAsync(g => g.Key, g => g.Count());
|
||||
foreach (var e in entities)
|
||||
{
|
||||
var tags = await taskRepo.GetEffectiveTagsAsync(e.Id);
|
||||
Tasks.Add(new TaskItemViewModel(e, tags, RunNowAsync, () => _worker.IsConnected, ToggleDoneAsync));
|
||||
subtaskCounts.TryGetValue(e.Id, out var count);
|
||||
Tasks.Add(new TaskItemViewModel(e, tags, RunNowAsync, () => _worker.IsConnected,
|
||||
_dbFactory, count, ToggleDoneAsync));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -135,7 +142,8 @@ public partial class TaskListViewModel : ViewModelBase
|
||||
var taskRepo = new TaskRepository(context);
|
||||
await taskRepo.AddAsync(entity);
|
||||
var tags = await taskRepo.GetEffectiveTagsAsync(entity.Id);
|
||||
var vm = new TaskItemViewModel(entity, tags, RunNowAsync, () => _worker.IsConnected, ToggleDoneAsync);
|
||||
var vm = new TaskItemViewModel(entity, tags, RunNowAsync, () => _worker.IsConnected,
|
||||
_dbFactory, 0, ToggleDoneAsync);
|
||||
Tasks.Add(vm);
|
||||
SelectedTask = vm;
|
||||
InlineAddTitle = "";
|
||||
@@ -183,7 +191,8 @@ public partial class TaskListViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
var tags = await taskRepo.GetEffectiveTagsAsync(saved.Id);
|
||||
Tasks.Add(new TaskItemViewModel(saved, tags, RunNowAsync, () => _worker.IsConnected, ToggleDoneAsync));
|
||||
Tasks.Add(new TaskItemViewModel(saved, tags, RunNowAsync, () => _worker.IsConnected,
|
||||
_dbFactory, 0, ToggleDoneAsync));
|
||||
|
||||
// Auto wake-queue if agent+queued
|
||||
if (saved.Status == TaskStatus.Queued &&
|
||||
@@ -282,7 +291,11 @@ public partial class TaskListViewModel : ViewModelBase
|
||||
}
|
||||
var tags = await taskRepo.GetEffectiveTagsAsync(taskId);
|
||||
if (existing is not null)
|
||||
{
|
||||
existing.Refresh(entity, tags);
|
||||
var subtaskCount = await context.Subtasks.CountAsync(s => s.TaskId == taskId);
|
||||
await existing.RefreshSubtasksAsync(subtaskCount);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunNowAsync(string taskId)
|
||||
|
||||
@@ -31,72 +31,128 @@
|
||||
KeyDown="OnTaskListKeyDown">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:TaskItemViewModel">
|
||||
<Grid ColumnDefinitions="Auto,*" Margin="4,4"
|
||||
<Grid RowDefinitions="Auto,Auto"
|
||||
Background="Transparent"
|
||||
Opacity="{Binding RowOpacity}"
|
||||
DoubleTapped="OnTaskItemDoubleTapped"
|
||||
PointerPressed="OnTaskItemPointerPressed">
|
||||
<Grid.ContextFlyout>
|
||||
<MenuFlyout>
|
||||
<MenuItem Header="Edit"
|
||||
Command="{Binding #Root.((vm:TaskListViewModel)DataContext).EditTaskCommand}"/>
|
||||
<MenuItem Header="Delete"
|
||||
Command="{Binding #Root.((vm:TaskListViewModel)DataContext).DeleteTaskCommand}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Run Now"
|
||||
Command="{Binding RunNowCommand}"/>
|
||||
</MenuFlyout>
|
||||
</Grid.ContextFlyout>
|
||||
Opacity="{Binding RowOpacity}">
|
||||
<!-- Row 0: Task row -->
|
||||
<Grid Grid.Row="0" ColumnDefinitions="20,Auto,*" Margin="4,4"
|
||||
DoubleTapped="OnTaskItemDoubleTapped"
|
||||
PointerPressed="OnTaskItemPointerPressed">
|
||||
<Grid.ContextFlyout>
|
||||
<MenuFlyout>
|
||||
<MenuItem Header="Edit"
|
||||
Command="{Binding #Root.((vm:TaskListViewModel)DataContext).EditTaskCommand}"/>
|
||||
<MenuItem Header="Delete"
|
||||
Command="{Binding #Root.((vm:TaskListViewModel)DataContext).DeleteTaskCommand}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Run Now"
|
||||
Command="{Binding RunNowCommand}"/>
|
||||
</MenuFlyout>
|
||||
</Grid.ContextFlyout>
|
||||
|
||||
<!-- Circular checkbox -->
|
||||
<Border Grid.Column="0" Width="22" Height="22"
|
||||
CornerRadius="11"
|
||||
BorderThickness="2"
|
||||
BorderBrush="{Binding StatusText, Converter={x:Static conv:CheckboxBorderConverter.Instance}}"
|
||||
Background="Transparent"
|
||||
VerticalAlignment="Center" Margin="0,0,10,0"
|
||||
Cursor="Hand"
|
||||
PointerPressed="OnCheckboxPressed">
|
||||
<Panel>
|
||||
<!-- Checkmark for done -->
|
||||
<Canvas Width="12" Height="12"
|
||||
IsVisible="{Binding IsDone}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Path Stroke="{StaticResource StatusGreenBrush}" StrokeThickness="2"
|
||||
Data="M 1,6 L 4.5,9.5 L 11,3"/>
|
||||
</Canvas>
|
||||
<!-- Running dot -->
|
||||
<Ellipse Width="8" Height="8"
|
||||
Fill="{StaticResource StatusOrangeBrush}"
|
||||
IsVisible="{Binding IsRunning}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<!-- Starting dot -->
|
||||
<Ellipse Width="8" Height="8" Fill="#FFD700"
|
||||
IsVisible="{Binding IsStarting}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Panel>
|
||||
</Border>
|
||||
<!-- Expand/collapse chevron -->
|
||||
<Button Grid.Column="0"
|
||||
Command="{Binding ToggleExpandedCommand}"
|
||||
IsVisible="{Binding HasSubtasks}"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Padding="0"
|
||||
Width="16" Height="16"
|
||||
VerticalAlignment="Center"
|
||||
Cursor="Hand">
|
||||
<Panel>
|
||||
<Canvas Width="10" Height="10"
|
||||
IsVisible="{Binding !IsExpanded}">
|
||||
<Path Stroke="{StaticResource TextDimBrush}" StrokeThickness="1.5"
|
||||
Data="M 2,0 L 8,5 L 2,10"/>
|
||||
</Canvas>
|
||||
<Canvas Width="10" Height="10"
|
||||
IsVisible="{Binding IsExpanded}">
|
||||
<Path Stroke="{StaticResource TextDimBrush}" StrokeThickness="1.5"
|
||||
Data="M 0,2 L 5,8 L 10,2"/>
|
||||
</Canvas>
|
||||
</Panel>
|
||||
</Button>
|
||||
|
||||
<!-- Task content -->
|
||||
<StackPanel Grid.Column="1" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Title}" FontWeight="Medium"
|
||||
Foreground="{Binding TitleForeground}"
|
||||
TextDecorations="{Binding TitleDecorations}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<TextBlock FontSize="11"
|
||||
Foreground="{StaticResource TextDimBrush}"
|
||||
IsVisible="{Binding TagsText, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0} · {1}">
|
||||
<Binding Path="TagsText"/>
|
||||
<Binding Path="StatusText"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
<TextBlock Text="{Binding StatusText}" FontSize="11"
|
||||
Foreground="{StaticResource TextDimBrush}"
|
||||
IsVisible="{Binding TagsText, Converter={x:Static StringConverters.IsNullOrEmpty}}"/>
|
||||
</StackPanel>
|
||||
<!-- Circular checkbox -->
|
||||
<Border Grid.Column="1" Width="22" Height="22"
|
||||
CornerRadius="11"
|
||||
BorderThickness="2"
|
||||
BorderBrush="{Binding StatusText, Converter={x:Static conv:CheckboxBorderConverter.Instance}}"
|
||||
Background="Transparent"
|
||||
VerticalAlignment="Center" Margin="0,0,10,0"
|
||||
Cursor="Hand"
|
||||
PointerPressed="OnCheckboxPressed">
|
||||
<Panel>
|
||||
<Canvas Width="12" Height="12"
|
||||
IsVisible="{Binding IsDone}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Path Stroke="{StaticResource StatusGreenBrush}" StrokeThickness="2"
|
||||
Data="M 1,6 L 4.5,9.5 L 11,3"/>
|
||||
</Canvas>
|
||||
<Ellipse Width="8" Height="8"
|
||||
Fill="{StaticResource StatusOrangeBrush}"
|
||||
IsVisible="{Binding IsRunning}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<Ellipse Width="8" Height="8" Fill="#FFD700"
|
||||
IsVisible="{Binding IsStarting}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Panel>
|
||||
</Border>
|
||||
|
||||
<!-- Task content -->
|
||||
<StackPanel Grid.Column="2" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Title}" FontWeight="Medium"
|
||||
Foreground="{Binding TitleForeground}"
|
||||
TextDecorations="{Binding TitleDecorations}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<TextBlock FontSize="11"
|
||||
Foreground="{StaticResource TextDimBrush}"
|
||||
IsVisible="{Binding TagsText, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0} · {1}">
|
||||
<Binding Path="TagsText"/>
|
||||
<Binding Path="StatusText"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
<TextBlock Text="{Binding StatusText}" FontSize="11"
|
||||
Foreground="{StaticResource TextDimBrush}"
|
||||
IsVisible="{Binding TagsText, Converter={x:Static StringConverters.IsNullOrEmpty}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Row 1: Subtask list (visible when expanded) -->
|
||||
<ItemsControl Grid.Row="1"
|
||||
ItemsSource="{Binding Subtasks}"
|
||||
IsVisible="{Binding IsExpanded}"
|
||||
Margin="40,0,0,4">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:SubtaskItemViewModel">
|
||||
<Grid ColumnDefinitions="Auto,*" Margin="0,2"
|
||||
PointerPressed="OnSubtaskPointerPressed">
|
||||
<Grid.ContextFlyout>
|
||||
<MenuFlyout>
|
||||
<MenuItem Header="Edit Task"
|
||||
Command="{Binding #Root.((vm:TaskListViewModel)DataContext).EditTaskCommand}"/>
|
||||
</MenuFlyout>
|
||||
</Grid.ContextFlyout>
|
||||
<CheckBox Grid.Column="0"
|
||||
IsChecked="{Binding Completed, Mode=OneWay}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,6,0"
|
||||
MinWidth="0"
|
||||
Click="OnSubtaskCheckboxClick"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding Title}"
|
||||
FontSize="12"
|
||||
Foreground="{StaticResource TextDimBrush}"
|
||||
VerticalAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
@@ -97,6 +98,29 @@ public partial class TaskListView : UserControl
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSubtaskPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (e.GetCurrentPoint(null).Properties.IsRightButtonPressed
|
||||
&& sender is Control { DataContext: SubtaskItemViewModel subtask }
|
||||
&& DataContext is TaskListViewModel vm)
|
||||
{
|
||||
var parent = vm.Tasks.FirstOrDefault(t => t.Subtasks.Contains(subtask));
|
||||
if (parent is not null)
|
||||
vm.SelectedTask = parent;
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnSubtaskCheckboxClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is CheckBox { DataContext: SubtaskItemViewModel subtask }
|
||||
&& DataContext is TaskListViewModel vm)
|
||||
{
|
||||
var parent = vm.Tasks.FirstOrDefault(t => t.Subtasks.Contains(subtask));
|
||||
if (parent is not null)
|
||||
await parent.ToggleSubtaskDoneCommand.ExecuteAsync(subtask.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public void FocusInlineAdd()
|
||||
{
|
||||
this.FindControl<TextBox>("InlineAddBox")?.Focus();
|
||||
|
||||
Reference in New Issue
Block a user