From 93130c311699078d3d4c87bba64aa7998ab876c3 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Fri, 31 May 2024 14:07:35 +0100 Subject: [PATCH] wip --- Bitvault.Avalonia/App.axaml.cs | 13 ++++---- Bitvault.Avalonia/Bitvault.Avalonia.csproj | 3 -- Bitvault.Avalonia/CreateItemActionView.axaml | 2 +- .../EmptyItemCollectionView.axaml | 1 - .../ItemCategoryNavigationView.axaml | 21 +++++++++++-- Bitvault.Avalonia/ItemNavigationView.axaml | 2 -- Bitvault.Avalonia/ItemView.axaml | 14 +-------- Bitvault.Avalonia/LockerNavigationView.axaml | 28 +++++++++++++++-- Bitvault.Avalonia/MainView.axaml | 1 + Bitvault.Data/ItemEntry.cs | 2 ++ ...> AggerateItemCategoryViewModelHandler.cs} | 6 ++-- ...ler.cs => AggerateItemViewModelHandler.cs} | 4 +-- Bitvault/ConfirmCreateItemHandler.cs | 30 +++++++++++++++++++ Bitvault/ConfirmItemActionViewModel.cs | 6 ++-- ...Handler.cs => ConfirmUpdateItemHandler.cs} | 20 ++----------- Bitvault/CreateItemHandler.cs | 8 ++--- Bitvault/ItemCategoryCollectionViewModel.cs | 2 +- Bitvault/ItemCategoryNavigationViewModel.cs | 3 ++ Bitvault/ItemCollectionViewModel.cs | 5 +++- Bitvault/ItemContentViewModel.cs | 10 +++++-- ...edItemHandler.cs => ItemCreatedHandler.cs} | 2 +- Bitvault/ItemHeaderViewModel.cs | 14 +++++++++ ...dItemHandler.cs => ItemModifiedHandler.cs} | 2 +- Bitvault/ItemState.cs | 1 + Bitvault/ItemViewModel.cs | 16 ++++++---- Bitvault/MainViewModel.cs | 2 +- 26 files changed, 147 insertions(+), 71 deletions(-) rename Bitvault/{AggerateLockerItemCategoryViewModelHandler.cs => AggerateItemCategoryViewModelHandler.cs} (75%) rename Bitvault/{AggerateLockerItemViewModelHandler.cs => AggerateItemViewModelHandler.cs} (95%) create mode 100644 Bitvault/ConfirmCreateItemHandler.cs rename Bitvault/{ConfirmItemHandler.cs => ConfirmUpdateItemHandler.cs} (57%) rename Bitvault/{CreatedItemHandler.cs => ItemCreatedHandler.cs} (95%) rename Bitvault/{ModifiedItemHandler.cs => ItemModifiedHandler.cs} (95%) diff --git a/Bitvault.Avalonia/App.axaml.cs b/Bitvault.Avalonia/App.axaml.cs index 38f6669..3fdc828 100644 --- a/Bitvault.Avalonia/App.axaml.cs +++ b/Bitvault.Avalonia/App.axaml.cs @@ -68,6 +68,7 @@ public partial class App : Application services.AddTransient(); services.AddTransient(); + services.TryAddSingleton, ValueStore>(); services.TryAddSingleton, ValueStore>(); @@ -99,7 +100,7 @@ public partial class App : Application services.AddTemplate("Locker"); services.AddTemplate("ContentItemCollection"); - services.AddHandler(); + services.AddHandler(); services.AddTemplate("LockerHeader"); services.AddTemplate(); @@ -109,7 +110,7 @@ public partial class App : Application services.AddTemplate("ItemCategoryCollection"); services.AddTemplate(); - services.AddHandler(); + services.AddHandler(); services.AddTemplate(); services.AddTemplate("Item"); @@ -133,14 +134,16 @@ public partial class App : Application services.AddScoped>, ValueStore>>(); - services.AddHandler(); + services.AddHandler(nameof(Update)); + services.AddHandler(nameof(Create)); + services.AddHandler(); services.AddHandler(); services.AddHandler(); services.AddHandler(); - services.AddHandler(ServiceLifetime.Singleton); - services.AddHandler(ServiceLifetime.Singleton); + services.AddHandler(ServiceLifetime.Singleton); + services.AddHandler(ServiceLifetime.Singleton); }); })!); diff --git a/Bitvault.Avalonia/Bitvault.Avalonia.csproj b/Bitvault.Avalonia/Bitvault.Avalonia.csproj index c57ae07..c5e3ebb 100644 --- a/Bitvault.Avalonia/Bitvault.Avalonia.csproj +++ b/Bitvault.Avalonia/Bitvault.Avalonia.csproj @@ -11,9 +11,6 @@ $(DefineConstants);ENABLE_XAML_HOT_RELOAD - - - diff --git a/Bitvault.Avalonia/CreateItemActionView.axaml b/Bitvault.Avalonia/CreateItemActionView.axaml index 80f8182..736082a 100644 --- a/Bitvault.Avalonia/CreateItemActionView.axaml +++ b/Bitvault.Avalonia/CreateItemActionView.axaml @@ -37,7 +37,7 @@ Route="Item" Scope="self"> - + diff --git a/Bitvault.Avalonia/EmptyItemCollectionView.axaml b/Bitvault.Avalonia/EmptyItemCollectionView.axaml index 57cca31..0bb1567 100644 --- a/Bitvault.Avalonia/EmptyItemCollectionView.axaml +++ b/Bitvault.Avalonia/EmptyItemCollectionView.axaml @@ -20,7 +20,6 @@ Region="{Binding Named, StringFormat='{}{0}:Content'}" Route="Item" Scope="self"> - diff --git a/Bitvault.Avalonia/ItemCategoryNavigationView.axaml b/Bitvault.Avalonia/ItemCategoryNavigationView.axaml index 289297b..cf70124 100644 --- a/Bitvault.Avalonia/ItemCategoryNavigationView.axaml +++ b/Bitvault.Avalonia/ItemCategoryNavigationView.axaml @@ -3,8 +3,25 @@ xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="using:Bitvault" - x:DataType="vm:ItemCategoryNavigationViewModel" - IsSelected="{Binding Selected, Mode=TwoWay}"> + x:DataType="vm:ItemCategoryNavigationViewModel"> + + + + + + + + + + + + + + + - @@ -32,7 +31,6 @@ Region="{Binding Named, StringFormat='{}{0}:Content'}" Route="Item" Scope="self"> - diff --git a/Bitvault.Avalonia/ItemView.axaml b/Bitvault.Avalonia/ItemView.axaml index fe7871a..ef48b98 100644 --- a/Bitvault.Avalonia/ItemView.axaml +++ b/Bitvault.Avalonia/ItemView.axaml @@ -22,19 +22,7 @@ - - - - - - - + diff --git a/Bitvault.Avalonia/LockerNavigationView.axaml b/Bitvault.Avalonia/LockerNavigationView.axaml index 8718fd1..9e7c9cd 100644 --- a/Bitvault.Avalonia/LockerNavigationView.axaml +++ b/Bitvault.Avalonia/LockerNavigationView.axaml @@ -2,6 +2,7 @@ x:Class="Bitvault.Avalonia.LockerNavigationView" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:vm="using:Bitvault" x:Name="NavigationViewItem" x:DataType="vm:LockerNavigationViewModel" @@ -85,8 +86,29 @@ + + + + + + + + - - - + + + + diff --git a/Bitvault.Avalonia/MainView.axaml b/Bitvault.Avalonia/MainView.axaml index fa4e6aa..53194ce 100644 --- a/Bitvault.Avalonia/MainView.axaml +++ b/Bitvault.Avalonia/MainView.axaml @@ -8,6 +8,7 @@ FooterMenuItemsSource="{Binding Footer}" MenuItemTemplate="{Binding Template}" MenuItemsSource="{Binding}" + IsSettingsVisible="False" SelectedItem="{Binding SelectedItem}" SelectionFollowsFocus="True"> diff --git a/Bitvault.Data/ItemEntry.cs b/Bitvault.Data/ItemEntry.cs index b106488..b502dc5 100644 --- a/Bitvault.Data/ItemEntry.cs +++ b/Bitvault.Data/ItemEntry.cs @@ -15,6 +15,8 @@ public record ItemEntry public int State { get; set; } = 0; + public required string Category { get; set; } + public ICollection? Tags { get; } public ICollection? Blobs { get; } diff --git a/Bitvault/AggerateLockerItemCategoryViewModelHandler.cs b/Bitvault/AggerateItemCategoryViewModelHandler.cs similarity index 75% rename from Bitvault/AggerateLockerItemCategoryViewModelHandler.cs rename to Bitvault/AggerateItemCategoryViewModelHandler.cs index 6ca4a5f..b47d3e0 100644 --- a/Bitvault/AggerateLockerItemCategoryViewModelHandler.cs +++ b/Bitvault/AggerateItemCategoryViewModelHandler.cs @@ -2,19 +2,21 @@ namespace Bitvault; -public class AggerateLockerItemCategoryViewModelHandler(IEnumerable> descriptors, +public class AggerateItemCategoryViewModelHandler(IEnumerable> descriptors, IServiceFactory serviceFactory, IPublisher publisher) : INotificationHandler> { public Task Handle(AggerateEventArgs args) { + bool selected = true; foreach (IConfigurationDescriptor descriptor in descriptors) { - if (serviceFactory.Create(descriptor.Name) + if (serviceFactory.Create(descriptor.Name, selected) is ItemCategoryNavigationViewModel viewModel) { publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel)); + selected = false; } } diff --git a/Bitvault/AggerateLockerItemViewModelHandler.cs b/Bitvault/AggerateItemViewModelHandler.cs similarity index 95% rename from Bitvault/AggerateLockerItemViewModelHandler.cs rename to Bitvault/AggerateItemViewModelHandler.cs index a2a9050..e2348f3 100644 --- a/Bitvault/AggerateLockerItemViewModelHandler.cs +++ b/Bitvault/AggerateItemViewModelHandler.cs @@ -3,7 +3,7 @@ using Toolkit.Foundation; namespace Bitvault; -public class AggerateLockerItemViewModelHandler(IMediator mediator, +public class AggerateItemViewModelHandler(IMediator mediator, IServiceProvider serviceProvider, ICache> cache, IPublisher publisher) : @@ -45,7 +45,5 @@ public class AggerateLockerItemViewModelHandler(IMediator mediator, } } } - - var d = cache; } } \ No newline at end of file diff --git a/Bitvault/ConfirmCreateItemHandler.cs b/Bitvault/ConfirmCreateItemHandler.cs new file mode 100644 index 0000000..4e2fe7f --- /dev/null +++ b/Bitvault/ConfirmCreateItemHandler.cs @@ -0,0 +1,30 @@ +using Toolkit.Foundation; + +namespace Bitvault; + +public class ConfirmCreateItemHandler(IMediator mediator, + IPublisher publisher) : + INotificationHandler> +{ + public async Task Handle(ConfirmEventArgs args) + { + ItemHeaderConfiguration? configuration = await mediator.Handle, + ItemHeaderConfiguration>(args); + + if (configuration is not null) + { + publisher.Publish(Notify.As(configuration)); + + Guid id = Guid.NewGuid(); + + string? name = configuration.Name; + string? category = configuration.Name; + + publisher.Publish(Created.As(new Item<(Guid, string)>((id, name)))); + + await mediator.Handle, bool>(new CreateEventArgs<(Guid, string, string, ItemConfiguration)>((id, name, category, + new ItemConfiguration()))); + } + } +} diff --git a/Bitvault/ConfirmItemActionViewModel.cs b/Bitvault/ConfirmItemActionViewModel.cs index ffe6447..af43bf2 100644 --- a/Bitvault/ConfirmItemActionViewModel.cs +++ b/Bitvault/ConfirmItemActionViewModel.cs @@ -8,8 +8,10 @@ public partial class ConfirmItemActionViewModel(IServiceProvider provider, IMediator mediator, IPublisher publisher, ISubscription subscriber, - IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer) + IDisposer disposer, + ItemState state) : Observable(provider, factory, mediator, publisher, subscriber, disposer) { [RelayCommand] - public void Invoke() => Publisher.Publish(Confirm.As()); + public void Invoke() => Publisher.Publish(Confirm.As(), + state is ItemState.New ? nameof(Create) : nameof(Update)); } \ No newline at end of file diff --git a/Bitvault/ConfirmItemHandler.cs b/Bitvault/ConfirmUpdateItemHandler.cs similarity index 57% rename from Bitvault/ConfirmItemHandler.cs rename to Bitvault/ConfirmUpdateItemHandler.cs index 769fddc..eab0c09 100644 --- a/Bitvault/ConfirmItemHandler.cs +++ b/Bitvault/ConfirmUpdateItemHandler.cs @@ -2,7 +2,7 @@ namespace Bitvault; -public class ConfirmItemHandler(IValueStore> valueStore, +public class ConfirmUpdateItemHandler(IValueStore> store, IMediator mediator, IPublisher publisher) : INotificationHandler> @@ -16,33 +16,19 @@ public class ConfirmItemHandler(IValueStore> valueStore, { publisher.Publish(Notify.As(configuration)); - if (valueStore?.Value is Item<(Guid, string)> item) + if (store?.Value is Item<(Guid, string)> item) { (Guid id, string _) = item.Value; - string? name = configuration.Name; Item<(Guid, string)> newItem = new((id, name)); publisher.Publish(Modified.As(item, newItem)); - valueStore.Set(newItem); + store.Set(newItem); await mediator.Handle, bool>(new UpdateEventArgs<(Guid, string, ItemConfiguration)>((id, name, new ItemConfiguration()))); } - else - { - Guid id = Guid.NewGuid(); - string? name = configuration.Name; - - bool Success = await mediator.Handle, bool>(new CreateEventArgs<(Guid, string, ItemConfiguration)>((id, name, new ItemConfiguration()))); - - if (Success) - { - publisher.Publish(Created.As(new Item<(Guid, string)>((id, name)))); - } - } } } } \ No newline at end of file diff --git a/Bitvault/CreateItemHandler.cs b/Bitvault/CreateItemHandler.cs index ff139ab..7658079 100644 --- a/Bitvault/CreateItemHandler.cs +++ b/Bitvault/CreateItemHandler.cs @@ -6,12 +6,12 @@ using Toolkit.Foundation; namespace Bitvault; public class CreateItemHandler(IDbContextFactory dbContextFactory) : - IHandler, bool> + IHandler, bool> { - public async Task Handle(CreateEventArgs<(Guid, string, ItemConfiguration)> args, + public async Task Handle(CreateEventArgs<(Guid, string, string, ItemConfiguration)> args, CancellationToken cancellationToken) { - if (args.Value is (Guid id, string name, ItemConfiguration configuration)) + if (args.Value is (Guid id, string name, string category, ItemConfiguration configuration)) { try { @@ -20,7 +20,7 @@ public class CreateItemHandler(IDbContextFactory dbContextFactory await Task.Run(async () => { - result = await context.AddAsync(new ItemEntry { Id = id, Name = name }, cancellationToken); + result = await context.AddAsync(new ItemEntry { Id = id, Name = name, Category = category }, cancellationToken); await context.SaveChangesAsync(cancellationToken); }, cancellationToken); diff --git a/Bitvault/ItemCategoryCollectionViewModel.cs b/Bitvault/ItemCategoryCollectionViewModel.cs index de0dc7d..f5b552c 100644 --- a/Bitvault/ItemCategoryCollectionViewModel.cs +++ b/Bitvault/ItemCategoryCollectionViewModel.cs @@ -3,7 +3,7 @@ using Toolkit.Foundation; namespace Bitvault; -[Aggerate(nameof(ItemCategoryCollectionViewModel))] +[Aggerate(typeof(CreateEventArgs), nameof(ItemCategoryCollectionViewModel))] public partial class ItemCategoryCollectionViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, diff --git a/Bitvault/ItemCategoryNavigationViewModel.cs b/Bitvault/ItemCategoryNavigationViewModel.cs index 6155efb..1c19e8f 100644 --- a/Bitvault/ItemCategoryNavigationViewModel.cs +++ b/Bitvault/ItemCategoryNavigationViewModel.cs @@ -1,4 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using Toolkit.Foundation; namespace Bitvault; @@ -21,4 +22,6 @@ public partial class ItemCategoryNavigationViewModel(IServiceProvider provider, [ObservableProperty] private bool selected = selected; + [RelayCommand] + public void Invoke() => Publisher.Publish(Notify.As(new ItemCategory(Name))); } diff --git a/Bitvault/ItemCollectionViewModel.cs b/Bitvault/ItemCollectionViewModel.cs index 67bdc63..2e1b88e 100644 --- a/Bitvault/ItemCollectionViewModel.cs +++ b/Bitvault/ItemCollectionViewModel.cs @@ -3,7 +3,10 @@ using Toolkit.Foundation; namespace Bitvault; -[Aggerate(nameof(ItemCollectionViewModel))] +[Aggerate(typeof(AggerateEventArgs), nameof(ItemCollectionViewModel))] +[Notification(typeof(CreateEventArgs), nameof(ItemCollectionViewModel))] +[Notification(typeof(InsertEventArgs), nameof(ItemCollectionViewModel))] +[Notification(typeof(MoveToEventArgs), nameof(ItemCollectionViewModel))] public partial class ItemCollectionViewModel : ObservableCollection, INotificationHandler>, diff --git a/Bitvault/ItemContentViewModel.cs b/Bitvault/ItemContentViewModel.cs index 635c811..3c9a417 100644 --- a/Bitvault/ItemContentViewModel.cs +++ b/Bitvault/ItemContentViewModel.cs @@ -2,7 +2,7 @@ namespace Bitvault; -[Aggerate(nameof(ItemContentViewModel))] +//[Aggerate(nameof(ItemContentViewModel))] public partial class ItemContentViewModel : ObservableCollection, IItemEntryViewModel, @@ -21,8 +21,14 @@ public partial class ItemContentViewModel : public IContentTemplate Template { get; set; } + protected override IAggerate OnAggerate(object? key) + { + return base.OnAggerate(key); + } + + public Task Handle(NotifyEventArgs> args) { - throw new NotImplementedException(); + return Task.CompletedTask; } } diff --git a/Bitvault/CreatedItemHandler.cs b/Bitvault/ItemCreatedHandler.cs similarity index 95% rename from Bitvault/CreatedItemHandler.cs rename to Bitvault/ItemCreatedHandler.cs index add147b..4bec2df 100644 --- a/Bitvault/CreatedItemHandler.cs +++ b/Bitvault/ItemCreatedHandler.cs @@ -3,7 +3,7 @@ using Toolkit.Foundation; namespace Bitvault; -public class CreatedItemHandler(IServiceProvider serviceProvider, +public class ItemCreatedHandler(IServiceProvider serviceProvider, ICache> cache, IPublisher publisher) : INotificationHandler>> diff --git a/Bitvault/ItemHeaderViewModel.cs b/Bitvault/ItemHeaderViewModel.cs index f124557..649449d 100644 --- a/Bitvault/ItemHeaderViewModel.cs +++ b/Bitvault/ItemHeaderViewModel.cs @@ -9,8 +9,12 @@ public partial class ItemHeaderViewModel : Observable, INotificationHandler>, INotificationHandler>, INotificationHandler>, + INotificationHandler>>, IItemEntryViewModel { + [ObservableProperty] + private string? category; + [ObservableProperty] private ItemState state; @@ -56,4 +60,14 @@ public partial class ItemHeaderViewModel : Observable, State = ItemState.Read; return Task.CompletedTask; } + + public Task Handle(NotifyEventArgs> args) + { + if (args.Value is ItemCategory category) + { + Category = category.Value; + } + + return Task.CompletedTask; + } } \ No newline at end of file diff --git a/Bitvault/ModifiedItemHandler.cs b/Bitvault/ItemModifiedHandler.cs similarity index 95% rename from Bitvault/ModifiedItemHandler.cs rename to Bitvault/ItemModifiedHandler.cs index d408c06..2943dc6 100644 --- a/Bitvault/ModifiedItemHandler.cs +++ b/Bitvault/ItemModifiedHandler.cs @@ -3,7 +3,7 @@ using Toolkit.Foundation; namespace Bitvault; -public class ModifiedItemHandler(IServiceProvider serviceProvider, +public class ItemModifiedHandler(IServiceProvider serviceProvider, IPublisher publisher) : INotificationHandler>> { diff --git a/Bitvault/ItemState.cs b/Bitvault/ItemState.cs index 1f2e8e1..9783e9a 100644 --- a/Bitvault/ItemState.cs +++ b/Bitvault/ItemState.cs @@ -2,6 +2,7 @@ public enum ItemState { + New, Read, Write } diff --git a/Bitvault/ItemViewModel.cs b/Bitvault/ItemViewModel.cs index 1a74c6f..ba95bcb 100644 --- a/Bitvault/ItemViewModel.cs +++ b/Bitvault/ItemViewModel.cs @@ -3,6 +3,7 @@ using Toolkit.Foundation; namespace Bitvault; +[Notification(typeof(ConfirmEventArgs), nameof(Create))] public partial class ItemViewModel : ObservableCollection, INotificationHandler>, @@ -42,10 +43,10 @@ public partial class ItemViewModel : bool favourite = false, bool archived = false) : base(provider, factory, mediator, publisher, subscriber, disposer) { - FromCategory = fromCategory; - Named = $"{named}"; Template = template; + Named = $"{named}"; State = state; + FromCategory = fromCategory; Favourite = favourite; Archived = archived; Name = name; @@ -60,7 +61,7 @@ public partial class ItemViewModel : { Publisher.Publish(Notify.As(Factory.Create(new List { - Factory.Create(), + Factory.Create(ItemState.Write), Factory.Create(), }))); @@ -70,9 +71,12 @@ public partial class ItemViewModel : public override void Dispose() { - Publisher.Publish(Notify.As(Factory.Create(new List()))); + Publisher.Publish(Notify.As(Factory.Create(new + List()))); + base.Dispose(); } + public Task Handle(CancelEventArgs args) { Publisher.Publish(Notify.As(Factory.Create(new List @@ -109,11 +113,11 @@ public partial class ItemViewModel : } else { - if (State is ItemState.Write) + if (State is ItemState.Write or ItemState.New) { Publisher.Publish(Notify.As(Factory.Create(new List { - Factory.Create(), + Factory.Create(State), Factory.Create(), }))); } diff --git a/Bitvault/MainViewModel.cs b/Bitvault/MainViewModel.cs index 60bf74b..584c8a1 100644 --- a/Bitvault/MainViewModel.cs +++ b/Bitvault/MainViewModel.cs @@ -3,7 +3,7 @@ using Toolkit.Foundation; namespace Bitvault; -[Aggerate(nameof(MainViewModel))] +[Aggerate(typeof(CreateEventArgs), nameof(MainViewModel))] public partial class MainViewModel : ObservableCollection {