Improved json support

This commit is contained in:
TheXamlGuy
2024-07-15 21:14:30 +01:00
parent 46d8ea6d6c
commit f38a3d6aad
34 changed files with 143 additions and 130 deletions
@@ -1,4 +1,4 @@
namespace Wallet; namespace Wallet;
public record AttachmentEntryCollectionConfiguration : public record AttachmentEntryCollectionConfiguration :
ItemEntryConfiguration; ItemEntryConfiguration<string>;
+3 -3
View File
@@ -9,9 +9,9 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<ICollection<Comment>> configuration,
string key, string key,
ICollection<Comment<(string, DateTimeOffset)>> value, ICollection<Comment> value,
bool isConcealed, bool isConcealed,
bool isRevealed, bool isRevealed,
double width) : ItemEntryCollectionViewModel<AttachmentEntryViewModel, ICollection<Comment<(string, DateTimeOffset)>>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width); double width) : ItemEntryCollectionViewModel<AttachmentEntryViewModel, ICollection<Comment>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width);
+4 -9
View File
@@ -1,19 +1,14 @@
using Microsoft.EntityFrameworkCore; using Toolkit.Foundation;
using Toolkit.Foundation;
using Wallet.Data;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace Wallet; namespace Wallet;
public class CloseWalletHandler(IDecoratorService<WalletConnection> walletConnectionDecorator, public class CloseWalletHandler(IDecoratorService<WalletConnection> walletConnectionDecorator) :
IDbContextFactory<WalletContext> dbContextFactory) :
IHandler<CloseEventArgs<Wallet>, bool> IHandler<CloseEventArgs<Wallet>, bool>
{ {
public async Task<bool> Handle(CloseEventArgs<Wallet> args, public Task<bool> Handle(CloseEventArgs<Wallet> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
walletConnectionDecorator.Set(null); walletConnectionDecorator.Set(null);
return Task.FromResult(true);
return true;
} }
} }
+8
View File
@@ -0,0 +1,8 @@
namespace Wallet;
public record Comment
{
public DateTimeOffset DateTime { get; set; }
public string? Text { get; set; }
}
@@ -1,4 +1,4 @@
namespace Wallet; namespace Wallet;
public record CommentEntryCollectionConfiguration : public record CommentEntryCollectionConfiguration :
ItemEntryConfiguration; ItemEntryConfiguration<ICollection<Comment>>;
+8 -7
View File
@@ -10,21 +10,22 @@ public partial class CommentEntryCollectionViewModel(IServiceProvider provider,
IDisposer disposer, IDisposer disposer,
IContentTemplate template, IContentTemplate template,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, ItemEntryConfiguration<ICollection<Comment>> configuration,
string key, string key,
ICollection<Comment<(string, DateTimeOffset)>> value, ICollection<Comment> value,
bool isConcealed, bool isConcealed,
bool isRevealed, bool isRevealed,
double width) : ItemEntryCollectionViewModel<ICommentEntryViewModel, ICollection<Comment<(string, DateTimeOffset)>>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width), double width) : ItemEntryCollectionViewModel<ICommentEntryViewModel, ICollection<Comment>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width),
INotificationHandler<CreateEventArgs<Comment<string>>> INotificationHandler<CreateEventArgs<Comment>>
{ {
public IContentTemplate Template { get; set; } = template; public IContentTemplate Template { get; set; } = template;
public Task Handle(CreateEventArgs<Comment<string>> args) public Task Handle(CreateEventArgs<Comment> args)
{ {
if (args.Sender is Comment<string> comment) if (args.Sender is Comment comment)
{ {
Insert<CommentEntryViewModel>(0, DateTimeOffset.Now, comment.Value); Insert<CommentEntryViewModel>(0, comment.DateTime, comment.Text);
Value.Add(comment);
} }
return Task.CompletedTask; return Task.CompletedTask;
@@ -11,7 +11,7 @@ public class CommentEntryCollectionViewModelHandler(IServiceFactory serviceFacto
if (args.Sender is CommentEntryCollectionConfiguration configuration) if (args.Sender is CommentEntryCollectionConfiguration configuration)
{ {
string? label = configuration.Label; string? label = configuration.Label;
string? value = $"{configuration.Value}" ?? ""; List<Comment> value = new List<Comment>();
double? width = configuration.Width; double? width = configuration.Width;
if (serviceFactory.Create<CommentEntryCollectionViewModel>(args => args.Initialize(), if (serviceFactory.Create<CommentEntryCollectionViewModel>(args => args.Initialize(),
+1 -3
View File
@@ -3,8 +3,6 @@ using Toolkit.Foundation;
namespace Wallet; namespace Wallet;
public record Comment<TValue>(TValue Value);
public partial class CreateCommentEntryViewModel(IServiceProvider provider, public partial class CreateCommentEntryViewModel(IServiceProvider provider,
IServiceFactory factory, IServiceFactory factory,
IMediator mediator, IMediator mediator,
@@ -16,7 +14,7 @@ public partial class CreateCommentEntryViewModel(IServiceProvider provider,
[RelayCommand] [RelayCommand]
private void Invoke() private void Invoke()
{ {
Publisher.Publish(Create.As(new Comment<string?>(Value))); Publisher.Publish(Create.As(new Comment { Text = Value, DateTime = DateTimeOffset.Now }));
Value = null; Value = null;
} }
} }
+1 -4
View File
@@ -1,7 +1,4 @@
namespace Wallet; namespace Wallet;
public record CurrencyEntryConfiguration : public record CurrencyEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>;
{
}
+1 -4
View File
@@ -1,7 +1,4 @@
namespace Wallet; namespace Wallet;
public record DateEntryConfiguration : public record DateEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<DateTimeOffset?>;
{
}
+3 -3
View File
@@ -9,9 +9,9 @@ public partial class DateEntryViewModel(IServiceProvider provider,
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<DateTimeOffset?> configuration,
string key, string key,
DateTimeOffset value, DateTimeOffset? value,
bool isConcealed, bool isConcealed,
bool isRevealed, bool isRevealed,
double width) : ItemEntryViewModel<DateTimeOffset>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width); double width) : ItemEntryViewModel<DateTimeOffset?>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width);
+1 -5
View File
@@ -12,11 +12,7 @@ public class DateEntryViewModelHandler(IServiceFactory serviceFactory) :
{ {
string? label = configuration.Label; string? label = configuration.Label;
if (!DateTimeOffset.TryParse($"{configuration.Value}", out DateTimeOffset value)) DateTimeOffset? value = configuration.Value is not null ? configuration.Value : DateTimeOffset.Now;
{
value = DateTimeOffset.Now;
}
double? width = configuration.Width; double? width = configuration.Width;
if (serviceFactory.Create<DateEntryViewModel>(args => args.Initialize(), if (serviceFactory.Create<DateEntryViewModel>(args => args.Initialize(),
@@ -3,8 +3,8 @@
namespace Wallet; namespace Wallet;
public record DropdownEntryCollectionConfiguration : public record DropdownEntryCollectionConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<object>
{ {
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public IList<string> Values { get; set; } = new List<string>(); public IList<string> Values { get; set; } = new List<string>();
} }
+2 -2
View File
@@ -13,7 +13,7 @@ public partial class DropdownEntryCollectionViewModel :
IDisposer disposer, IDisposer disposer,
IEnumerable<DropdownEntryViewModel> items, IEnumerable<DropdownEntryViewModel> items,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, DropdownEntryCollectionConfiguration configuration,
string key, string key,
object value, object value,
bool isConcealed, bool isConcealed,
@@ -32,7 +32,7 @@ public partial class DropdownEntryCollectionViewModel :
IDisposer disposer, IDisposer disposer,
IEnumerable<DropdownEntryViewModel> items, IEnumerable<DropdownEntryViewModel> items,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, DropdownEntryCollectionConfiguration configuration,
string key, string key,
object value, object value,
bool isConcealed, bool isConcealed,
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Wallet; namespace Wallet;
public record Hyperlink(string Value); public record Hyperlink(string? Value);
+1 -4
View File
@@ -1,7 +1,4 @@
namespace Wallet; namespace Wallet;
public record HyperlinkEntryConfiguration : public record HyperlinkEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>;
{
}
+1 -1
View File
@@ -10,7 +10,7 @@ public partial class HyperlinkEntryViewModel(IServiceProvider provider,
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<string> configuration,
string key, string key,
string value, string value,
double width, double width,
+32 -3
View File
@@ -1,8 +1,37 @@
namespace Wallet; using System.Text.Json.Serialization;
public interface IItemEntryConfiguration namespace Wallet;
[JsonDerivedType(typeof(DropdownEntryCollectionConfiguration), typeDiscriminator: "Dropdown")]
[JsonDerivedType(typeof(MaskedTextEntryConfiguration), typeDiscriminator: "MaskedText")]
[JsonDerivedType(typeof(NumberEntryConfiguration), typeDiscriminator: "Number")]
[JsonDerivedType(typeof(PasswordEntryConfiguration), typeDiscriminator: "Password")]
[JsonDerivedType(typeof(TextEntryConfiguration), typeDiscriminator: "Text")]
[JsonDerivedType(typeof(ImageEntryConfiguration), typeDiscriminator: "Images")]
[JsonDerivedType(typeof(AttachmentEntryCollectionConfiguration), typeDiscriminator: "Attachments")]
[JsonDerivedType(typeof(CommentEntryCollectionConfiguration), typeDiscriminator: "Comments")]
[JsonDerivedType(typeof(CurrencyEntryConfiguration), typeDiscriminator: "Currency")]
[JsonDerivedType(typeof(DateEntryConfiguration), typeDiscriminator: "Date")]
[JsonDerivedType(typeof(HyperlinkEntryConfiguration), typeDiscriminator: "Hyperlink")]
[JsonDerivedType(typeof(PinEntryConfiguration), typeDiscriminator: "Pin")]
public interface IItemEntryConfiguration<TValue> :
IItemEntryConfiguration
{ {
string? Label { get; set; } string? Label { get; set; }
object? Value { get; set; } TValue? Value { get; set; }
} }
[JsonDerivedType(typeof(DropdownEntryCollectionConfiguration), typeDiscriminator: "Dropdown")]
[JsonDerivedType(typeof(MaskedTextEntryConfiguration), typeDiscriminator: "MaskedText")]
[JsonDerivedType(typeof(NumberEntryConfiguration), typeDiscriminator: "Number")]
[JsonDerivedType(typeof(PasswordEntryConfiguration), typeDiscriminator: "Password")]
[JsonDerivedType(typeof(TextEntryConfiguration), typeDiscriminator: "Text")]
[JsonDerivedType(typeof(ImageEntryConfiguration), typeDiscriminator: "Images")]
[JsonDerivedType(typeof(AttachmentEntryCollectionConfiguration), typeDiscriminator: "Attachments")]
[JsonDerivedType(typeof(CommentEntryCollectionConfiguration), typeDiscriminator: "Comments")]
[JsonDerivedType(typeof(CurrencyEntryConfiguration), typeDiscriminator: "Currency")]
[JsonDerivedType(typeof(DateEntryConfiguration), typeDiscriminator: "Date")]
[JsonDerivedType(typeof(HyperlinkEntryConfiguration), typeDiscriminator: "Hyperlink")]
[JsonDerivedType(typeof(PinEntryConfiguration), typeDiscriminator: "Pin")]
public interface IItemEntryConfiguration;
+1 -4
View File
@@ -1,7 +1,4 @@
namespace Wallet; namespace Wallet;
public record ImageEntryConfiguration : public record ImageEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>;
{
}
+22 -23
View File
@@ -10,7 +10,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -76,7 +76,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new NumberEntryConfiguration new NumberEntryConfiguration
{ {
@@ -155,7 +155,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new CommentEntryCollectionConfiguration new CommentEntryCollectionConfiguration
{ {
@@ -172,7 +172,7 @@ public record ItemConfiguration
{ {
new () new ()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -193,7 +193,7 @@ public record ItemConfiguration
{ {
new ItemSectionConfiguration new ItemSectionConfiguration
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -238,7 +238,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -295,7 +295,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -332,7 +332,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new PasswordEntryConfiguration new PasswordEntryConfiguration
{ {
@@ -357,7 +357,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -406,7 +406,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -447,7 +447,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -488,7 +488,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -533,7 +533,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -586,7 +586,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -635,7 +635,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -684,7 +684,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -753,7 +753,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -792,7 +792,7 @@ public record ItemConfiguration
}, },
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new PinEntryConfiguration new PinEntryConfiguration
{ {
@@ -815,7 +815,7 @@ public record ItemConfiguration
}, },
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -840,7 +840,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -893,7 +893,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -954,7 +954,7 @@ public record ItemConfiguration
{ {
new() new()
{ {
Entries = new List<ItemEntryConfiguration> Entries = new List<IItemEntryConfiguration>
{ {
new TextEntryConfiguration new TextEntryConfiguration
{ {
@@ -1004,5 +1004,4 @@ public record ItemConfiguration
} }
} }
}; };
} }
+8 -4
View File
@@ -7,13 +7,14 @@ namespace Wallet;
public partial class ItemEntryCollectionViewModel<TItem, TValue> : public partial class ItemEntryCollectionViewModel<TItem, TValue> :
ObservableCollection<TItem, string, TValue>, ObservableCollection<TItem, string, TValue>,
IItemEntryViewModel, IItemEntryViewModel,
IHandler<ValidateEventArgs<ItemEntry>, bool>,
INotificationHandler<UpdateEventArgs<Item>>, INotificationHandler<UpdateEventArgs<Item>>,
INotificationHandler<ConfirmEventArgs<Item>>, INotificationHandler<ConfirmEventArgs<Item>>,
INotificationHandler<CancelEventArgs<Item>> INotificationHandler<CancelEventArgs<Item>>
where TItem : notnull, where TItem : notnull,
IDisposable IDisposable
{ {
private readonly ItemEntryConfiguration configuration; private readonly IItemEntryConfiguration<TValue> configuration;
[ObservableProperty] [ObservableProperty]
private bool isConcealed; private bool isConcealed;
@@ -34,7 +35,7 @@ public partial class ItemEntryCollectionViewModel<TItem, TValue> :
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<TValue> configuration,
string key, string key,
TValue value, TValue value,
bool isConcealed, bool isConcealed,
@@ -59,7 +60,7 @@ public partial class ItemEntryCollectionViewModel<TItem, TValue> :
IDisposer disposer, IDisposer disposer,
IEnumerable<TItem> items, IEnumerable<TItem> items,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<TValue> configuration,
string key, string key,
TValue value, TValue value,
bool isConcealed, bool isConcealed,
@@ -95,12 +96,15 @@ public partial class ItemEntryCollectionViewModel<TItem, TValue> :
return Task.CompletedTask; return Task.CompletedTask;
} }
protected override void OnValueChanged() public async Task<bool> Handle(ValidateEventArgs<ItemEntry> args,
CancellationToken cancellationToken)
{ {
if (configuration is not null) if (configuration is not null)
{ {
configuration.Value = Value; configuration.Value = Value;
} }
return await Task.FromResult(true);
} }
[RelayCommand] [RelayCommand]
+6 -6
View File
@@ -14,15 +14,15 @@ namespace Wallet;
[JsonDerivedType(typeof(DateEntryConfiguration), typeDiscriminator: "Date")] [JsonDerivedType(typeof(DateEntryConfiguration), typeDiscriminator: "Date")]
[JsonDerivedType(typeof(HyperlinkEntryConfiguration), typeDiscriminator: "Hyperlink")] [JsonDerivedType(typeof(HyperlinkEntryConfiguration), typeDiscriminator: "Hyperlink")]
[JsonDerivedType(typeof(PinEntryConfiguration), typeDiscriminator: "Pin")] [JsonDerivedType(typeof(PinEntryConfiguration), typeDiscriminator: "Pin")]
public record ItemEntryConfiguration : public record ItemEntryConfiguration<TValue> :
IItemEntryConfiguration IItemEntryConfiguration<TValue>
{ {
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string? Label { get; set; } public string? Label { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public object? Value { get; set; } public TValue? Value { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public double? Width { get; set; } = 296; public double? Width { get; set; } = 296;
} }
+23 -20
View File
@@ -7,11 +7,25 @@ namespace Wallet;
public partial class ItemEntryViewModel<TValue> : public partial class ItemEntryViewModel<TValue> :
Observable<string, TValue>, Observable<string, TValue>,
IItemEntryViewModel, IItemEntryViewModel,
IHandler<ValidateEventArgs<ItemEntry>, bool>,
INotificationHandler<ConfirmEventArgs<ItemEntry>>, INotificationHandler<ConfirmEventArgs<ItemEntry>>,
INotificationHandler<UpdateEventArgs<ItemEntry>>, INotificationHandler<UpdateEventArgs<ItemEntry>>,
INotificationHandler<CancelEventArgs<ItemEntry>> INotificationHandler<CancelEventArgs<ItemEntry>>
where TValue : notnull
{ {
private readonly IItemEntryConfiguration<TValue> configuration;
[ObservableProperty]
private bool isConcealed;
[ObservableProperty]
private bool isRevealed;
[ObservableProperty]
private ItemState state;
[ObservableProperty]
private double width;
public ItemEntryViewModel(IServiceProvider provider, public ItemEntryViewModel(IServiceProvider provider,
IServiceFactory factory, IServiceFactory factory,
IMediator mediator, IMediator mediator,
@@ -19,7 +33,7 @@ public partial class ItemEntryViewModel<TValue> :
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<TValue> configuration,
string key, string key,
TValue value, TValue value,
bool isConcealed, bool isConcealed,
@@ -36,20 +50,6 @@ public partial class ItemEntryViewModel<TValue> :
Track(nameof(Value), () => Value, x => Value = x); Track(nameof(Value), () => Value, x => Value = x);
} }
private readonly ItemEntryConfiguration configuration;
[ObservableProperty]
private bool isConcealed;
[ObservableProperty]
private bool isRevealed;
[ObservableProperty]
private ItemState state;
[ObservableProperty]
private double width;
public Task Handle(UpdateEventArgs<ItemEntry> args) => public Task Handle(UpdateEventArgs<ItemEntry> args) =>
Task.FromResult(State = ItemState.Write); Task.FromResult(State = ItemState.Write);
@@ -69,20 +69,23 @@ public partial class ItemEntryViewModel<TValue> :
return Task.CompletedTask; return Task.CompletedTask;
} }
protected override void OnValueChanged() public async Task<bool> Handle(ValidateEventArgs<ItemEntry> args,
CancellationToken cancellationToken)
{ {
if (configuration is not null) if (configuration is not null)
{ {
configuration.Value = Value; configuration.Value = Value;
} }
return await Task.FromResult(true);
} }
[RelayCommand]
private void Copy() => Publisher.Publish(Write.As(new Clipboard<object>($"{Value}")));
[RelayCommand] [RelayCommand]
private void Hide() => IsRevealed = false; private void Hide() => IsRevealed = false;
[RelayCommand] [RelayCommand]
private void Reveal() => IsRevealed = true; private void Reveal() => IsRevealed = true;
[RelayCommand]
private void Copy() => Publisher.Publish(Write.As(new Clipboard<object>($"{Value}")));
} }
-2
View File
@@ -1,8 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using System.Xml.Linq;
using Toolkit.Foundation; using Toolkit.Foundation;
using Wallet.Data;
namespace Wallet; namespace Wallet;
+1 -1
View File
@@ -2,5 +2,5 @@
public record ItemSectionConfiguration public record ItemSectionConfiguration
{ {
public IList<ItemEntryConfiguration> Entries { get; set; } = new List<ItemEntryConfiguration>(); public IList<IItemEntryConfiguration> Entries { get; set; } = new List<IItemEntryConfiguration>();
} }
+1 -1
View File
@@ -3,7 +3,7 @@
namespace Wallet; namespace Wallet;
public record MaskedTextEntryConfiguration : public record MaskedTextEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>
{ {
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Pattern { get; set; } public string? Pattern { get; set; }
+1 -1
View File
@@ -10,7 +10,7 @@ public partial class MaskedTextEntryViewModel(IServiceProvider provider,
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<string> configuration,
string pattern, string pattern,
string key, string key,
string value, string value,
+1 -1
View File
@@ -1,7 +1,7 @@
namespace Wallet; namespace Wallet;
public record NumberEntryConfiguration : public record NumberEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>
{ {
public int MinLength { get; set; } public int MinLength { get; set; }
+1 -4
View File
@@ -1,7 +1,4 @@
namespace Wallet; namespace Wallet;
public record PasswordEntryConfiguration : public record PasswordEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>;
{
}
+1 -1
View File
@@ -9,7 +9,7 @@ public partial class PasswordEntryViewModel(IServiceProvider provider,
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, IItemEntryConfiguration<string> configuration,
string key, string key,
string value, string value,
bool isConcealed, bool isConcealed,
+1 -1
View File
@@ -1,7 +1,7 @@
namespace Wallet; namespace Wallet;
public record PinEntryConfiguration : public record PinEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>
{ {
public int Minimum { get; set; } public int Minimum { get; set; }
+1 -1
View File
@@ -9,7 +9,7 @@ public partial class PinEntryViewModel(IServiceProvider provider,
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, PinEntryConfiguration configuration,
string key, string key,
string value, string value,
double width, double width,
+1 -4
View File
@@ -1,7 +1,4 @@
namespace Wallet; namespace Wallet;
public record TextEntryConfiguration : public record TextEntryConfiguration :
ItemEntryConfiguration ItemEntryConfiguration<string>;
{
}
+1 -1
View File
@@ -9,7 +9,7 @@ public partial class TextEntryViewModel(IServiceProvider provider,
ISubscriber subscriber, ISubscriber subscriber,
IDisposer disposer, IDisposer disposer,
ItemState state, ItemState state,
ItemEntryConfiguration configuration, TextEntryConfiguration configuration,
string key, string key,
string value, string value,
bool isConcealed, bool isConcealed,