WIP: Item counts
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Main" Route="Wallet">
|
<NavigateAction Region="Main" Route="Wallet">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
</NavigateAction>
|
</NavigateAction>
|
||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
<ConditionAction>
|
<ConditionAction>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Left" Route="ItemCollection">
|
<NavigateAction Region="Left" Route="ItemCollection">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
<Parameter Key="Transition" Value="FromRight" />
|
<Parameter Key="Transition" Value="FromRight" />
|
||||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||||
@@ -33,4 +33,7 @@
|
|||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
</DataTriggerBehavior>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
|
<NavigationViewItem.InfoBadge>
|
||||||
|
<InfoBadge Value="{Binding Key}" />
|
||||||
|
</NavigationViewItem.InfoBadge>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ public partial class App : Application
|
|||||||
services.AddHandler<CreateItemHandler>();
|
services.AddHandler<CreateItemHandler>();
|
||||||
services.AddHandler<UpdateItemHander>();
|
services.AddHandler<UpdateItemHander>();
|
||||||
services.AddHandler<UpdateItemStateHandler>();
|
services.AddHandler<UpdateItemStateHandler>();
|
||||||
|
services.AddHandler<CountCategoriesHandler>();
|
||||||
|
|
||||||
services.AddHandler<OpenWalletHandler>();
|
services.AddHandler<OpenWalletHandler>();
|
||||||
|
|
||||||
@@ -184,6 +185,8 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddHandler<HyperlinkHandler>();
|
services.AddHandler<HyperlinkHandler>();
|
||||||
|
|
||||||
|
services.AddHandler<ItemChangedHandler>(ServiceLifetime.Singleton);
|
||||||
|
|
||||||
services.AddHandler<ArchiveItemHandler>();
|
services.AddHandler<ArchiveItemHandler>();
|
||||||
services.AddHandler<UnarchiveItemHandler>();
|
services.AddHandler<UnarchiveItemHandler>();
|
||||||
services.AddHandler<FavouriteItemHandler>();
|
services.AddHandler<FavouriteItemHandler>();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Main" Route="Wallet">
|
<NavigateAction Region="Main" Route="Wallet">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
</NavigateAction>
|
</NavigateAction>
|
||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
<ConditionAction>
|
<ConditionAction>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Left" Route="ItemCollection">
|
<NavigateAction Region="Left" Route="ItemCollection">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
<Parameter Key="Transition" Value="FromRight" />
|
<Parameter Key="Transition" Value="FromRight" />
|
||||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||||
@@ -33,4 +33,7 @@
|
|||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
</DataTriggerBehavior>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
|
<NavigationViewItem.InfoBadge>
|
||||||
|
<InfoBadge Value="{Binding Key}" />
|
||||||
|
</NavigationViewItem.InfoBadge>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:vm="using:Wallet"
|
xmlns:vm="using:Wallet"
|
||||||
x:DataType="vm:CategoryNavigationViewModel"
|
x:DataType="vm:CategoryNavigationViewModel"
|
||||||
Content="{Binding Filter}"
|
Content="{Binding Value}"
|
||||||
IsSelected="{Binding Selected}">
|
IsSelected="{Binding Selected}">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Main" Route="Wallet">
|
<NavigateAction Region="Main" Route="Wallet">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
</NavigateAction>
|
</NavigateAction>
|
||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
<ConditionAction>
|
<ConditionAction>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Left" Route="ItemCollection">
|
<NavigateAction Region="Left" Route="ItemCollection">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
<Parameter Key="Transition" Value="FromRight" />
|
<Parameter Key="Transition" Value="FromRight" />
|
||||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Main" Route="Wallet">
|
<NavigateAction Region="Main" Route="Wallet">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
</NavigateAction>
|
</NavigateAction>
|
||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
<ConditionAction>
|
<ConditionAction>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Region="Left" Route="ItemCollection">
|
<NavigateAction Region="Left" Route="ItemCollection">
|
||||||
<Parameter Key="Filter" Value="{Binding Filter}" />
|
<Parameter Key="Filter" Value="{Binding Value}" />
|
||||||
<Parameter Key="Transition" Value="FromRight" />
|
<Parameter Key="Transition" Value="FromRight" />
|
||||||
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
<Parameter Key="IsBackStackEnabled" Value="{x:True}" />
|
||||||
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
<Parameter Key="ClearBackStack" Value="{x:True}" />
|
||||||
@@ -33,5 +33,8 @@
|
|||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
</DataTriggerBehavior>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
|
<NavigationViewItem.InfoBadge>
|
||||||
|
<InfoBadge Value="{Binding Key}" />
|
||||||
|
</NavigationViewItem.InfoBadge>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,20 @@
|
|||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
|
[Notification(typeof(NotifyEventArgs<Item<int>>), "All")]
|
||||||
public partial class AllNavigationViewModel(IServiceProvider provider,
|
public partial class AllNavigationViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory, IMediator mediator,
|
||||||
IMediator mediator,
|
IPublisher publisher, ISubscription subscriber, IDisposer disposer, int key, string value) :
|
||||||
IPublisher publisher,
|
FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||||
ISubscription subscriber,
|
INotificationHandler<NotifyEventArgs<Item<int>>>
|
||||||
IDisposer disposer,
|
{
|
||||||
string filter) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
public Task Handle(NotifyEventArgs<Item<int>> args)
|
||||||
|
{
|
||||||
|
if (args.Sender is Item<int> item)
|
||||||
|
{
|
||||||
|
Key = item.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public record ArchiveEventArgs<TValue>(TValue Value);
|
public record ArchiveEventArgs<TSender>(TSender Sender);
|
||||||
@@ -4,7 +4,8 @@ namespace Wallet;
|
|||||||
|
|
||||||
public class ArchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
public class ArchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||||
ICache<Item<(Guid, string)>> cache,
|
ICache<Item<(Guid, string)>> cache,
|
||||||
IMediator mediator) :
|
IMediator mediator,
|
||||||
|
IPublisher publisher) :
|
||||||
INotificationHandler<ArchiveEventArgs<Item>>
|
INotificationHandler<ArchiveEventArgs<Item>>
|
||||||
{
|
{
|
||||||
public async Task Handle(ArchiveEventArgs<Item> args)
|
public async Task Handle(ArchiveEventArgs<Item> args)
|
||||||
@@ -21,6 +22,7 @@ public class ArchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decorato
|
|||||||
bool>(new UpdateEventArgs<(Guid, int)>((id, 2)));
|
bool>(new UpdateEventArgs<(Guid, int)>((id, 2)));
|
||||||
|
|
||||||
cache.Remove(item);
|
cache.Remove(item);
|
||||||
|
publisher.Publish(Changed.As(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,24 @@
|
|||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
|
[Notification(typeof(NotifyEventArgs<Item<int>>), "Archive")]
|
||||||
public partial class ArchiveNavigationViewModel(IServiceProvider provider,
|
public partial class ArchiveNavigationViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string name) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
int key,
|
||||||
|
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||||
|
INotificationHandler<NotifyEventArgs<Item<int>>>
|
||||||
|
{
|
||||||
|
public Task Handle(NotifyEventArgs<Item<int>> args)
|
||||||
|
{
|
||||||
|
if (args.Sender is Item<int> item)
|
||||||
|
{
|
||||||
|
Key = item.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,5 @@ public partial class CategoriesNavigationViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string name) : FilterNavigationViewModel<CategoryNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer, name)
|
int key,
|
||||||
{
|
string value) : FilterNavigationViewModel<CategoryNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer, key, value);
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,4 +8,4 @@ public partial class CategoryNavigationViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string filter) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, 0, value);
|
||||||
@@ -13,15 +13,19 @@ public class ConfirmCreateItemHandler(IMediator mediator,
|
|||||||
if (itemHeaderConfiguration.Service is ItemHeaderConfiguration headerConfiguration &&
|
if (itemHeaderConfiguration.Service is ItemHeaderConfiguration headerConfiguration &&
|
||||||
itemConfigurationDecorator.Service is ItemConfiguration itemConfiguration)
|
itemConfigurationDecorator.Service is ItemConfiguration itemConfiguration)
|
||||||
{
|
{
|
||||||
string? name = headerConfiguration?.Name;
|
if (headerConfiguration.Name is { Length: > 0 } name &&
|
||||||
if (name is not null)
|
headerConfiguration.Category is { Length: > 0 } category)
|
||||||
{
|
{
|
||||||
Guid id = Guid.NewGuid();
|
Guid id = Guid.NewGuid();
|
||||||
publisher.Publish(Created.As(new Item<(Guid, string)>((id, name))));
|
|
||||||
|
Item<(Guid, string)> item = new((id, name));
|
||||||
|
publisher.Publish(Created.As(item));
|
||||||
|
|
||||||
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
||||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string,
|
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string,
|
||||||
ItemConfiguration)>((id, name, "", itemConfiguration)));
|
ItemConfiguration)>((id, name, category, itemConfiguration)));
|
||||||
|
|
||||||
|
publisher.Publish(Changed.As(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class ConfirmUpdateItemHandler(IDecoratorService<Item<(Guid, string)>> it
|
|||||||
|
|
||||||
await mediator.Handle<UpdateEventArgs<Item<(Guid, string, ItemConfiguration)>>, bool>(new UpdateEventArgs<Item<(Guid, string,
|
await mediator.Handle<UpdateEventArgs<Item<(Guid, string, ItemConfiguration)>>, bool>(new UpdateEventArgs<Item<(Guid, string,
|
||||||
ItemConfiguration)>>(new Item<(Guid, string, ItemConfiguration)>((id, name, itemConfiguration))));
|
ItemConfiguration)>>(new Item<(Guid, string, ItemConfiguration)>((id, name, itemConfiguration))));
|
||||||
|
|
||||||
|
publisher.Publish(Changed.As(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Linq;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
using Wallet.Data;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class CountCategoriesHandler(IDbContextFactory<WalletContext> dbContextFactory) :
|
||||||
|
IHandler<CountEventArgs<ItemCategory>, IReadOnlyCollection<(string, int)>>
|
||||||
|
{
|
||||||
|
public async Task<IReadOnlyCollection<(string, int)>> Handle(CountEventArgs<ItemCategory> args,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var stateCounts = await context.Items
|
||||||
|
.GroupBy(i => i.State)
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
var categoryCounts = await context.Items.Where(x => !string.IsNullOrEmpty(x.Category))
|
||||||
|
.GroupBy(i => i.Category)
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
int allCount = stateCounts.Where(x => x.Key != 2).Sum(x => x.Count);
|
||||||
|
int favouritesCount = stateCounts.Where(x => x.Key == 1).Sum(x => x.Count);
|
||||||
|
int archiveCount = stateCounts.Where(x => x.Key == 2).Sum(x => x.Count);
|
||||||
|
|
||||||
|
List<(string, int)> combinedCounts =
|
||||||
|
[
|
||||||
|
new("Favourites", favouritesCount),
|
||||||
|
new("Archive", archiveCount),
|
||||||
|
new("All", allCount)
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ((string key, int count) in categoryCounts.Select(x => (x.Key, x.Count)))
|
||||||
|
{
|
||||||
|
combinedCounts.Add((key, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
return combinedCounts;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public record FavouriteEventArgs<TValue>(TValue Value);
|
public record FavouriteEventArgs<TSender>(TSender Sender);
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public class FavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
public class FavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||||
IMediator mediator) :
|
IMediator mediator,
|
||||||
|
IPublisher publisher) :
|
||||||
INotificationHandler<FavouriteEventArgs<Item>>
|
INotificationHandler<FavouriteEventArgs<Item>>
|
||||||
{
|
{
|
||||||
public async Task Handle(FavouriteEventArgs<Item> args)
|
public async Task Handle(FavouriteEventArgs<Item> args)
|
||||||
@@ -14,6 +15,8 @@ public class FavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decora
|
|||||||
{
|
{
|
||||||
(Guid id, string name) = item.Value;
|
(Guid id, string name) = item.Value;
|
||||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 1)));
|
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 1)));
|
||||||
|
|
||||||
|
publisher.Publish(Changed.As(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public partial class FilterNavigationViewModel :
|
public partial class FilterNavigationViewModel :
|
||||||
ObservableCollection<IWalletNavigationViewModel>,
|
ObservableCollection<IWalletNavigationViewModel, int, string>,
|
||||||
IWalletNavigationViewModel,
|
IWalletNavigationViewModel,
|
||||||
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
||||||
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
||||||
@@ -12,9 +12,6 @@ public partial class FilterNavigationViewModel :
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool activated;
|
private bool activated;
|
||||||
|
|
||||||
[ObservableProperty]
|
|
||||||
private string? filter;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool selected;
|
private bool selected;
|
||||||
|
|
||||||
@@ -24,9 +21,10 @@ public partial class FilterNavigationViewModel :
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
int key,
|
||||||
|
string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
||||||
{
|
{
|
||||||
Filter = filter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
||||||
@@ -37,7 +35,7 @@ public partial class FilterNavigationViewModel :
|
|||||||
}
|
}
|
||||||
|
|
||||||
public partial class FilterNavigationViewModel<TWalletNavigation> :
|
public partial class FilterNavigationViewModel<TWalletNavigation> :
|
||||||
ObservableCollection<TWalletNavigation>,
|
ObservableCollection<TWalletNavigation, int, string>,
|
||||||
IWalletNavigationViewModel,
|
IWalletNavigationViewModel,
|
||||||
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
||||||
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
INotificationHandler<DeactivatedEventArgs<Wallet>>
|
||||||
@@ -47,9 +45,6 @@ public partial class FilterNavigationViewModel<TWalletNavigation> :
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool activated;
|
private bool activated;
|
||||||
|
|
||||||
[ObservableProperty]
|
|
||||||
private string? filter;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool selected;
|
private bool selected;
|
||||||
|
|
||||||
@@ -59,9 +54,10 @@ public partial class FilterNavigationViewModel<TWalletNavigation> :
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
int key,
|
||||||
|
string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
||||||
{
|
{
|
||||||
Filter = filter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class ItemChangedHandler(IMediator mediator,
|
||||||
|
IPublisher publisher) :
|
||||||
|
INotificationHandler<ChangedEventArgs<Item<(Guid, string)>>>
|
||||||
|
{
|
||||||
|
public async Task Handle(ChangedEventArgs<Item<(Guid, string)>> args)
|
||||||
|
{
|
||||||
|
IReadOnlyCollection<(string, int)>? categoryCounts = await mediator.Handle<CountEventArgs<ItemCategory>,
|
||||||
|
IReadOnlyCollection<(string, int)>>(Count.As<ItemCategory>());
|
||||||
|
|
||||||
|
if (categoryCounts is { Count: > 0 } )
|
||||||
|
{
|
||||||
|
foreach ((string key, int count) in categoryCounts)
|
||||||
|
{
|
||||||
|
publisher.Publish(Notify.As(new Item<int>(count)), key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,4 +3,6 @@
|
|||||||
public class ItemHeaderConfiguration
|
public class ItemHeaderConfiguration
|
||||||
{
|
{
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Category { get; set; }
|
||||||
}
|
}
|
||||||
@@ -70,6 +70,7 @@ public partial class ItemHeaderViewModel :
|
|||||||
if (args.Sender is ItemCategory<string> category)
|
if (args.Sender is ItemCategory<string> category)
|
||||||
{
|
{
|
||||||
Category = category.Value;
|
Category = category.Value;
|
||||||
|
configuration.Category = category.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class QueryWalletHandler(IDbContextFactory<WalletContext> dbContextFactor
|
|||||||
Handle(QueryEventArgs<Wallet<(string, string)>> args,CancellationToken cancellationToken)
|
Handle(QueryEventArgs<Wallet<(string, string)>> args,CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
List<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)> items = [];
|
List<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)> items = [];
|
||||||
if (args.Value is Wallet<(string, string)> Wallet)
|
if (args.Sender is Wallet<(string, string)> Wallet)
|
||||||
{
|
{
|
||||||
(string filter, string text) = Wallet.Sender;
|
(string filter, string text) = Wallet.Sender;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,24 @@
|
|||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
|
[Notification(typeof(NotifyEventArgs<Item<int>>), "Favourites")]
|
||||||
public partial class StarredNavigationViewModel(IServiceProvider provider,
|
public partial class StarredNavigationViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string name) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
int key,
|
||||||
|
string value) : FilterNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||||
|
INotificationHandler<NotifyEventArgs<Item<int>>>
|
||||||
|
{
|
||||||
|
public Task Handle(NotifyEventArgs<Item<int>> args)
|
||||||
|
{
|
||||||
|
if (args.Sender is Item<int> item)
|
||||||
|
{
|
||||||
|
Key = item.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public record UnarchiveEventArgs<TValue>(TValue Value);
|
public record UnarchiveEventArgs<TSender>(TSender Sender);
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using Wallet.Data;
|
using Toolkit.Foundation;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.Threading;
|
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||||
IDbContextFactory<WalletContext> dbContextFactory) :
|
ICache<Item<(Guid, string)>> cache,
|
||||||
|
IMediator mediator,
|
||||||
|
IPublisher publisher) :
|
||||||
INotificationHandler<UnarchiveEventArgs<Item>>
|
INotificationHandler<UnarchiveEventArgs<Item>>
|
||||||
{
|
{
|
||||||
public async Task Handle(UnarchiveEventArgs<Item> args)
|
public async Task Handle(UnarchiveEventArgs<Item> args)
|
||||||
@@ -17,12 +16,11 @@ public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decora
|
|||||||
{
|
{
|
||||||
(Guid id, string name) = item.Value;
|
(Guid id, string name) = item.Value;
|
||||||
|
|
||||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync();
|
await mediator.Handle<UpdateEventArgs<(Guid, int)>,
|
||||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
bool>(new UpdateEventArgs<(Guid, int)>((id, 0)));
|
||||||
{
|
|
||||||
result.State = 0;
|
cache.Add(item);
|
||||||
await context.SaveChangesAsync();
|
publisher.Publish(Changed.As(item));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public record UnfavouriteEventArgs<TValue>(TValue Value);
|
public record UnfavouriteEventArgs<TSender>(TSender Sender);
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public class UnfavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
public class UnfavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
|
||||||
IMediator mediator) :
|
IMediator mediator,
|
||||||
|
IPublisher publisher) :
|
||||||
INotificationHandler<UnfavouriteEventArgs<Item>>
|
INotificationHandler<UnfavouriteEventArgs<Item>>
|
||||||
{
|
{
|
||||||
public async Task Handle(UnfavouriteEventArgs<Item> args)
|
public async Task Handle(UnfavouriteEventArgs<Item> args)
|
||||||
@@ -13,6 +15,8 @@ public class UnfavouriteItemHandler(IDecoratorService<Item<(Guid, string)>> deco
|
|||||||
{
|
{
|
||||||
(Guid id, string name) = item.Value;
|
(Guid id, string name) = item.Value;
|
||||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 0)));
|
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 0)));
|
||||||
|
|
||||||
|
publisher.Publish(Changed.As(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -11,16 +11,13 @@ public class UpdateItemStateHandler(IDbContextFactory<WalletContext> dbContextFa
|
|||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (args.Value is (Guid id, int state))
|
if (args.Value is (Guid id, int state))
|
||||||
{
|
|
||||||
await Task.Run(async () =>
|
|
||||||
{
|
{
|
||||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
||||||
{
|
{
|
||||||
result.State = state;
|
result.State = state;
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
}, cancellationToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ public partial class WalletNavigationViewModel :
|
|||||||
|
|
||||||
public Task Handle(OpenedEventArgs<Wallet> args)
|
public Task Handle(OpenedEventArgs<Wallet> args)
|
||||||
{
|
{
|
||||||
Add<AllNavigationViewModel>("All");
|
Add<AllNavigationViewModel>("All", 0);
|
||||||
Add<StarredNavigationViewModel>("Starred");
|
Add<StarredNavigationViewModel>("Starred", 0);
|
||||||
Add<ArchiveNavigationViewModel>("Archive");
|
Add<ArchiveNavigationViewModel>("Archive", 0);
|
||||||
Add<CategoriesNavigationViewModel>("Categories");
|
Add<CategoriesNavigationViewModel>("Categories", 0);
|
||||||
|
|
||||||
Opened = true;
|
Opened = true;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|||||||
Reference in New Issue
Block a user