File attachment WIP

This commit is contained in:
TheXamlGuy
2024-07-24 21:18:39 +01:00
parent 455c633980
commit c3996d3bcc
11 changed files with 147 additions and 24 deletions
+10
View File
@@ -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;
public record AttachmentEntryCollectionConfiguration :
ItemEntryConfiguration<string>;
ItemEntryConfiguration<ICollection<Attachment>>;
+27 -4
View File
@@ -1,4 +1,5 @@
using Toolkit.Foundation;
using CommunityToolkit.Mvvm.Input;
using Toolkit.Foundation;
namespace Wallet;
@@ -9,9 +10,31 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide
ISubscriber subscriber,
IDisposer disposer,
ItemState state,
IItemEntryConfiguration<ICollection<Comment>> configuration,
IItemEntryConfiguration<ICollection<Attachment>> configuration,
string key,
ICollection<Comment> value,
ICollection<Attachment> value,
bool isConcealed,
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);
}
}
+1 -1
View File
@@ -8,4 +8,4 @@ public partial class AttachmentEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscriber subscriber,
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);
+27
View File
@@ -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;
}
}
+3
View File
@@ -0,0 +1,3 @@
namespace Wallet;
public record FileAttachment;
+16 -16
View File
@@ -159,7 +159,7 @@ public record ItemConfiguration
{
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -180,7 +180,7 @@ public record ItemConfiguration
},
new AttachmentEntryCollectionConfiguration
{
Label = "Attachments",
Label = "Attachments"
}
}
}
@@ -221,11 +221,11 @@ public record ItemConfiguration
},
new AttachmentEntryCollectionConfiguration
{
Label = "Ticket"
Label = "Attachments"
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -319,7 +319,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -344,7 +344,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -434,7 +434,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -475,7 +475,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -520,7 +520,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -573,7 +573,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -622,7 +622,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -671,7 +671,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -740,7 +740,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -880,7 +880,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -941,7 +941,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}
@@ -998,7 +998,7 @@ public record ItemConfiguration
},
new CommentEntryCollectionConfiguration
{
Label = "Notes"
Label = "Comments"
}
}
}