Populate navigation caterogies
This commit is contained in:
@@ -2,7 +2,9 @@ using Toolkit.UI.Controls.Avalonia;
|
|||||||
|
|
||||||
namespace Wallet.Avalonia;
|
namespace Wallet.Avalonia;
|
||||||
|
|
||||||
public partial class AllNavigationView : NavigationViewItem
|
public partial class AllNavigationView :
|
||||||
|
NavigationViewItem
|
||||||
{
|
{
|
||||||
public AllNavigationView() => InitializeComponent();
|
public AllNavigationView() =>
|
||||||
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ public partial class App : Application
|
|||||||
.AddConfiguration("Item:Note", ItemConfiguration.Note)
|
.AddConfiguration("Item:Note", ItemConfiguration.Note)
|
||||||
.AddConfiguration("Item:Password", ItemConfiguration.Password)
|
.AddConfiguration("Item:Password", ItemConfiguration.Password)
|
||||||
.AddConfiguration("Item:Passport", ItemConfiguration.Passport)
|
.AddConfiguration("Item:Passport", ItemConfiguration.Passport)
|
||||||
.AddConfiguration("Item:Api Credentials", ItemConfiguration.ApiCredentials)
|
.AddConfiguration("Item:API Credentials", ItemConfiguration.ApiCredentials)
|
||||||
.AddConfiguration("Item:Software License", ItemConfiguration.SoftwareLicense)
|
.AddConfiguration("Item:Software License", ItemConfiguration.SoftwareLicense)
|
||||||
.AddConfiguration("Item:Crypto", ItemConfiguration.CryptoWallet)
|
.AddConfiguration("Item:Crypto", ItemConfiguration.CryptoWallet)
|
||||||
.AddConfiguration("Item:Database", ItemConfiguration.Database)
|
.AddConfiguration("Item:Database", ItemConfiguration.Database)
|
||||||
@@ -84,8 +84,8 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddTransient<IItemConfigurationCollection, ItemConfigurationCollection>(provider =>
|
services.AddTransient<IItemConfigurationCollection, ItemConfigurationCollection>(provider =>
|
||||||
{
|
{
|
||||||
IEnumerable<IConfigurationDescriptor<ItemConfiguration>> items =
|
IEnumerable<IConfigurationDescriptor<ItemConfiguration>> items =
|
||||||
provider.GetServices<IConfigurationDescriptor<ItemConfiguration>>() ??
|
provider.GetServices<IConfigurationDescriptor<ItemConfiguration>>().OrderBy(x => x.Name) ??
|
||||||
Enumerable.Empty<IConfigurationDescriptor<ItemConfiguration>>();
|
Enumerable.Empty<IConfigurationDescriptor<ItemConfiguration>>();
|
||||||
|
|
||||||
return new ItemConfigurationCollection(items.ToDictionary(x => x.Name, x => (Func<ItemConfiguration>)(() => x.Value)));
|
return new ItemConfigurationCollection(items.ToDictionary(x => x.Name, x => (Func<ItemConfiguration>)(() => x.Value)));
|
||||||
@@ -115,6 +115,7 @@ public partial class App : Application
|
|||||||
services.AddTemplate<AllNavigationViewModel, AllNavigationView>();
|
services.AddTemplate<AllNavigationViewModel, AllNavigationView>();
|
||||||
services.AddTemplate<StarredNavigationViewModel, StarredNavigationView>();
|
services.AddTemplate<StarredNavigationViewModel, StarredNavigationView>();
|
||||||
services.AddTemplate<CategoriesNavigationViewModel, CategoriesNavigationView>();
|
services.AddTemplate<CategoriesNavigationViewModel, CategoriesNavigationView>();
|
||||||
|
services.AddTemplate<CategoryNavigationViewModel, CategoryNavigationView>();
|
||||||
services.AddTemplate<ArchiveNavigationViewModel, ArchiveNavigationView>();
|
services.AddTemplate<ArchiveNavigationViewModel, ArchiveNavigationView>();
|
||||||
|
|
||||||
services.AddTemplate<OpenWalletViewModel, OpenWalletView>("OpenWallet");
|
services.AddTemplate<OpenWalletViewModel, OpenWalletView>("OpenWallet");
|
||||||
@@ -133,7 +134,9 @@ 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<SynchronizeCategoriesNavigationViewModelHandler>();
|
||||||
|
|
||||||
services.AddHandler<SynchronizeItemCategoryViewModelHandler>();
|
services.AddHandler<SynchronizeItemCategoryViewModelHandler>();
|
||||||
|
|
||||||
services.AddScoped<IDecoratorService<Item<(Guid, string)>>, DecoratorService<Item<(Guid, string)>>>();
|
services.AddScoped<IDecoratorService<Item<(Guid, string)>>, DecoratorService<Item<(Guid, string)>>>();
|
||||||
|
|||||||
@@ -2,4 +2,7 @@
|
|||||||
x:Class="Wallet.Avalonia.CategoriesNavigationView"
|
x:Class="Wallet.Avalonia.CategoriesNavigationView"
|
||||||
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"
|
||||||
Content="Categories" />
|
xmlns:vm="using:Wallet"
|
||||||
|
x:DataType="vm:CategoriesNavigationViewModel"
|
||||||
|
Content="Categories"
|
||||||
|
MenuItemsSource="{Binding}" />
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ using Toolkit.UI.Controls.Avalonia;
|
|||||||
|
|
||||||
namespace Wallet.Avalonia;
|
namespace Wallet.Avalonia;
|
||||||
|
|
||||||
public partial class CategoriesNavigationView : NavigationViewItem
|
public partial class CategoriesNavigationView :
|
||||||
|
NavigationViewItem
|
||||||
{
|
{
|
||||||
public CategoriesNavigationView() => InitializeComponent();
|
public CategoriesNavigationView() =>
|
||||||
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<NavigationViewItem
|
||||||
|
x:Class="Wallet.Avalonia.CategoryNavigationView"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Wallet"
|
||||||
|
x:DataType="vm:CategoryNavigationViewModel"
|
||||||
|
Content="{Binding Filter}" />
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
|
namespace Wallet.Avalonia;
|
||||||
|
|
||||||
|
public partial class CategoryNavigationView :
|
||||||
|
NavigationViewItem
|
||||||
|
{
|
||||||
|
public CategoryNavigationView() =>
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
@@ -8,4 +8,4 @@ public partial class AllNavigationViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string filter) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
string filter) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
||||||
@@ -8,4 +8,4 @@ public partial class ArchiveNavigationViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string name) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
string name) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||||
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
|
[Notification(typeof(CreateEventArgs<CategoryNavigationViewModel>), nameof(CategoriesNavigationViewModel))]
|
||||||
public partial class CategoriesNavigationViewModel(IServiceProvider provider,
|
public partial class CategoriesNavigationViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string name) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
string name) : FilterNavigationViewModel<CategoryNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer, name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public partial class CategoryNavigationViewModel(IServiceProvider provider,
|
||||||
|
IServiceFactory factory,
|
||||||
|
IMediator mediator,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscription subscriber,
|
||||||
|
IDisposer disposer,
|
||||||
|
string filter) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public partial class FilterNavigationViewModel :
|
||||||
|
ObservableCollection<IWalletNavigationViewModel>,
|
||||||
|
IWalletNavigationViewModel,
|
||||||
|
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
||||||
|
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool activated;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? filter;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool selected;
|
||||||
|
|
||||||
|
public FilterNavigationViewModel(IServiceProvider provider,
|
||||||
|
IServiceFactory factory,
|
||||||
|
IMediator mediator,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscription subscriber,
|
||||||
|
IDisposer disposer,
|
||||||
|
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
Filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
||||||
|
Task.FromResult(Activated = false);
|
||||||
|
|
||||||
|
public Task Handle(ActivatedEventArgs<Wallet> args) =>
|
||||||
|
Task.FromResult(Activated = true);
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
public void Invoke() => Publisher.Publish(Notify.As(new Filter(Filter)),
|
||||||
|
nameof(ItemCollectionViewModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class FilterNavigationViewModel<TWalletNavigation> :
|
||||||
|
ObservableCollection<TWalletNavigation>,
|
||||||
|
IWalletNavigationViewModel,
|
||||||
|
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
||||||
|
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
||||||
|
where TWalletNavigation : IWalletNavigationViewModel
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool activated;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? filter;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool selected;
|
||||||
|
|
||||||
|
public FilterNavigationViewModel(IServiceProvider provider,
|
||||||
|
IServiceFactory factory,
|
||||||
|
IMediator mediator,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscription subscriber,
|
||||||
|
IDisposer disposer,
|
||||||
|
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
Filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
||||||
|
Task.FromResult(Activated = false);
|
||||||
|
|
||||||
|
public Task Handle(ActivatedEventArgs<Wallet> args) =>
|
||||||
|
Task.FromResult(Activated = true);
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
public void Invoke() => Publisher.Publish(Notify.As(new Filter(Filter)),
|
||||||
|
nameof(ItemCollectionViewModel));
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
|
||||||
using CommunityToolkit.Mvvm.Input;
|
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Wallet;
|
|
||||||
|
|
||||||
public partial class FilterWalletNavigationViewModel : Observable,
|
|
||||||
IWalletNavigationViewModel,
|
|
||||||
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
|
||||||
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
private bool activated;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
|
||||||
private string? filter;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
|
||||||
private bool selected;
|
|
||||||
|
|
||||||
public FilterWalletNavigationViewModel(IServiceProvider provider,
|
|
||||||
IServiceFactory factory,
|
|
||||||
IMediator mediator,
|
|
||||||
IPublisher publisher,
|
|
||||||
ISubscription subscriber,
|
|
||||||
IDisposer disposer,
|
|
||||||
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
|
||||||
{
|
|
||||||
Filter = filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
|
||||||
Task.FromResult(Activated = false);
|
|
||||||
|
|
||||||
public Task Handle(ActivatedEventArgs<Wallet> args) =>
|
|
||||||
Task.FromResult(Activated = true);
|
|
||||||
|
|
||||||
[RelayCommand]
|
|
||||||
public void Invoke() => Publisher.Publish(Notify.As(new Filter(Filter)),
|
|
||||||
nameof(ItemCollectionViewModel));
|
|
||||||
}
|
|
||||||
@@ -8,4 +8,4 @@ public partial class StarredNavigationViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string name) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
string name) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class SynchronizeCategoriesNavigationViewModelHandler(IItemConfigurationCollection configurations,
|
||||||
|
IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher) :
|
||||||
|
INotificationHandler<SynchronizeEventArgs<CategoryNavigationViewModel>>
|
||||||
|
{
|
||||||
|
public Task Handle(SynchronizeEventArgs<CategoryNavigationViewModel> args)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<string, Func<ItemConfiguration>> configuration in configurations)
|
||||||
|
{
|
||||||
|
if (serviceFactory.Create<CategoryNavigationViewModel>(configuration.Key)
|
||||||
|
is CategoryNavigationViewModel viewModel)
|
||||||
|
{
|
||||||
|
publisher.Publish(Create.As(viewModel), nameof(CategoriesNavigationViewModel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ public partial class WalletViewModel :
|
|||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string filter;
|
private string filter;
|
||||||
|
|
||||||
public WalletViewModel(IServiceProvider provider,
|
public WalletViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
|
|||||||
Reference in New Issue
Block a user