Got adding working again
This commit is contained in:
@@ -7,9 +7,9 @@ public class AggerateContainerViewModelHandler(IMediator mediator,
|
||||
IServiceProvider serviceProvider,
|
||||
ICache<Item> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<Aggerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||
INotificationHandler<AggerateEventArgs<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||
{
|
||||
public async Task Handle(Aggerate<ItemNavigationViewModel,
|
||||
public async Task Handle(AggerateEventArgs<ItemNavigationViewModel,
|
||||
ContainerViewModelConfiguration> args)
|
||||
{
|
||||
if (args.Options is ContainerViewModelConfiguration configuration)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggerateItemViewModelHandler(IMediator mediator,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<IItemEntryViewModel>>
|
||||
{
|
||||
public Task Handle(AggerateEventArgs<IItemEntryViewModel> args)
|
||||
{
|
||||
if (serviceFactory.Create<ItemHeaderViewModel>(false) is ItemHeaderViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Create.As<IItemEntryViewModel>(viewModel), nameof(ItemViewModel));
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,21 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ConfirmItemHandler(IMediator mediator) :
|
||||
public class ConfirmItemHandler(IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
{
|
||||
(bool result, int index) result = await mediator.Handle<CreateEventArgs<ItemConfiguration>,
|
||||
(bool, int)>(new CreateEventArgs<ItemConfiguration>(new ItemConfiguration()));
|
||||
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item>,
|
||||
ItemHeaderConfiguration>(args);
|
||||
|
||||
(bool Success, int Id, string Name) result = await mediator.Handle<CreateEventArgs<ItemConfiguration>,
|
||||
(bool, int, string)>(new CreateEventArgs<ItemConfiguration>(new ItemConfiguration { Name = configuration?.Name }));
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
publisher.Publish(Activated.As(new Item { Id = result.Id, Name = result.Name }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,20 +15,9 @@ public partial class ContainerHeaderViewModel :
|
||||
{
|
||||
Template = template;
|
||||
|
||||
Add<SearchContainerActionViewModel>();
|
||||
|
||||
//Add<CreateItemActionViewModel>(scope: true);
|
||||
Add<CreateItemActionViewModel>(0);
|
||||
Add<SearchContainerActionViewModel>(2);
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
//public Task Handle(RequestEventArgs<Filter<string>> args)
|
||||
//{
|
||||
// if (args.Value is Filter<string> filter)
|
||||
// {
|
||||
// Value = filter.Value;
|
||||
// }
|
||||
|
||||
// return Task.CompletedTask;
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
|
||||
[Enumerate(nameof(ContainerViewModel))]
|
||||
[Aggerate(nameof(ContainerViewModel))]
|
||||
public partial class ContainerViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
@@ -13,7 +13,7 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
NamedComponent named,
|
||||
ContainerViewModelConfiguration configuration) : Toolkit.Foundation.ObservableCollection<ItemNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
ContainerViewModelConfiguration configuration) : ObservableCollection<ItemNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
INotificationHandler<NotifyEventArgs<Filter>>,
|
||||
INotificationHandler<NotifyEventArgs<Search>>
|
||||
{
|
||||
@@ -39,7 +39,7 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
||||
if (args.Value is Filter filter)
|
||||
{
|
||||
configuration = configuration with { Filter = filter.Value };
|
||||
Aggerate();
|
||||
BeginAggregation();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -49,12 +49,12 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
||||
if (args.Value is Search search)
|
||||
{
|
||||
configuration = configuration with { Query = search.Value };
|
||||
Aggerate();
|
||||
BeginAggregation();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override IAggerate OnAggerate(object? key) =>
|
||||
AggerateEventArgs<ItemNavigationViewModel>.With(configuration) with { Key = key };
|
||||
protected override IAggerate OnPrepareAggregation(object? key) =>
|
||||
Aggerate.With<ItemNavigationViewModel, ContainerViewModelConfiguration>(configuration) with { Key = key };
|
||||
}
|
||||
@@ -9,8 +9,11 @@ public partial class CreateItemActionViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
NamedComponent named) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
NamedComponent named,
|
||||
int index) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private int index = index;
|
||||
|
||||
[ObservableProperty]
|
||||
private string named = $"{named}";
|
||||
|
||||
@@ -6,9 +6,9 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
public class CreateItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<CreateEventArgs<ItemConfiguration>, (bool, int)>
|
||||
IHandler<CreateEventArgs<ItemConfiguration>, (bool, int, string?)>
|
||||
{
|
||||
public async Task<(bool, int)> Handle(CreateEventArgs<ItemConfiguration> args,
|
||||
public async Task<(bool, int, string?)> Handle(CreateEventArgs<ItemConfiguration> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (args.Value is ItemConfiguration configuration)
|
||||
@@ -27,7 +27,7 @@ public class CreateItemHander(IDbContextFactory<ContainerDbContext> dbContextFac
|
||||
|
||||
if (result is not null)
|
||||
{
|
||||
return (false, -1);
|
||||
return (true, result.Entity.Id, result.Entity.Name);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -36,6 +36,6 @@ public class CreateItemHander(IDbContextFactory<ContainerDbContext> dbContextFac
|
||||
}
|
||||
}
|
||||
|
||||
return (false, -1);
|
||||
return (false, -1, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IItemEntryViewModel :
|
||||
IDisposable
|
||||
{
|
||||
|
||||
}
|
||||
@@ -4,3 +4,28 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemActivatedHandler(IServiceProvider serviceProvider,
|
||||
ICache<Item> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ActivatedEventArgs<Item>>
|
||||
{
|
||||
public Task Handle(ActivatedEventArgs<Item> args)
|
||||
{
|
||||
if (args.Value is Item item)
|
||||
{
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
|
||||
cache.Add(item);
|
||||
int index = cache.IndexOf(item);
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1, true)
|
||||
is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Insert.As(index, viewModel), nameof(ContainerViewModel));
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ public partial class ItemCommandHeaderViewModel(IServiceProvider provider,
|
||||
public Task Handle(NotifyEventArgs<CommandCollection> args)
|
||||
{
|
||||
Clear();
|
||||
|
||||
if (args.Value is CommandCollection commandCollection)
|
||||
{
|
||||
foreach (IDisposable command in commandCollection)
|
||||
|
||||
@@ -12,7 +12,8 @@ public partial class ItemHeaderViewModel(IServiceProvider provider,
|
||||
bool immutable,
|
||||
string? value = null) : Observable<string, string>(provider, factory, mediator, publisher, subscriber, disposer, value),
|
||||
IHandler<ValidationEventArgs<Item>, bool>,
|
||||
IHandler<ConfirmEventArgs<Item>, ItemHeaderConfiguration>
|
||||
IHandler<ConfirmEventArgs<Item>, ItemHeaderConfiguration>,
|
||||
IItemEntryViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool immutable = immutable;
|
||||
@@ -20,7 +21,6 @@ public partial class ItemHeaderViewModel(IServiceProvider provider,
|
||||
public Task<bool> Handle(ValidationEventArgs<Item> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// we need to work on the local validation layer
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
string name,
|
||||
string description,
|
||||
bool selected,
|
||||
bool favourite,
|
||||
bool archived) :
|
||||
bool favourite = false,
|
||||
bool archived = false) :
|
||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
INotificationHandler<ArchiveEventArgs<Item>>,
|
||||
INotificationHandler<UnarchiveEventArgs<Item>>,
|
||||
|
||||
+41
-18
@@ -3,14 +3,21 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(nameof(ItemViewModel))]
|
||||
public partial class ItemViewModel :
|
||||
ObservableCollection<IDisposable>,
|
||||
ObservableCollection<IItemEntryViewModel>,
|
||||
INotificationHandler<EditEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool archived;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool favourite;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool immutable;
|
||||
|
||||
public ItemViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
@@ -18,28 +25,14 @@ public partial class ItemViewModel :
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
bool immutable = true,
|
||||
bool favourite = false,
|
||||
bool archived = false) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
Immutable = immutable;
|
||||
Favourite = favourite;
|
||||
Archived = archived;
|
||||
|
||||
if (!Archived)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<FavouriteItemActionViewModel>(favourite),
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
else
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<UnarchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
@@ -65,4 +58,34 @@ public partial class ItemViewModel :
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task OnActivated()
|
||||
{
|
||||
if (!Immutable)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<ConfirmItemActionViewModel>(),
|
||||
Factory.Create<DismissItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
else if (Archived)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<UnarchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
else
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<FavouriteItemActionViewModel>(Favourite),
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
|
||||
return base.OnActivated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Enumerate(nameof(MainViewModel))]
|
||||
[Aggerate(nameof(MainViewModel))]
|
||||
public partial class MainViewModel :
|
||||
ObservableCollection<IMainNavigationViewModel>
|
||||
{
|
||||
|
||||
@@ -5,4 +5,4 @@ public record QueryContainerConfiguration
|
||||
public string? Filter { get; set; }
|
||||
|
||||
public string? Query { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,21 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class QueryItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<RequestEventArgs<QueryItemConfiguration>, (int Id, string? Name)>
|
||||
{
|
||||
public Task<(int Id, string? Name)> Handle(RequestEventArgs<QueryItemConfiguration> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public record QueryItemConfiguration
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class QueryContainerHandler(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<RequestEventArgs<QueryContainerConfiguration>, IReadOnlyCollection<(int Id, string? Name, bool Favourite, bool Archived)>>
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
@@ -8,8 +9,12 @@ public partial class SearchContainerActionViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
IDisposer disposer,
|
||||
int index) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private int index = index;
|
||||
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Notify.As(new Search(Value)),
|
||||
nameof(ContainerViewModel));
|
||||
|
||||
Reference in New Issue
Block a user