Make it possible to gather values using scoped ItemConfiguration
This commit is contained in:
@@ -129,6 +129,9 @@ public partial class App : Application
|
||||
|
||||
services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>();
|
||||
services.AddTemplate<EmptyItemCollectionViewModel, EmptyItemCollectionView>("EmptyItemCollection");
|
||||
|
||||
services.AddScoped<IDecoratorService<ItemConfiguration>, DecoratorService<ItemConfiguration>>();
|
||||
|
||||
services.AddTemplate<ItemViewModel, ItemView>("Item");
|
||||
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
||||
services.AddTemplate<ItemContentViewModel, ItemContentView>();
|
||||
|
||||
@@ -3,28 +3,23 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public class ConfirmCreateItemHandler(IMediator mediator,
|
||||
IDecoratorService<ItemConfiguration> decoratorItemConfiguration,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
{
|
||||
string? name = await mediator.Handle<ConfirmEventArgs<ItemHeader>,
|
||||
string>(Confirm.As<ItemHeader>());
|
||||
|
||||
if (name is not null)
|
||||
if (decoratorItemConfiguration.Value is ItemConfiguration configuration)
|
||||
{
|
||||
IList<(int, string)> sections = await mediator.HandleMany<ConfirmEventArgs<ItemSection>,
|
||||
(int, string)>(Confirm.As<ItemSection>());
|
||||
string? name = await mediator.Handle<ConfirmEventArgs<ItemHeader>, string>(Confirm.As<ItemHeader>());
|
||||
if (name is not null)
|
||||
{
|
||||
Guid id = Guid.NewGuid();
|
||||
publisher.Publish(Created.As(new Item<(Guid, string)>((id, name))));
|
||||
|
||||
IList<(int, ItemEntryConfiguration)> entries = await mediator.HandleMany<ConfirmEventArgs<ItemContentEntry>,
|
||||
(int, ItemEntryConfiguration)>(Confirm.As<ItemContentEntry>());
|
||||
|
||||
Guid id = Guid.NewGuid();
|
||||
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, "",
|
||||
new ItemConfiguration())));
|
||||
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string, ItemConfiguration)>((id, name, "", configuration)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,8 @@ public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ItemState state) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Confirm.As<Item>(),
|
||||
state is ItemState.New ? nameof(ItemState.New) : nameof(ItemState.Write));
|
||||
public void Invoke() => Publisher.Publish(Confirm.As<Item>());
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ConfirmUpdateItemHandler(IDecoratorService<Item<(Guid, string)>> store,
|
||||
public class ConfirmUpdateItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorItem,
|
||||
IDecoratorService<ItemConfiguration> decoratorItemConfiguration,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
@@ -14,17 +15,16 @@ public class ConfirmUpdateItemHandler(IDecoratorService<Item<(Guid, string)>> st
|
||||
|
||||
if (name is not null)
|
||||
{
|
||||
|
||||
|
||||
var dd = decoratorItemConfiguration;
|
||||
publisher.Publish(Notify.As(new ItemHeader<string>(name)));
|
||||
if (store?.Value is Item<(Guid, string)> item)
|
||||
if (decoratorItem?.Value is Item<(Guid, string)> item)
|
||||
{
|
||||
(Guid id, string _) = item.Value;
|
||||
|
||||
Item<(Guid, string)> newItem = new((id, name));
|
||||
publisher.Publish(Modified.As(item, newItem));
|
||||
|
||||
store.Set(newItem);
|
||||
decoratorItem.Set(newItem);
|
||||
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, string, ItemConfiguration)>, bool>(new UpdateEventArgs<(Guid, string,
|
||||
ItemConfiguration)>((id, name, new ItemConfiguration())));
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record ItemContentEntry<TValue>(TValue Value);
|
||||
|
||||
public record ItemContentEntry;
|
||||
@@ -8,8 +8,7 @@ public partial class ItemContentViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
ItemState state = ItemState.Read) :
|
||||
IContentTemplate template) :
|
||||
ObservableCollection<ItemSectionViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel,
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>
|
||||
@@ -22,8 +21,7 @@ public partial class ItemContentViewModel(IServiceProvider provider,
|
||||
{
|
||||
if (category.Value is string value)
|
||||
{
|
||||
Fetch(() => new SynchronizeExpression(new SynchronizeEventArgs<IItemEntryViewModel,
|
||||
(string, ISynchronizationCollection<ItemSectionViewModel>)>((value, this))), true);
|
||||
Fetch(() => new SynchronizeExpression(new SynchronizeEventArgs<IItemEntryViewModel, string>(value)), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ public partial class ItemDropdownEntryViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ISynchronizationCollection<IItemEntryViewModel> synchronization,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
string? value = default) : ItemEntryViewModel<string, string?>(provider, factory, mediator, publisher, subscriber, disposer, synchronization, configuration, key, value);
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
|
||||
@@ -10,7 +10,7 @@ public class ItemDropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
{
|
||||
if (args.Value is DropdownEntryConfiguration configuration)
|
||||
{
|
||||
if (serviceFactory.Create<ItemDropdownEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
|
||||
if (serviceFactory.Create<ItemDropdownEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
|
||||
is ItemDropdownEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
using Toolkit.Foundation;
|
||||
using System.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemEntryViewModel<TKey, TValue>(IServiceProvider provider,
|
||||
public partial class ItemEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ISynchronizationCollection<IItemEntryViewModel> synchronization,
|
||||
ItemEntryConfiguration configuration,
|
||||
TKey? key = default,
|
||||
TValue? value = default) :
|
||||
Observable<TKey, TValue>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IHandler<ConfirmEventArgs<ItemContentEntry>, (int, ItemEntryConfiguration)>,
|
||||
IItemEntryViewModel,
|
||||
IIndexable
|
||||
string? key = default,
|
||||
object? value = default) :
|
||||
Observable<string, object>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IItemEntryViewModel
|
||||
{
|
||||
public int Index => synchronization.IndexOf(this);
|
||||
|
||||
public Task<(int, ItemEntryConfiguration)> Handle(ConfirmEventArgs<ItemContentEntry> args,
|
||||
CancellationToken cancellationToken) => Task.FromResult((Index, configuration with { Value = Value }));
|
||||
protected override void OnValueChanged() => configuration.Value = Value;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ public partial class ItemMaskedTextEntryViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ISynchronizationCollection<IItemEntryViewModel> synchronization,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
string? value = default) : ItemEntryViewModel<string, string?>(provider, factory, mediator, publisher, subscriber, disposer, synchronization, configuration, key, value);
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
|
||||
@@ -10,7 +10,7 @@ public class ItemMaskedTextEntryViewModelHandler(IServiceFactory serviceFactory)
|
||||
{
|
||||
if (args.Value is MaskedTextEntryConfiguration configuration)
|
||||
{
|
||||
if (serviceFactory.Create<ItemMaskedTextEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
|
||||
if (serviceFactory.Create<ItemMaskedTextEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
|
||||
is ItemMaskedTextEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
|
||||
@@ -24,6 +24,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
INotificationHandler<FavouriteEventArgs<Item>>,
|
||||
INotificationHandler<UnfavouriteEventArgs<Item>>,
|
||||
INotificationHandler<NotifyEventArgs<ItemHeader<string>>>,
|
||||
IKeyed<Guid>,
|
||||
ISelectable,
|
||||
IRemovable
|
||||
{
|
||||
|
||||
@@ -8,7 +8,6 @@ public partial class ItemPasswordEntryViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ISynchronizationCollection<IItemEntryViewModel> synchronization,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
string? value = default) : ItemEntryViewModel<string, string?>(provider, factory, mediator, publisher, subscriber, disposer, synchronization, configuration, key, value);
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
|
||||
@@ -10,7 +10,7 @@ public class ItemPasswordEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
{
|
||||
if (args.Value is PasswordEntryConfiguration configuration)
|
||||
{
|
||||
if (serviceFactory.Create<ItemPasswordEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
|
||||
if (serviceFactory.Create<ItemPasswordEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
|
||||
is ItemPasswordEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(typeof(CreateEventArgs<IItemEntryViewModel>), nameof(Section))]
|
||||
[Notification(typeof(CreateEventArgs<IItemEntryViewModel>), nameof(Id))]
|
||||
public partial class ItemSectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
@@ -11,18 +10,10 @@ public partial class ItemSectionViewModel(IServiceProvider provider,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
ISynchronizationCollection<ItemSectionViewModel> synchronization,
|
||||
string section) : ObservableCollection<IItemEntryViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IHandler<ConfirmEventArgs<ItemSection>, (int, string)>,
|
||||
IIndexable
|
||||
string id) : ObservableCollection<IItemEntryViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IKeyed<string>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string section = section;
|
||||
public string Id => id;
|
||||
|
||||
public IContentTemplate Template { get; set; } = template;
|
||||
|
||||
public int Index => synchronization.IndexOf(this);
|
||||
|
||||
public Task<(int, string)> Handle(ConfirmEventArgs<ItemSection> args,
|
||||
CancellationToken cancellationToken) => Task.FromResult((0, Section));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ public partial class ItemTextEntryViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ISynchronizationCollection<IItemEntryViewModel> synchronization,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
string? value = default) : ItemEntryViewModel<string, string?>(provider, factory, mediator, publisher, subscriber, disposer, synchronization, configuration, key, value);
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
|
||||
@@ -10,7 +10,7 @@ public class ItemTextEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
{
|
||||
if (args.Value is TextEntryConfiguration configuration)
|
||||
{
|
||||
if (serviceFactory.Create<ItemTextEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
|
||||
if (serviceFactory.Create<ItemTextEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
|
||||
is ItemTextEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
|
||||
@@ -3,12 +3,10 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(typeof(ConfirmEventArgs<Item>), nameof(ItemState.New))]
|
||||
[Notification(typeof(ConfirmEventArgs<Item>), nameof(ItemState.Write))]
|
||||
public partial class ItemViewModel :
|
||||
ObservableCollection,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
@@ -51,8 +49,8 @@ public partial class ItemViewModel :
|
||||
Archived = archived;
|
||||
Name = name;
|
||||
|
||||
Add<ItemHeaderViewModel>(state, name);
|
||||
Add<ItemContentViewModel>(state);
|
||||
Add<ItemHeaderViewModel>(name, state);
|
||||
Add<ItemContentViewModel>();
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
@@ -61,7 +59,7 @@ public partial class ItemViewModel :
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<ConfirmItemActionViewModel>(ItemState.Write),
|
||||
Factory.Create<ConfirmItemActionViewModel>(),
|
||||
Factory.Create<DismissItemActionViewModel>(),
|
||||
})));
|
||||
|
||||
@@ -97,6 +95,9 @@ public partial class ItemViewModel :
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
|
||||
Publisher.Publish(Confirm.As<Item>(),
|
||||
State is ItemState.New ? nameof(ItemState.New) : nameof(ItemState.Write));
|
||||
|
||||
State = ItemState.Read;
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -4,36 +4,40 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
public class SynchronizeItemContentFromCategoryViewModelHandler(IItemConfigurationCollection configurations,
|
||||
IDecoratorService<ItemConfiguration> decoratorItemConfiguration,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<SynchronizeEventArgs<IItemEntryViewModel,
|
||||
(string, ISynchronizationCollection<ItemSectionViewModel>)>>
|
||||
INotificationHandler<SynchronizeEventArgs<IItemEntryViewModel, string>>
|
||||
{
|
||||
public async Task Handle(SynchronizeEventArgs<IItemEntryViewModel, (string, ISynchronizationCollection<ItemSectionViewModel>)> args)
|
||||
public async Task Handle(SynchronizeEventArgs<IItemEntryViewModel, string> args)
|
||||
{
|
||||
(string category, ISynchronizationCollection<ItemSectionViewModel> synchronization) = args.Value;
|
||||
if (configurations.TryGetValue(category, out Func<ItemConfiguration>? factory))
|
||||
if (args.Value is string category)
|
||||
{
|
||||
if (factory.Invoke() is ItemConfiguration configuration)
|
||||
if (configurations.TryGetValue(category, out Func<ItemConfiguration>? configurationFactory))
|
||||
{
|
||||
foreach (ItemSectionConfiguration configurationSection in configuration.Sections)
|
||||
if (configurationFactory.Invoke() is ItemConfiguration configuration)
|
||||
{
|
||||
string section = $"{nameof(ItemSection)}:{Guid.NewGuid()}";
|
||||
if (serviceFactory.Create<ItemSectionViewModel>(synchronization, section)
|
||||
is ItemSectionViewModel sectionViewModel)
|
||||
decoratorItemConfiguration.Set(configuration);
|
||||
foreach (ItemSectionConfiguration configurationSection in configuration.Sections)
|
||||
{
|
||||
publisher.Publish(Create.As(sectionViewModel), nameof(ItemContentViewModel));
|
||||
foreach (IItemEntryConfiguration entryConfiguration in configurationSection.Entries)
|
||||
string id = $"{nameof(ItemSection)}:{Guid.NewGuid()}";
|
||||
if (serviceFactory.Create<ItemSectionViewModel>(id)
|
||||
is ItemSectionViewModel sectionViewModel)
|
||||
{
|
||||
Type messageType = typeof(CreateEventArgs<>).MakeGenericType(entryConfiguration.GetType());
|
||||
ConstructorInfo? constructor = messageType.GetConstructor([entryConfiguration.GetType(), typeof(object[])]);
|
||||
|
||||
if (constructor?.Invoke(new object[] { entryConfiguration, new object[] { sectionViewModel } }) is object message)
|
||||
publisher.Publish(Create.As(sectionViewModel), nameof(ItemContentViewModel));
|
||||
foreach (IItemEntryConfiguration entryConfiguration in configurationSection.Entries)
|
||||
{
|
||||
if (await mediator.Handle<object, IItemEntryViewModel?>(message, entryConfiguration.GetType().Name) is IItemEntryViewModel entryViewModel)
|
||||
Type messageType = typeof(CreateEventArgs<>).MakeGenericType(entryConfiguration.GetType());
|
||||
ConstructorInfo? constructor = messageType.GetConstructor([entryConfiguration.GetType(), typeof(object[])]);
|
||||
|
||||
if (constructor?.Invoke(new object[] { entryConfiguration, new object[] { sectionViewModel } }) is object message)
|
||||
{
|
||||
publisher.Publish(Create.As(entryViewModel), section);
|
||||
if (await mediator.Handle<object, IItemEntryViewModel?>(message,
|
||||
entryConfiguration.GetType().Name) is IItemEntryViewModel entryViewModel)
|
||||
{
|
||||
publisher.Publish(Create.As(entryViewModel), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +45,5 @@ public class SynchronizeItemContentFromCategoryViewModelHandler(IItemConfigurati
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user