wip
This commit is contained in:
+4
-2
@@ -2,19 +2,21 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggerateLockerItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors,
|
||||
public class AggerateItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>>
|
||||
{
|
||||
public Task Handle(AggerateEventArgs<ItemCategoryNavigationViewModel> args)
|
||||
{
|
||||
bool selected = true;
|
||||
foreach (IConfigurationDescriptor<ItemConfiguration> descriptor in descriptors)
|
||||
{
|
||||
if (serviceFactory.Create<ItemCategoryNavigationViewModel>(descriptor.Name)
|
||||
if (serviceFactory.Create<ItemCategoryNavigationViewModel>(descriptor.Name, selected)
|
||||
is ItemCategoryNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel));
|
||||
selected = false;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggerateLockerItemViewModelHandler(IMediator mediator,
|
||||
public class AggerateItemViewModelHandler(IMediator mediator,
|
||||
IServiceProvider serviceProvider,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IPublisher publisher) :
|
||||
@@ -45,7 +45,5 @@ public class AggerateLockerItemViewModelHandler(IMediator mediator,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var d = cache;
|
||||
}
|
||||
}
|
||||
@@ -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())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,10 @@ public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
IDisposer disposer,
|
||||
ItemState state) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
[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;
|
||||
|
||||
public class ConfirmItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
public class ConfirmUpdateItemHandler(IValueStore<Item<(Guid, string)>> store,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
@@ -16,33 +16,19 @@ public class ConfirmItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
{
|
||||
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;
|
||||
|
||||
string? name = configuration.Name;
|
||||
|
||||
Item<(Guid, string)> newItem = new((id, name));
|
||||
publisher.Publish(Modified.As(item, newItem));
|
||||
|
||||
valueStore.Set(newItem);
|
||||
store.Set(newItem);
|
||||
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, string, ItemConfiguration)>, bool>(new UpdateEventArgs<(Guid, string,
|
||||
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))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,12 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
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)
|
||||
{
|
||||
if (args.Value is (Guid id, string name, ItemConfiguration configuration))
|
||||
if (args.Value is (Guid id, string name, string category, ItemConfiguration configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -20,7 +20,7 @@ public class CreateItemHandler(IDbContextFactory<LockerContext> dbContextFactory
|
||||
|
||||
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);
|
||||
}, cancellationToken);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(nameof(ItemCategoryCollectionViewModel))]
|
||||
[Aggerate(typeof(CreateEventArgs<ItemCategoryNavigationViewModel>), nameof(ItemCategoryCollectionViewModel))]
|
||||
public partial class ItemCategoryCollectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
@@ -21,4 +22,6 @@ public partial class ItemCategoryNavigationViewModel(IServiceProvider provider,
|
||||
[ObservableProperty]
|
||||
private bool selected = selected;
|
||||
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Notify.As(new ItemCategory<string>(Name)));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ using Toolkit.Foundation;
|
||||
|
||||
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 :
|
||||
ObservableCollection<ItemNavigationViewModel>,
|
||||
INotificationHandler<NotifyEventArgs<Filter>>,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(nameof(ItemContentViewModel))]
|
||||
//[Aggerate(nameof(ItemContentViewModel))]
|
||||
public partial class ItemContentViewModel :
|
||||
ObservableCollection<IItemEntryViewModel>,
|
||||
IItemEntryViewModel,
|
||||
@@ -21,8 +21,14 @@ public partial class ItemContentViewModel :
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
protected override IAggerate OnAggerate(object? key)
|
||||
{
|
||||
return base.OnAggerate(key);
|
||||
}
|
||||
|
||||
|
||||
public Task Handle(NotifyEventArgs<ItemCategory<string>> args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class CreatedItemHandler(IServiceProvider serviceProvider,
|
||||
public class ItemCreatedHandler(IServiceProvider serviceProvider,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<CreatedEventArgs<Item<(Guid, string)>>>
|
||||
@@ -9,8 +9,12 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>,
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>,
|
||||
IItemEntryViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? category;
|
||||
|
||||
[ObservableProperty]
|
||||
private ItemState state;
|
||||
|
||||
@@ -56,4 +60,14 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
|
||||
State = ItemState.Read;
|
||||
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;
|
||||
|
||||
public class ModifiedItemHandler(IServiceProvider serviceProvider,
|
||||
public class ItemModifiedHandler(IServiceProvider serviceProvider,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ModifiedEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
public enum ItemState
|
||||
{
|
||||
New,
|
||||
Read,
|
||||
Write
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(typeof(ConfirmEventArgs<Item>), nameof(Create))]
|
||||
public partial class ItemViewModel :
|
||||
ObservableCollection<IItemEntryViewModel>,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
@@ -42,10 +43,10 @@ public partial class ItemViewModel :
|
||||
bool favourite = false,
|
||||
bool archived = false) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
FromCategory = fromCategory;
|
||||
Named = $"{named}";
|
||||
Template = template;
|
||||
Named = $"{named}";
|
||||
State = state;
|
||||
FromCategory = fromCategory;
|
||||
Favourite = favourite;
|
||||
Archived = archived;
|
||||
Name = name;
|
||||
@@ -60,7 +61,7 @@ public partial class ItemViewModel :
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<ConfirmItemActionViewModel>(),
|
||||
Factory.Create<ConfirmItemActionViewModel>(ItemState.Write),
|
||||
Factory.Create<DismissItemActionViewModel>(),
|
||||
})));
|
||||
|
||||
@@ -70,9 +71,12 @@ public partial class ItemViewModel :
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public Task Handle(CancelEventArgs<Item> args)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
@@ -109,11 +113,11 @@ public partial class ItemViewModel :
|
||||
}
|
||||
else
|
||||
{
|
||||
if (State is ItemState.Write)
|
||||
if (State is ItemState.Write or ItemState.New)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<ConfirmItemActionViewModel>(),
|
||||
Factory.Create<ConfirmItemActionViewModel>(State),
|
||||
Factory.Create<DismissItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(nameof(MainViewModel))]
|
||||
[Aggerate(typeof(CreateEventArgs<IMainNavigationViewModel>), nameof(MainViewModel))]
|
||||
public partial class MainViewModel :
|
||||
ObservableCollection<IMainNavigationViewModel>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user