File attachment WIP
This commit is contained in:
@@ -114,6 +114,7 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddDbContextFactory<WalletContext>();
|
services.AddDbContextFactory<WalletContext>();
|
||||||
|
|
||||||
|
services.AddHandler<CreateFileAttachmentHandler>();
|
||||||
services.AddHandler<CreateProfileImageHandler>();
|
services.AddHandler<CreateProfileImageHandler>();
|
||||||
|
|
||||||
services.AddHandler<QueryWalletHandler>();
|
services.AddHandler<QueryWalletHandler>();
|
||||||
@@ -186,12 +187,13 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddTemplate<ItemSectionViewModel, ItemSectionView>();
|
services.AddTemplate<ItemSectionViewModel, ItemSectionView>();
|
||||||
|
|
||||||
services.AddTemplate<TextEntryViewModel, TextEntryView>();
|
|
||||||
|
|
||||||
services.AddTemplate<CreateCommentEntryViewModel, CreateCommentEntryView>();
|
services.AddTemplate<CreateCommentEntryViewModel, CreateCommentEntryView>();
|
||||||
services.AddTemplate<CommentEntryViewModel, CommentEntryView>();
|
services.AddTemplate<CommentEntryViewModel, CommentEntryView>();
|
||||||
services.AddTemplate<CommentEntryCollectionViewModel, CommentEntryCollectionView>();
|
services.AddTemplate<CommentEntryCollectionViewModel, CommentEntryCollectionView>();
|
||||||
|
|
||||||
|
services.AddTemplate<AttachmentEntryCollectionViewModel, AttachmentEntryCollectionView>();
|
||||||
|
|
||||||
|
services.AddTemplate<TextEntryViewModel, TextEntryView>();
|
||||||
services.AddTemplate<PasswordEntryViewModel, PasswordEntryView>();
|
services.AddTemplate<PasswordEntryViewModel, PasswordEntryView>();
|
||||||
services.AddTemplate<MaskedTextEntryViewModel, MaskedTextEntryView>();
|
services.AddTemplate<MaskedTextEntryViewModel, MaskedTextEntryView>();
|
||||||
services.AddTemplate<DropdownEntryCollectionViewModel, DropdownEntryCollectionView>();
|
services.AddTemplate<DropdownEntryCollectionViewModel, DropdownEntryCollectionView>();
|
||||||
@@ -222,6 +224,7 @@ public partial class App : Application
|
|||||||
services.AddHandler<FavouriteItemHandler>();
|
services.AddHandler<FavouriteItemHandler>();
|
||||||
services.AddHandler<UnfavouriteItemHandler>();
|
services.AddHandler<UnfavouriteItemHandler>();
|
||||||
|
|
||||||
|
services.AddHandler<AttachmentEntryCollectionViewModelHandler>(nameof(AttachmentEntryCollectionConfiguration));
|
||||||
services.AddHandler<TextEntryViewModelHandler>(nameof(TextEntryConfiguration));
|
services.AddHandler<TextEntryViewModelHandler>(nameof(TextEntryConfiguration));
|
||||||
services.AddHandler<CommentEntryCollectionViewModelHandler>(nameof(CommentEntryCollectionConfiguration));
|
services.AddHandler<CommentEntryCollectionViewModelHandler>(nameof(CommentEntryCollectionConfiguration));
|
||||||
services.AddHandler<PasswordEntryViewModelHandler>(nameof(PasswordEntryConfiguration));
|
services.AddHandler<PasswordEntryViewModelHandler>(nameof(PasswordEntryConfiguration));
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<SettingsExpander
|
||||||
|
x:Class="Wallet.Avalonia.AttachmentEntryCollectionView"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Wallet"
|
||||||
|
x:DataType="vm:AttachmentEntryCollectionViewModel"
|
||||||
|
Header="{Binding Key}"
|
||||||
|
IsExpanded="True"
|
||||||
|
IsToggleable="{Binding Count}"
|
||||||
|
ItemTemplate="{ReflectionBinding Template}"
|
||||||
|
ItemsSource="{Binding}">
|
||||||
|
<SettingsExpander.Action>
|
||||||
|
<Button Command="{Binding InvokeCommand}" />
|
||||||
|
</SettingsExpander.Action>
|
||||||
|
</SettingsExpander>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
|
namespace Wallet.Avalonia;
|
||||||
|
|
||||||
|
public partial class AttachmentEntryCollectionView :
|
||||||
|
SettingsExpander
|
||||||
|
{
|
||||||
|
public AttachmentEntryCollectionView() =>
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public record Attachment
|
||||||
|
{
|
||||||
|
public DateTimeOffset DateTime { get; set; }
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Path { get; set; }
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public record AttachmentEntryCollectionConfiguration :
|
public record AttachmentEntryCollectionConfiguration :
|
||||||
ItemEntryConfiguration<string>;
|
ItemEntryConfiguration<ICollection<Attachment>>;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Toolkit.Foundation;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
@@ -9,9 +10,31 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide
|
|||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
ItemState state,
|
ItemState state,
|
||||||
IItemEntryConfiguration<ICollection<Comment>> configuration,
|
IItemEntryConfiguration<ICollection<Attachment>> configuration,
|
||||||
string key,
|
string key,
|
||||||
ICollection<Comment> value,
|
ICollection<Attachment> value,
|
||||||
bool isConcealed,
|
bool isConcealed,
|
||||||
bool isRevealed,
|
bool isRevealed,
|
||||||
double width) : ItemEntryCollectionViewModel<AttachmentEntryViewModel, ICollection<Comment>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width);
|
double width) : ItemEntryCollectionViewModel<AttachmentEntryViewModel, ICollection<Attachment>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width)
|
||||||
|
{
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task Invoke()
|
||||||
|
{
|
||||||
|
if (await Mediator.Handle<CreateEventArgs<FileAttachment>, IReadOnlyCollection<IFileDescriptor>>(Create.As<FileAttachment>())
|
||||||
|
is IReadOnlyCollection<IFileDescriptor> fileDescriptors)
|
||||||
|
{
|
||||||
|
foreach (IFileDescriptor file in fileDescriptors)
|
||||||
|
{
|
||||||
|
Attachment attachment = new()
|
||||||
|
{
|
||||||
|
Name = file.Name,
|
||||||
|
Path = file.Path,
|
||||||
|
DateTime = DateTimeOffset.Now
|
||||||
|
};
|
||||||
|
|
||||||
|
Add<AttachmentEntryViewModel>(attachment);
|
||||||
|
Value.Add(attachment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class AttachmentEntryCollectionViewModelHandler(IServiceFactory serviceFactory) :
|
||||||
|
IHandler<CreateEventArgs<AttachmentEntryCollectionConfiguration>, IItemEntryViewModel?>
|
||||||
|
{
|
||||||
|
public Task<IItemEntryViewModel?> Handle(CreateEventArgs<AttachmentEntryCollectionConfiguration> args,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (args.Sender is AttachmentEntryCollectionConfiguration configuration)
|
||||||
|
{
|
||||||
|
string? label = configuration.Label;
|
||||||
|
List<Attachment> values = configuration.Value is not null ? new List<Attachment>(configuration.Value) : [];
|
||||||
|
double? width = configuration.Width;
|
||||||
|
|
||||||
|
if (serviceFactory.Create<AttachmentEntryCollectionViewModel>(args => args.Initialize(),
|
||||||
|
[.. args.Parameters, configuration, label, values, false, false, width])
|
||||||
|
is AttachmentEntryCollectionViewModel viewModel)
|
||||||
|
{
|
||||||
|
//foreach (Comment value in values.OrderByDescending(x => x.DateTime))
|
||||||
|
//{
|
||||||
|
// viewModel.Add<CommentEntryViewModel>(value.DateTime, value.Text);
|
||||||
|
//}
|
||||||
|
|
||||||
|
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult<IItemEntryViewModel?>(default);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,4 +8,4 @@ public partial class AttachmentEntryViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string? value = default) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer, value);
|
Attachment? value = default) : Observable<Attachment>(provider, factory, mediator, publisher, subscriber, disposer, value);
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class CreateFileAttachmentHandler(IFileProvider fileProvider) :
|
||||||
|
IHandler<CreateEventArgs<FileAttachment>, IReadOnlyCollection<IFileDescriptor>>
|
||||||
|
{
|
||||||
|
public async Task<IReadOnlyCollection<IFileDescriptor>> Handle(CreateEventArgs<FileAttachment> args,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
List<IFileDescriptor> attachments = [];
|
||||||
|
if (await fileProvider.SelectFiles(new FileFilter("All files", [], true))
|
||||||
|
is { Count: > 0 } files)
|
||||||
|
{
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
FileInfo fileInfo = new(file);
|
||||||
|
if (fileInfo.Exists)
|
||||||
|
{
|
||||||
|
attachments.Add(new FileDescriptor(fileInfo.Name, fileInfo.FullName, (int)fileInfo.Length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachments;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public record FileAttachment;
|
||||||
+16
-16
@@ -159,7 +159,7 @@ public record ItemConfiguration
|
|||||||
{
|
{
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new AttachmentEntryCollectionConfiguration
|
new AttachmentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Attachments",
|
Label = "Attachments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,11 +221,11 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new AttachmentEntryCollectionConfiguration
|
new AttachmentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Ticket"
|
Label = "Attachments"
|
||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,7 +319,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,7 +344,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -434,7 +434,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -475,7 +475,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -520,7 +520,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -573,7 +573,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -622,7 +622,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -671,7 +671,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -740,7 +740,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -880,7 +880,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -941,7 +941,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -998,7 +998,7 @@ public record ItemConfiguration
|
|||||||
},
|
},
|
||||||
new CommentEntryCollectionConfiguration
|
new CommentEntryCollectionConfiguration
|
||||||
{
|
{
|
||||||
Label = "Notes"
|
Label = "Comments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user