This commit is contained in:
TheXamlGuy
2024-05-31 14:07:35 +01:00
parent eb5306f956
commit 93130c3116
26 changed files with 147 additions and 71 deletions
+8 -5
View File
@@ -68,6 +68,7 @@ public partial class App : Application
services.AddTransient<ISecurityKeyFactory, SecurityKeyFactory>(); services.AddTransient<ISecurityKeyFactory, SecurityKeyFactory>();
services.AddTransient<ILockerStorageFactory, LockerStorageFactory>(); services.AddTransient<ILockerStorageFactory, LockerStorageFactory>();
services.TryAddSingleton<IValueStore<SecurityKey>, ValueStore<SecurityKey>>(); services.TryAddSingleton<IValueStore<SecurityKey>, ValueStore<SecurityKey>>();
services.TryAddSingleton<IValueStore<LockerConnection>, ValueStore<LockerConnection>>(); services.TryAddSingleton<IValueStore<LockerConnection>, ValueStore<LockerConnection>>();
@@ -99,7 +100,7 @@ public partial class App : Application
services.AddTemplate<LockerViewModel, LockerView>("Locker"); services.AddTemplate<LockerViewModel, LockerView>("Locker");
services.AddTemplate<ItemCollectionViewModel, ItemCollectionView>("ContentItemCollection"); services.AddTemplate<ItemCollectionViewModel, ItemCollectionView>("ContentItemCollection");
services.AddHandler<AggerateLockerItemViewModelHandler>(); services.AddHandler<AggerateItemViewModelHandler>();
services.AddTemplate<LockerHeaderViewModel, LockerHeaderView>("LockerHeader"); services.AddTemplate<LockerHeaderViewModel, LockerHeaderView>("LockerHeader");
services.AddTemplate<BackActionViewModel, BackActionView>(); services.AddTemplate<BackActionViewModel, BackActionView>();
@@ -109,7 +110,7 @@ public partial class App : Application
services.AddTemplate<ItemCategoryCollectionViewModel, ItemCategoryCollectionView>("ItemCategoryCollection"); services.AddTemplate<ItemCategoryCollectionViewModel, ItemCategoryCollectionView>("ItemCategoryCollection");
services.AddTemplate<ItemCategoryNavigationViewModel, ItemCategoryNavigationView>(); services.AddTemplate<ItemCategoryNavigationViewModel, ItemCategoryNavigationView>();
services.AddHandler<AggerateLockerItemCategoryViewModelHandler>(); services.AddHandler<AggerateItemCategoryViewModelHandler>();
services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>(); services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>();
services.AddTemplate<ItemViewModel, ItemView>("Item"); services.AddTemplate<ItemViewModel, ItemView>("Item");
@@ -133,14 +134,16 @@ public partial class App : Application
services.AddScoped<IValueStore<Item<(Guid, string)>>, ValueStore<Item<(Guid, string)>>>(); services.AddScoped<IValueStore<Item<(Guid, string)>>, ValueStore<Item<(Guid, string)>>>();
services.AddHandler<ConfirmItemHandler>(); services.AddHandler<ConfirmUpdateItemHandler>(nameof(Update));
services.AddHandler<ConfirmCreateItemHandler>(nameof(Create));
services.AddHandler<ArchiveItemHandler>(); services.AddHandler<ArchiveItemHandler>();
services.AddHandler<UnarchiveItemHandler>(); services.AddHandler<UnarchiveItemHandler>();
services.AddHandler<FavouriteItemHandler>(); services.AddHandler<FavouriteItemHandler>();
services.AddHandler<UnfavouriteItemHandler>(); services.AddHandler<UnfavouriteItemHandler>();
services.AddHandler<CreatedItemHandler>(ServiceLifetime.Singleton); services.AddHandler<ItemCreatedHandler>(ServiceLifetime.Singleton);
services.AddHandler<ModifiedItemHandler>(ServiceLifetime.Singleton); services.AddHandler<ItemModifiedHandler>(ServiceLifetime.Singleton);
}); });
})!); })!);
@@ -11,9 +11,6 @@
<PropertyGroup Condition="'$(Configuration)' == 'Debug'"> <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>$(DefineConstants);ENABLE_XAML_HOT_RELOAD</DefineConstants> <DefineConstants>$(DefineConstants);ENABLE_XAML_HOT_RELOAD</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Assets\Class1.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="Avalonia.Markup.Xaml.Loader" Version="11.1.0-beta2" /> <PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="Avalonia.Markup.Xaml.Loader" Version="11.1.0-beta2" />
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="HotAvalonia" Version="1.1.1" /> <PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="HotAvalonia" Version="1.1.1" />
+1 -1
View File
@@ -37,7 +37,7 @@
Route="Item" Route="Item"
Scope="self"> Scope="self">
<Parameter Key="FromCategory" Value="{x:True}" /> <Parameter Key="FromCategory" Value="{x:True}" />
<Parameter Key="State" Value="{x:Static vm:ItemState.Write}" /> <Parameter Key="State" Value="{x:Static vm:ItemState.New}" />
</NavigateAction> </NavigateAction>
</EventTriggerBehavior> </EventTriggerBehavior>
</Interaction.Behaviors> </Interaction.Behaviors>
@@ -20,7 +20,6 @@
Region="{Binding Named, StringFormat='{}{0}:Content'}" Region="{Binding Named, StringFormat='{}{0}:Content'}"
Route="Item" Route="Item"
Scope="self"> Scope="self">
<Parameter Key="FromCategory" Value="{x:True}" />
<Parameter Key="State" Value="{x:Static vm:ItemState.Write}" /> <Parameter Key="State" Value="{x:Static vm:ItemState.Write}" />
</NavigateAction> </NavigateAction>
</EventTriggerBehavior> </EventTriggerBehavior>
@@ -3,8 +3,25 @@
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Bitvault" xmlns:vm="using:Bitvault"
x:DataType="vm:ItemCategoryNavigationViewModel" x:DataType="vm:ItemCategoryNavigationViewModel">
IsSelected="{Binding Selected, Mode=TwoWay}"> <Interaction.Behaviors>
<AttachedBehaviour>
<ConditionAction>
<ConditionAction.Condition>
<ConditionalExpression ForwardChaining="And">
<ComparisonCondition LeftOperand="{Binding Selected}" RightOperand="True" />
</ConditionalExpression>
</ConditionAction.Condition>
<InvokeCommandAction Command="{Binding InvokeCommand}" />
</ConditionAction>
</AttachedBehaviour>
<DataTriggerBehavior
Binding="{Binding Selected}"
ComparisonCondition="Equal"
Value="True">
<InvokeCommandAction Command="{Binding InvokeCommand}" />
</DataTriggerBehavior>
</Interaction.Behaviors>
<Grid Background="Transparent" ColumnDefinitions="Auto,*"> <Grid Background="Transparent" ColumnDefinitions="Auto,*">
<PersonPicture <PersonPicture
Grid.Column="0" Grid.Column="0"
@@ -19,7 +19,6 @@
Region="{Binding Named, StringFormat='{}{0}:Content'}" Region="{Binding Named, StringFormat='{}{0}:Content'}"
Route="Item" Route="Item"
Scope="self"> Scope="self">
<Parameter Key="FromCategory" Value="{x:False}" />
<Parameter Key="State" Value="{x:Static vm:ItemState.Read}" /> <Parameter Key="State" Value="{x:Static vm:ItemState.Read}" />
<Parameter Key="Name" Value="{Binding Name}" /> <Parameter Key="Name" Value="{Binding Name}" />
<Parameter Key="Favourite" Value="{Binding Favourite}" /> <Parameter Key="Favourite" Value="{Binding Favourite}" />
@@ -32,7 +31,6 @@
Region="{Binding Named, StringFormat='{}{0}:Content'}" Region="{Binding Named, StringFormat='{}{0}:Content'}"
Route="Item" Route="Item"
Scope="self"> Scope="self">
<Parameter Key="FromCategory" Value="{x:False}" />
<Parameter Key="Name" Value="{Binding Name}" /> <Parameter Key="Name" Value="{Binding Name}" />
<Parameter Key="State" Value="{x:Static vm:ItemState.Read}" /> <Parameter Key="State" Value="{x:Static vm:ItemState.Read}" />
<Parameter Key="Favourite" Value="{Binding Favourite}" /> <Parameter Key="Favourite" Value="{Binding Favourite}" />
-12
View File
@@ -24,18 +24,6 @@
<NavigateBackAction Region="Left" /> <NavigateBackAction Region="Left" />
</ConditionAction> </ConditionAction>
</DataTriggerBehavior> </DataTriggerBehavior>
<DataTriggerBehavior
Binding="{Binding SelectedItem}"
ComparisonCondition="Equal"
Value="{x:Null}">
<NavigateAction
Region="{Binding Named, StringFormat='{}{0}:Content'}"
Route="Item"
Scope="self">
<Parameter Key="FromCategory" Value="{x:True}" />
<Parameter Key="State" Value="{x:Static vm:ItemState.Write}" />
</NavigateAction>
</DataTriggerBehavior>
</Interaction.Behaviors> </Interaction.Behaviors>
<ScrollViewer Padding="12,12,12,0"> <ScrollViewer Padding="12,12,12,0">
<ItemsControl ItemTemplate="{ReflectionBinding Template}" ItemsSource="{Binding}"> <ItemsControl ItemTemplate="{ReflectionBinding Template}" ItemsSource="{Binding}">
+24 -2
View File
@@ -2,6 +2,7 @@
x:Class="Bitvault.Avalonia.LockerNavigationView" x:Class="Bitvault.Avalonia.LockerNavigationView"
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:vm="using:Bitvault" xmlns:vm="using:Bitvault"
x:Name="NavigationViewItem" x:Name="NavigationViewItem"
x:DataType="vm:LockerNavigationViewModel" x:DataType="vm:LockerNavigationViewModel"
@@ -85,8 +86,29 @@
<InvokeNavigationViewItemAction /> <InvokeNavigationViewItemAction />
</ConditionAction> </ConditionAction>
</AttachedEventTriggerBehaviour> </AttachedEventTriggerBehaviour>
<DataTriggerBehavior Binding="{Binding Opened}" Value="False">
<RemoveClassAction ClassName="Closed" />
<AddClassAction ClassName="Closed" RemoveIfExists="True" />
</DataTriggerBehavior>
<DataTriggerBehavior Binding="{Binding Opened}" Value="True">
<RemoveClassAction ClassName="Opened" />
<AddClassAction ClassName="Opened" RemoveIfExists="True" />
</DataTriggerBehavior>
</Interaction.Behaviors> </Interaction.Behaviors>
<NavigationViewItem.IconSource> <NavigationViewItem.Styles>
<Style Selector="ui|NavigationViewItem.Closed">
<Setter Property="IconSource">
<Setter.Value>
<PathIconSource Data="M512,757.76C525.653,757.76 537.6,752.64 547.84,742.4C558.08,732.16 563.2,720.213 563.2,706.56C563.2,692.907 558.08,680.96 547.84,670.72C537.6,660.48 525.653,655.36 512,655.36C498.347,655.36 486.4,660.48 476.16,670.72C465.92,680.96 460.8,692.907 460.8,706.56C460.8,720.213 465.92,732.16 476.16,742.4C486.4,752.64 498.347,757.76 512,757.76ZM307.2,399.36L358.4,399.36L358.4,348.16C358.4,305.835 373.419,269.653 403.456,239.616C433.493,209.579 469.675,194.56 512,194.56C554.325,194.56 590.507,209.579 620.544,239.616C650.581,269.653 665.6,305.835 665.6,348.16L665.6,399.36L716.8,399.36C759.125,399.36 795.307,414.379 825.344,444.416C855.381,474.453 870.4,510.635 870.4,552.96L870.4,860.16C870.4,902.485 855.381,938.667 825.344,968.704C795.307,998.741 759.125,1013.76 716.8,1013.76L307.2,1013.76C264.875,1013.76 228.693,998.741 198.656,968.704C168.619,938.667 153.6,902.485 153.6,860.16L153.6,552.96C153.6,510.635 168.619,474.453 198.656,444.416C228.693,414.379 264.875,399.36 307.2,399.36ZM512,245.76C483.328,245.76 459.093,255.659 439.296,275.456C419.499,295.253 409.6,319.488 409.6,348.16L409.6,399.36L614.4,399.36L614.4,348.16C614.4,319.488 604.501,295.253 584.704,275.456C564.907,255.659 540.672,245.76 512,245.76ZM819.2,552.96C819.2,524.288 809.301,500.053 789.504,480.256C769.707,460.459 745.472,450.56 716.8,450.56L307.2,450.56C278.528,450.56 254.293,460.459 234.496,480.256C214.699,500.053 204.8,524.288 204.8,552.96L204.8,860.16C204.8,888.832 214.699,913.067 234.496,932.864C254.293,952.661 278.528,962.56 307.2,962.56L716.8,962.56C745.472,962.56 769.707,952.661 789.504,932.864C809.301,913.067 819.2,888.832 819.2,860.16Z" /> <PathIconSource Data="M512,757.76C525.653,757.76 537.6,752.64 547.84,742.4C558.08,732.16 563.2,720.213 563.2,706.56C563.2,692.907 558.08,680.96 547.84,670.72C537.6,660.48 525.653,655.36 512,655.36C498.347,655.36 486.4,660.48 476.16,670.72C465.92,680.96 460.8,692.907 460.8,706.56C460.8,720.213 465.92,732.16 476.16,742.4C486.4,752.64 498.347,757.76 512,757.76ZM307.2,399.36L358.4,399.36L358.4,348.16C358.4,305.835 373.419,269.653 403.456,239.616C433.493,209.579 469.675,194.56 512,194.56C554.325,194.56 590.507,209.579 620.544,239.616C650.581,269.653 665.6,305.835 665.6,348.16L665.6,399.36L716.8,399.36C759.125,399.36 795.307,414.379 825.344,444.416C855.381,474.453 870.4,510.635 870.4,552.96L870.4,860.16C870.4,902.485 855.381,938.667 825.344,968.704C795.307,998.741 759.125,1013.76 716.8,1013.76L307.2,1013.76C264.875,1013.76 228.693,998.741 198.656,968.704C168.619,938.667 153.6,902.485 153.6,860.16L153.6,552.96C153.6,510.635 168.619,474.453 198.656,444.416C228.693,414.379 264.875,399.36 307.2,399.36ZM512,245.76C483.328,245.76 459.093,255.659 439.296,275.456C419.499,295.253 409.6,319.488 409.6,348.16L409.6,399.36L614.4,399.36L614.4,348.16C614.4,319.488 604.501,295.253 584.704,275.456C564.907,255.659 540.672,245.76 512,245.76ZM819.2,552.96C819.2,524.288 809.301,500.053 789.504,480.256C769.707,460.459 745.472,450.56 716.8,450.56L307.2,450.56C278.528,450.56 254.293,460.459 234.496,480.256C214.699,500.053 204.8,524.288 204.8,552.96L204.8,860.16C204.8,888.832 214.699,913.067 234.496,932.864C254.293,952.661 278.528,962.56 307.2,962.56L716.8,962.56C745.472,962.56 769.707,952.661 789.504,932.864C809.301,913.067 819.2,888.832 819.2,860.16Z" />
</NavigationViewItem.IconSource> </Setter.Value>
</Setter>
</Style>
<Style Selector="ui|NavigationViewItem.Opened">
<Setter Property="IconSource">
<Setter.Value>
<PathIconSource Data="M512,757.76C525.653,757.76 537.6,752.64 547.84,742.4C558.08,732.16 563.2,720.213 563.2,706.56C563.2,692.907 558.08,680.96 547.84,670.72C537.6,660.48 525.653,655.36 512,655.36C498.347,655.36 486.4,660.48 476.16,670.72C465.92,680.96 460.8,692.907 460.8,706.56C460.8,720.213 465.92,732.16 476.16,742.4C486.4,752.64 498.347,757.76 512,757.76ZM768,194.56C739.328,194.56 715.093,204.459 695.296,224.256C675.499,244.053 665.6,268.288 665.6,296.96L665.6,399.36L716.8,399.36C759.125,399.36 795.307,414.379 825.344,444.416C855.381,474.453 870.4,510.635 870.4,552.96L870.4,860.16C870.4,902.485 855.381,938.667 825.344,968.704C795.307,998.741 759.125,1013.76 716.8,1013.76L307.2,1013.76C264.875,1013.76 228.693,998.741 198.656,968.704C168.619,938.667 153.6,902.485 153.6,860.16L153.6,552.96C153.6,510.635 168.619,474.453 198.656,444.416C228.693,414.379 264.875,399.36 307.2,399.36L614.4,399.36L614.4,296.96C614.4,254.635 629.419,218.453 659.456,188.416C689.493,158.379 725.675,143.36 768,143.36C810.325,143.36 846.507,158.379 876.544,188.416C906.581,218.453 921.6,254.635 921.6,296.96L921.6,321.536C921.6,329.728 919.211,336.213 914.432,340.992C909.653,345.771 903.509,348.16 896,348.16C888.491,348.16 882.347,345.771 877.568,340.992C872.789,336.213 870.4,330.411 870.4,323.584L870.4,296.96C870.4,268.288 860.501,244.053 840.704,224.256C820.907,204.459 796.672,194.56 768,194.56ZM716.8,450.56L307.2,450.56C278.528,450.56 254.293,460.459 234.496,480.256C214.699,500.053 204.8,524.288 204.8,552.96L204.8,860.16C204.8,888.832 214.699,913.067 234.496,932.864C254.293,952.661 278.528,962.56 307.2,962.56L716.8,962.56C745.472,962.56 769.707,952.661 789.504,932.864C809.301,913.067 819.2,888.832 819.2,860.16L819.2,552.96C819.2,524.288 809.301,500.053 789.504,480.256C769.707,460.459 745.472,450.56 716.8,450.56Z" />
</Setter.Value>
</Setter>
</Style>
</NavigationViewItem.Styles>
</NavigationViewItem> </NavigationViewItem>
+1
View File
@@ -8,6 +8,7 @@
FooterMenuItemsSource="{Binding Footer}" FooterMenuItemsSource="{Binding Footer}"
MenuItemTemplate="{Binding Template}" MenuItemTemplate="{Binding Template}"
MenuItemsSource="{Binding}" MenuItemsSource="{Binding}"
IsSettingsVisible="False"
SelectedItem="{Binding SelectedItem}" SelectedItem="{Binding SelectedItem}"
SelectionFollowsFocus="True"> SelectionFollowsFocus="True">
<NavigationView.Resources> <NavigationView.Resources>
+2
View File
@@ -15,6 +15,8 @@ public record ItemEntry
public int State { get; set; } = 0; public int State { get; set; } = 0;
public required string Category { get; set; }
public ICollection<TagEntry>? Tags { get; } public ICollection<TagEntry>? Tags { get; }
public ICollection<BlobEntry>? Blobs { get; } public ICollection<BlobEntry>? Blobs { get; }
@@ -2,19 +2,21 @@
namespace Bitvault; namespace Bitvault;
public class AggerateLockerItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors, public class AggerateItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors,
IServiceFactory serviceFactory, IServiceFactory serviceFactory,
IPublisher publisher) : IPublisher publisher) :
INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>> INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>>
{ {
public Task Handle(AggerateEventArgs<ItemCategoryNavigationViewModel> args) public Task Handle(AggerateEventArgs<ItemCategoryNavigationViewModel> args)
{ {
bool selected = true;
foreach (IConfigurationDescriptor<ItemConfiguration> descriptor in descriptors) foreach (IConfigurationDescriptor<ItemConfiguration> descriptor in descriptors)
{ {
if (serviceFactory.Create<ItemCategoryNavigationViewModel>(descriptor.Name) if (serviceFactory.Create<ItemCategoryNavigationViewModel>(descriptor.Name, selected)
is ItemCategoryNavigationViewModel viewModel) is ItemCategoryNavigationViewModel viewModel)
{ {
publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel)); publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel));
selected = false;
} }
} }
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
public class AggerateLockerItemViewModelHandler(IMediator mediator, public class AggerateItemViewModelHandler(IMediator mediator,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
ICache<Item<(Guid, string)>> cache, ICache<Item<(Guid, string)>> cache,
IPublisher publisher) : IPublisher publisher) :
@@ -45,7 +45,5 @@ public class AggerateLockerItemViewModelHandler(IMediator mediator,
} }
} }
} }
var d = cache;
} }
} }
+30
View File
@@ -0,0 +1,30 @@
using Toolkit.Foundation;
namespace Bitvault;
public class ConfirmCreateItemHandler(IMediator mediator,
IPublisher publisher) :
INotificationHandler<ConfirmEventArgs<Item>>
{
public async Task Handle(ConfirmEventArgs<Item> args)
{
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item>,
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<CreateEventArgs<(Guid, string, string,
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string, ItemConfiguration)>((id, name, category,
new ItemConfiguration())));
}
}
}
+4 -2
View File
@@ -8,8 +8,10 @@ public partial class ConfirmItemActionViewModel(IServiceProvider provider,
IMediator mediator, IMediator mediator,
IPublisher publisher, IPublisher publisher,
ISubscription subscriber, ISubscription subscriber,
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer) IDisposer disposer,
ItemState state) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
{ {
[RelayCommand] [RelayCommand]
public void Invoke() => Publisher.Publish(Confirm.As<Item>()); public void Invoke() => Publisher.Publish(Confirm.As<Item>(),
state is ItemState.New ? nameof(Create) : nameof(Update));
} }
@@ -2,7 +2,7 @@
namespace Bitvault; namespace Bitvault;
public class ConfirmItemHandler(IValueStore<Item<(Guid, string)>> valueStore, public class ConfirmUpdateItemHandler(IValueStore<Item<(Guid, string)>> store,
IMediator mediator, IMediator mediator,
IPublisher publisher) : IPublisher publisher) :
INotificationHandler<ConfirmEventArgs<Item>> INotificationHandler<ConfirmEventArgs<Item>>
@@ -16,33 +16,19 @@ public class ConfirmItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
{ {
publisher.Publish(Notify.As(configuration)); 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; (Guid id, string _) = item.Value;
string? name = configuration.Name; string? name = configuration.Name;
Item<(Guid, string)> newItem = new((id, name)); Item<(Guid, string)> newItem = new((id, name));
publisher.Publish(Modified.As(item, newItem)); publisher.Publish(Modified.As(item, newItem));
valueStore.Set(newItem); store.Set(newItem);
await mediator.Handle<UpdateEventArgs<(Guid, string, ItemConfiguration)>, bool>(new UpdateEventArgs<(Guid, string, await mediator.Handle<UpdateEventArgs<(Guid, string, ItemConfiguration)>, bool>(new UpdateEventArgs<(Guid, string,
ItemConfiguration)>((id, name, new ItemConfiguration()))); ItemConfiguration)>((id, name, new ItemConfiguration())));
} }
else
{
Guid id = Guid.NewGuid();
string? name = configuration.Name;
bool Success = await mediator.Handle<CreateEventArgs<(Guid, string,
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, ItemConfiguration)>((id, name, new ItemConfiguration())));
if (Success)
{
publisher.Publish(Created.As(new Item<(Guid, string)>((id, name))));
}
}
} }
} }
} }
+4 -4
View File
@@ -6,12 +6,12 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
public class CreateItemHandler(IDbContextFactory<LockerContext> dbContextFactory) : public class CreateItemHandler(IDbContextFactory<LockerContext> dbContextFactory) :
IHandler<CreateEventArgs<(Guid, string, ItemConfiguration)>, bool> IHandler<CreateEventArgs<(Guid, string, string, ItemConfiguration)>, bool>
{ {
public async Task<bool> Handle(CreateEventArgs<(Guid, string, ItemConfiguration)> args, public async Task<bool> Handle(CreateEventArgs<(Guid, string, string, ItemConfiguration)> args,
CancellationToken cancellationToken) 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 try
{ {
@@ -20,7 +20,7 @@ public class CreateItemHandler(IDbContextFactory<LockerContext> dbContextFactory
await Task.Run(async () => 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); await context.SaveChangesAsync(cancellationToken);
}, cancellationToken); }, cancellationToken);
+1 -1
View File
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
[Aggerate(nameof(ItemCategoryCollectionViewModel))] [Aggerate(typeof(CreateEventArgs<ItemCategoryNavigationViewModel>), nameof(ItemCategoryCollectionViewModel))]
public partial class ItemCategoryCollectionViewModel(IServiceProvider provider, public partial class ItemCategoryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory, IServiceFactory factory,
IMediator mediator, IMediator mediator,
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Toolkit.Foundation; using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
@@ -21,4 +22,6 @@ public partial class ItemCategoryNavigationViewModel(IServiceProvider provider,
[ObservableProperty] [ObservableProperty]
private bool selected = selected; private bool selected = selected;
[RelayCommand]
public void Invoke() => Publisher.Publish(Notify.As(new ItemCategory<string>(Name)));
} }
+4 -1
View File
@@ -3,7 +3,10 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
[Aggerate(nameof(ItemCollectionViewModel))] [Aggerate(typeof(AggerateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
[Notification(typeof(CreateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
[Notification(typeof(InsertEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
[Notification(typeof(MoveToEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
public partial class ItemCollectionViewModel : public partial class ItemCollectionViewModel :
ObservableCollection<ItemNavigationViewModel>, ObservableCollection<ItemNavigationViewModel>,
INotificationHandler<NotifyEventArgs<Filter>>, INotificationHandler<NotifyEventArgs<Filter>>,
+8 -2
View File
@@ -2,7 +2,7 @@
namespace Bitvault; namespace Bitvault;
[Aggerate(nameof(ItemContentViewModel))] //[Aggerate(nameof(ItemContentViewModel))]
public partial class ItemContentViewModel : public partial class ItemContentViewModel :
ObservableCollection<IItemEntryViewModel>, ObservableCollection<IItemEntryViewModel>,
IItemEntryViewModel, IItemEntryViewModel,
@@ -21,8 +21,14 @@ public partial class ItemContentViewModel :
public IContentTemplate Template { get; set; } public IContentTemplate Template { get; set; }
protected override IAggerate OnAggerate(object? key)
{
return base.OnAggerate(key);
}
public Task Handle(NotifyEventArgs<ItemCategory<string>> args) public Task Handle(NotifyEventArgs<ItemCategory<string>> args)
{ {
throw new NotImplementedException(); return Task.CompletedTask;
} }
} }
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
public class CreatedItemHandler(IServiceProvider serviceProvider, public class ItemCreatedHandler(IServiceProvider serviceProvider,
ICache<Item<(Guid, string)>> cache, ICache<Item<(Guid, string)>> cache,
IPublisher publisher) : IPublisher publisher) :
INotificationHandler<CreatedEventArgs<Item<(Guid, string)>>> INotificationHandler<CreatedEventArgs<Item<(Guid, string)>>>
+14
View File
@@ -9,8 +9,12 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
INotificationHandler<UpdateEventArgs<Item>>, INotificationHandler<UpdateEventArgs<Item>>,
INotificationHandler<ConfirmEventArgs<Item>>, INotificationHandler<ConfirmEventArgs<Item>>,
INotificationHandler<CancelEventArgs<Item>>, INotificationHandler<CancelEventArgs<Item>>,
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>,
IItemEntryViewModel IItemEntryViewModel
{ {
[ObservableProperty]
private string? category;
[ObservableProperty] [ObservableProperty]
private ItemState state; private ItemState state;
@@ -56,4 +60,14 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
State = ItemState.Read; State = ItemState.Read;
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Handle(NotifyEventArgs<ItemCategory<string>> args)
{
if (args.Value is ItemCategory<string> category)
{
Category = category.Value;
}
return Task.CompletedTask;
}
} }
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
public class ModifiedItemHandler(IServiceProvider serviceProvider, public class ItemModifiedHandler(IServiceProvider serviceProvider,
IPublisher publisher) : IPublisher publisher) :
INotificationHandler<ModifiedEventArgs<Item<(Guid, string)>>> INotificationHandler<ModifiedEventArgs<Item<(Guid, string)>>>
{ {
+1
View File
@@ -2,6 +2,7 @@
public enum ItemState public enum ItemState
{ {
New,
Read, Read,
Write Write
} }
+10 -6
View File
@@ -3,6 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
[Notification(typeof(ConfirmEventArgs<Item>), nameof(Create))]
public partial class ItemViewModel : public partial class ItemViewModel :
ObservableCollection<IItemEntryViewModel>, ObservableCollection<IItemEntryViewModel>,
INotificationHandler<UpdateEventArgs<Item>>, INotificationHandler<UpdateEventArgs<Item>>,
@@ -42,10 +43,10 @@ public partial class ItemViewModel :
bool favourite = false, bool favourite = false,
bool archived = false) : base(provider, factory, mediator, publisher, subscriber, disposer) bool archived = false) : base(provider, factory, mediator, publisher, subscriber, disposer)
{ {
FromCategory = fromCategory;
Named = $"{named}";
Template = template; Template = template;
Named = $"{named}";
State = state; State = state;
FromCategory = fromCategory;
Favourite = favourite; Favourite = favourite;
Archived = archived; Archived = archived;
Name = name; Name = name;
@@ -60,7 +61,7 @@ public partial class ItemViewModel :
{ {
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable> Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
{ {
Factory.Create<ConfirmItemActionViewModel>(), Factory.Create<ConfirmItemActionViewModel>(ItemState.Write),
Factory.Create<DismissItemActionViewModel>(), Factory.Create<DismissItemActionViewModel>(),
}))); })));
@@ -70,9 +71,12 @@ public partial class ItemViewModel :
public override void Dispose() public override void Dispose()
{ {
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>()))); Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new
List<IDisposable>())));
base.Dispose(); base.Dispose();
} }
public Task Handle(CancelEventArgs<Item> args) public Task Handle(CancelEventArgs<Item> args)
{ {
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable> Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
@@ -109,11 +113,11 @@ public partial class ItemViewModel :
} }
else else
{ {
if (State is ItemState.Write) if (State is ItemState.Write or ItemState.New)
{ {
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable> Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
{ {
Factory.Create<ConfirmItemActionViewModel>(), Factory.Create<ConfirmItemActionViewModel>(State),
Factory.Create<DismissItemActionViewModel>(), Factory.Create<DismissItemActionViewModel>(),
}))); })));
} }
+1 -1
View File
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault; namespace Bitvault;
[Aggerate(nameof(MainViewModel))] [Aggerate(typeof(CreateEventArgs<IMainNavigationViewModel>), nameof(MainViewModel))]
public partial class MainViewModel : public partial class MainViewModel :
ObservableCollection<IMainNavigationViewModel> ObservableCollection<IMainNavigationViewModel>
{ {