This commit is contained in:
TheXamlGuy
2024-07-13 21:35:58 +01:00
parent 3b4deea573
commit f4f9fdac46
32 changed files with 369 additions and 235 deletions
@@ -0,0 +1,4 @@
namespace Wallet;
public record AttachmentEntryCollectionConfiguration :
ItemEntryConfiguration;
@@ -0,0 +1,17 @@
using Toolkit.Foundation;
namespace Wallet;
public partial class AttachmentEntryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string key,
ICollection<Comment<(string, DateTimeOffset)>> value,
bool isConcealed,
bool isRevealed,
double width) : ItemEntryCollectionViewModel<AttachmentEntryViewModel, ICollection<Comment<(string, DateTimeOffset)>>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width);
-7
View File
@@ -1,7 +0,0 @@
namespace Wallet;
public record AttachmentEntryConfiguration :
ItemEntryConfiguration
{
}
+11
View File
@@ -0,0 +1,11 @@
using Toolkit.Foundation;
namespace Wallet;
public partial class AttachmentEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
string? value = default) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer, value);
@@ -0,0 +1,4 @@
namespace Wallet;
public record CommentEntryCollectionConfiguration :
ItemEntryConfiguration;
+33
View File
@@ -0,0 +1,33 @@
using Toolkit.Foundation;
namespace Wallet;
public partial class CommentEntryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
IContentTemplate template,
ItemState state,
ItemEntryConfiguration configuration,
string key,
ICollection<Comment<(string, DateTimeOffset)>> value,
bool isConcealed,
bool isRevealed,
double width) : ItemEntryCollectionViewModel<ICommentEntryViewModel, ICollection<Comment<(string, DateTimeOffset)>>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width),
INotificationHandler<CreateEventArgs<Comment<string>>>
{
public IContentTemplate Template { get; set; } = template;
public Task Handle(CreateEventArgs<Comment<string>> args)
{
if (args.Sender is Comment<string> comment)
{
Insert<CommentEntryViewModel>(0, DateTimeOffset.Now, comment.Value);
}
return Task.CompletedTask;
}
}
@@ -0,0 +1,30 @@
using Toolkit.Foundation;
namespace Wallet;
public class CommentEntryCollectionViewModelHandler(IServiceFactory serviceFactory) :
IHandler<CreateEventArgs<CommentEntryCollectionConfiguration>, IItemEntryViewModel?>
{
public Task<IItemEntryViewModel?> Handle(CreateEventArgs<CommentEntryCollectionConfiguration> args,
CancellationToken cancellationToken)
{
if (args.Sender is CommentEntryCollectionConfiguration configuration)
{
string? label = configuration.Label;
string? value = $"{configuration.Value}" ?? "";
double? width = configuration.Width;
if (serviceFactory.Create<CommentEntryCollectionViewModel>(args => args.Initialize(),
[.. args.Parameters, configuration, label, value, false, false, width])
is CommentEntryCollectionViewModel viewModel)
{
viewModel.Add<CreateCommentEntryViewModel>();
return Task.FromResult<IItemEntryViewModel?>(viewModel);
}
}
return Task.FromResult<IItemEntryViewModel?>(default);
}
}
+13
View File
@@ -0,0 +1,13 @@
using Toolkit.Foundation;
namespace Wallet;
public partial class CommentEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
DateTimeOffset key,
string? value = default) : Observable<DateTimeOffset, string>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
ICommentEntryViewModel;
+22
View File
@@ -0,0 +1,22 @@
using CommunityToolkit.Mvvm.Input;
using Toolkit.Foundation;
namespace Wallet;
public record Comment<TValue>(TValue Value);
public partial class CreateCommentEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer),
ICommentEntryViewModel
{
[RelayCommand]
private void Invoke()
{
Publisher.Publish(Create.As(new Comment<string?>(Value)));
Value = null;
}
}
@@ -2,7 +2,7 @@
namespace Wallet;
public record DropdownEntryConfiguration :
public record DropdownEntryCollectionConfiguration :
ItemEntryConfiguration
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
@@ -0,0 +1,43 @@
using Toolkit.Foundation;
namespace Wallet;
public partial class DropdownEntryCollectionViewModel :
ItemEntryCollectionViewModel<DropdownEntryViewModel, object>
{
public DropdownEntryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
IEnumerable<DropdownEntryViewModel> items,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value,
bool isConcealed,
bool isRevealed,
double width,
DropdownEntryViewModel selectedItem) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value, isConcealed, isRevealed, width)
{
SelectedItem = selectedItem;
}
public DropdownEntryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
IEnumerable<DropdownEntryViewModel> items,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value,
bool isConcealed,
bool isRevealed,
double width) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value, isConcealed, isRevealed, width)
{
}
}
@@ -2,31 +2,31 @@
namespace Wallet;
public class DropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
IHandler<CreateEventArgs<DropdownEntryConfiguration>, IItemEntryViewModel?>
public class DropdownEntryCollectionViewModelHandler(IServiceFactory serviceFactory) :
IHandler<CreateEventArgs<DropdownEntryCollectionConfiguration>, IItemEntryViewModel?>
{
public Task<IItemEntryViewModel?> Handle(CreateEventArgs<DropdownEntryConfiguration> args,
public Task<IItemEntryViewModel?> Handle(CreateEventArgs<DropdownEntryCollectionConfiguration> args,
CancellationToken cancellationToken)
{
if (args.Sender is DropdownEntryConfiguration configuration)
if (args.Sender is DropdownEntryCollectionConfiguration configuration)
{
List<DropdownValueViewModel> values = [];
values.Add(serviceFactory.Create<DropdownValueViewModel>());
List<DropdownEntryViewModel> values = [];
values.Add(serviceFactory.Create<DropdownEntryViewModel>());
foreach (string item in configuration.Values)
{
values.Add(serviceFactory.Create<DropdownValueViewModel>(item));
values.Add(serviceFactory.Create<DropdownEntryViewModel>(item));
}
string? label = configuration.Label;
object? value = configuration.Value ?? "";
double? width = configuration.Width;
DropdownValueViewModel? selected = values.FirstOrDefault(x => x.Value is not null && x.Value.Equals($"{value}"));
DropdownEntryViewModel? selected = values.FirstOrDefault(x => x.Value is not null && x.Value.Equals($"{value}"));
if (serviceFactory.Create<DropdownEntryViewModel>(args => args.Initialize(),
if (serviceFactory.Create<DropdownEntryCollectionViewModel>(args => args.Initialize(),
[values, .. args.Parameters, configuration, label, value, false, false, width, selected ?? null])
is DropdownEntryViewModel viewModel)
is DropdownEntryCollectionViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
}
+7 -39
View File
@@ -2,42 +2,10 @@
namespace Wallet;
public partial class DropdownEntryViewModel :
ItemEntryCollectionViewModel<DropdownValueViewModel>
{
public DropdownEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
IEnumerable<DropdownValueViewModel> items,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value,
bool isConcealed,
bool isRevealed,
double width,
DropdownValueViewModel selectedItem) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value, isConcealed, isRevealed, width)
{
SelectedItem = selectedItem;
}
public DropdownEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
IEnumerable<DropdownValueViewModel> items,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value,
bool isConcealed,
bool isRevealed,
double width) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value, isConcealed, isRevealed, width)
{
}
}
public partial class DropdownEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
string? value = default) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer, value);
-11
View File
@@ -1,11 +0,0 @@
using Toolkit.Foundation;
namespace Wallet;
public partial class DropdownValueViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
string? value = null) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer, value);
+3
View File
@@ -0,0 +1,3 @@
namespace Wallet;
public interface ICommentEntryViewModel : IItemEntryViewModel;
+24 -24
View File
@@ -24,7 +24,7 @@ public record ItemConfiguration
{
Label = "Date of birth"
},
new DropdownEntryConfiguration
new DropdownEntryCollectionConfiguration
{
Label = "Gender",
Values = ["Male", "Female", "Non-binary", "Prefer not to say", "Other"]
@@ -82,7 +82,7 @@ public record ItemConfiguration
{
Label = "Name on account"
},
new DropdownEntryConfiguration
new DropdownEntryCollectionConfiguration
{
Label = "Type",
Values = [
@@ -157,7 +157,7 @@ public record ItemConfiguration
{
Entries = new List<ItemEntryConfiguration>
{
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -178,7 +178,7 @@ public record ItemConfiguration
{
Label = "Description",
},
new AttachmentEntryConfiguration
new AttachmentEntryCollectionConfiguration
{
Label = "Attachments",
}
@@ -219,11 +219,11 @@ public record ItemConfiguration
{
Label = "Price"
},
new AttachmentEntryConfiguration
new AttachmentEntryCollectionConfiguration
{
Label = "Ticket"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -317,7 +317,7 @@ public record ItemConfiguration
{
Label = "Two-factor Authentication (2FA)"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -342,7 +342,7 @@ public record ItemConfiguration
{
Label = "Expiration Date"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -391,7 +391,7 @@ public record ItemConfiguration
{
Label = "Documentation URL"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Additional Notes"
}
@@ -428,11 +428,11 @@ public record ItemConfiguration
{
Label = "Major/Field of Study"
},
new AttachmentEntryConfiguration
new AttachmentEntryCollectionConfiguration
{
Label = "Attachments"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -473,7 +473,7 @@ public record ItemConfiguration
{
Label = "Due Date"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -518,7 +518,7 @@ public record ItemConfiguration
{
Label = "Contact Information"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -567,11 +567,11 @@ public record ItemConfiguration
{
Label = "Contact Information"
},
new AttachmentEntryConfiguration
new AttachmentEntryCollectionConfiguration
{
Label = "Attachments"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -616,11 +616,11 @@ public record ItemConfiguration
{
Label = "Purpose/Details"
},
new AttachmentEntryConfiguration
new AttachmentEntryCollectionConfiguration
{
Label = "Attachments"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -669,7 +669,7 @@ public record ItemConfiguration
{
Label = "Backup Seed Phrase"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -738,7 +738,7 @@ public record ItemConfiguration
{
Label = "Passport Photo"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -759,7 +759,7 @@ public record ItemConfiguration
{
Label = "Cardholder"
},
new DropdownEntryConfiguration
new DropdownEntryCollectionConfiguration
{
Label = "Type",
Values = ["American Express", "Discover", "Maestro", "Mastercard", "Visa"]
@@ -807,7 +807,7 @@ public record ItemConfiguration
{
Label = "Interest Rates",
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Rewards"
}
@@ -878,7 +878,7 @@ public record ItemConfiguration
{
Label = "Remote Desktop URL"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -939,7 +939,7 @@ public record ItemConfiguration
{
Label = "Backup Location"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
@@ -996,7 +996,7 @@ public record ItemConfiguration
{
Label = "Usage Restrictions"
},
new MultilineTextEntryConfiguration
new CommentEntryCollectionConfiguration
{
Label = "Notes"
}
+6 -5
View File
@@ -4,13 +4,13 @@ using Toolkit.Foundation;
namespace Wallet;
public partial class ItemEntryCollectionViewModel<TItem> :
ObservableCollection<TItem, string, object>,
public partial class ItemEntryCollectionViewModel<TItem, TValue> :
ObservableCollection<TItem, string, TValue>,
IItemEntryViewModel,
INotificationHandler<UpdateEventArgs<Item>>,
INotificationHandler<ConfirmEventArgs<Item>>,
INotificationHandler<CancelEventArgs<Item>>
where TItem : notnull,
where TItem : notnull,
IDisposable
{
private readonly ItemEntryConfiguration configuration;
@@ -23,6 +23,7 @@ public partial class ItemEntryCollectionViewModel<TItem> :
[ObservableProperty]
private ItemState state;
[ObservableProperty]
private double width;
@@ -35,7 +36,7 @@ public partial class ItemEntryCollectionViewModel<TItem> :
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value,
TValue value,
bool isConcealed,
bool isRevealed,
double width) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
@@ -60,7 +61,7 @@ public partial class ItemEntryCollectionViewModel<TItem> :
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value,
TValue value,
bool isConcealed,
bool isRevealed,
double width) : base(provider, factory, mediator, publisher, subscriber, disposer, items, key, value)
+4 -4
View File
@@ -2,14 +2,14 @@
namespace Wallet;
[JsonDerivedType(typeof(DropdownEntryConfiguration), typeDiscriminator: "Dropdown")]
[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: "Image")]
[JsonDerivedType(typeof(AttachmentEntryConfiguration), typeDiscriminator: "Attachment")]
[JsonDerivedType(typeof(MultilineTextEntryConfiguration), typeDiscriminator: "MultilineText")]
[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")]
@@ -1,7 +0,0 @@
namespace Wallet;
public record MultilineTextEntryConfiguration :
ItemEntryConfiguration
{
}
-18
View File
@@ -1,18 +0,0 @@
using Toolkit.Foundation;
namespace Wallet;
public partial class MultilineTextEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string key,
string value,
bool isConcealed,
bool isRevealed,
double width) : ItemEntryViewModel<string>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width);
@@ -1,28 +0,0 @@
using Toolkit.Foundation;
namespace Wallet;
public class MultilineTextEntryViewModelHandler(IServiceFactory serviceFactory) :
IHandler<CreateEventArgs<MultilineTextEntryConfiguration>, IItemEntryViewModel?>
{
public Task<IItemEntryViewModel?> Handle(CreateEventArgs<MultilineTextEntryConfiguration> args,
CancellationToken cancellationToken)
{
if (args.Sender is MultilineTextEntryConfiguration configuration)
{
string? label = configuration.Label;
string? value = $"{configuration.Value}" ?? "";
double? width = configuration.Width;
if (serviceFactory.Create<MultilineTextEntryViewModel>(args => args.Initialize(),
[.. args.Parameters, configuration, label, value, false, false, width])
is MultilineTextEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
}
}
return Task.FromResult<IItemEntryViewModel?>(default);
}
}