Initial support for masking
This commit is contained in:
@@ -8,7 +8,7 @@ public partial class BackActionViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private int index = 0;
|
||||
|
||||
@@ -6,5 +6,5 @@ public record DropdownEntryConfiguration :
|
||||
ItemEntryConfiguration
|
||||
{
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string[]? Values { get; set; }
|
||||
public IList<string> Values { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
@@ -2,13 +2,36 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemDropdownEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
|
||||
public partial class ItemDropdownEntryViewModel :
|
||||
ItemEntryCollectionViewModel<ItemDropdownValueViewModel>
|
||||
{
|
||||
public ItemDropdownEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IEnumerable<ItemDropdownValueViewModel> items,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string key,
|
||||
object value,
|
||||
ItemDropdownValueViewModel selectedItem) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value)
|
||||
{
|
||||
SelectedItem = selectedItem;
|
||||
}
|
||||
|
||||
public ItemDropdownEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IEnumerable<ItemDropdownValueViewModel> items,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string key,
|
||||
object value) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,18 @@ public class ItemDropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
{
|
||||
if (args.Value is DropdownEntryConfiguration configuration)
|
||||
{
|
||||
if (serviceFactory.Create<ItemDropdownEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
|
||||
List<ItemDropdownValueViewModel> values = [];
|
||||
foreach (string item in configuration.Values)
|
||||
{
|
||||
values.Add(serviceFactory.Create<ItemDropdownValueViewModel>(item));
|
||||
}
|
||||
|
||||
string? label = configuration.Label;
|
||||
object? value = configuration.Value;
|
||||
|
||||
ItemDropdownValueViewModel? selected = values.FirstOrDefault(x => x.Value is not null && x.Value.Equals($"{value}"));
|
||||
|
||||
if (serviceFactory.Create<ItemDropdownEntryViewModel>([values, .. args.Parameters, configuration, label, value ?? "", selected])
|
||||
is ItemDropdownEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemDropdownValueViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string? value = null) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer, value);
|
||||
@@ -0,0 +1,77 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemEntryCollectionViewModel<TItem> :
|
||||
ObservableCollection<TItem, string, object>,
|
||||
IItemEntryViewModel,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>
|
||||
where TItem : notnull,
|
||||
IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private ItemState state;
|
||||
|
||||
private readonly ItemEntryConfiguration configuration;
|
||||
|
||||
public ItemEntryCollectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string key,
|
||||
object value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
State = state;
|
||||
}
|
||||
|
||||
public ItemEntryCollectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IEnumerable<TItem> items,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string key,
|
||||
object value) : base(provider, factory, mediator, publisher, subscriber, disposer, items, key, value)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
State = state;
|
||||
}
|
||||
|
||||
protected override void OnValueChanged()
|
||||
{
|
||||
if (configuration is not null)
|
||||
{
|
||||
configuration.Value = Value;
|
||||
}
|
||||
}
|
||||
|
||||
public Task Handle(UpdateEventArgs<Item> args) =>
|
||||
Task.FromResult(State = ItemState.Write);
|
||||
|
||||
public Task Handle(CancelEventArgs<Item> args)
|
||||
{
|
||||
Revert();
|
||||
|
||||
State = ItemState.Read;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(ConfirmEventArgs<Item> args)
|
||||
{
|
||||
Commit();
|
||||
|
||||
State = ItemState.Read;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
|
||||
IDisposer disposer,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
object? value = default) :
|
||||
string key,
|
||||
object value) :
|
||||
Observable<string, object>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IItemEntryViewModel,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
@@ -43,4 +43,4 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
|
||||
State = ItemState.Read;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,8 @@ public partial class ItemHeaderViewModel :
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
ItemState state,
|
||||
string? value = null) : base(provider, factory, mediator, publisher, subscriber, disposer, value)
|
||||
string key,
|
||||
string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
||||
{
|
||||
State = state;
|
||||
Value = value;
|
||||
@@ -68,6 +69,6 @@ public partial class ItemHeaderViewModel :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<string?> Handle(ConfirmEventArgs<ItemHeader> args,
|
||||
public Task<string> Handle(ConfirmEventArgs<ItemHeader> args,
|
||||
CancellationToken cancellationToken) => Task.FromResult(Value);
|
||||
}
|
||||
@@ -11,10 +11,10 @@ public partial class ItemMaskedTextEntryViewModel(IServiceProvider provider,
|
||||
IDisposer disposer,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? pattern,
|
||||
string? key = default,
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value)
|
||||
string pattern,
|
||||
string key,
|
||||
object value) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? pattern = pattern;
|
||||
private string pattern = pattern;
|
||||
}
|
||||
@@ -10,5 +10,5 @@ public partial class ItemPasswordEntryViewModel(IServiceProvider provider,
|
||||
IDisposer disposer,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
|
||||
string key,
|
||||
object value) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
|
||||
@@ -10,5 +10,5 @@ public partial class ItemTextEntryViewModel(IServiceProvider provider,
|
||||
IDisposer disposer,
|
||||
ItemState state,
|
||||
ItemEntryConfiguration configuration,
|
||||
string? key = default,
|
||||
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
|
||||
string key,
|
||||
object value) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
|
||||
@@ -49,7 +49,7 @@ public partial class ItemViewModel :
|
||||
Archived = archived;
|
||||
Name = name;
|
||||
|
||||
Add<ItemHeaderViewModel>(name, state);
|
||||
Add<ItemHeaderViewModel>("", name, state);
|
||||
Add<ItemContentViewModel>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user