From b9259ce6ca90f9e4a002f888b8eed3d728cd24a5 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Thu, 16 Sep 2021 07:59:36 -0400 Subject: [PATCH] added optional event callback delegates to FileManager component to allow calling components to be notified on upload, change, or delete --- .../Modules/Controls/FileManager.razor | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Oqtane.Client/Modules/Controls/FileManager.razor b/Oqtane.Client/Modules/Controls/FileManager.razor index d454a0de..c8c5e82a 100644 --- a/Oqtane.Client/Modules/Controls/FileManager.razor +++ b/Oqtane.Client/Modules/Controls/FileManager.razor @@ -96,7 +96,7 @@ public string Id { get; set; } // optional - for setting the id of the FileManager component for accessibility [Parameter] - public string Folder { get; set; } // optional - for setting a specific folder by default + public string Folder { get; set; } // optional - for setting a specific folder by default ( only relevant for host functions ) [Parameter] public int FolderId { get; set; } = -1; // optional - for setting a specific folderid by default @@ -114,7 +114,7 @@ public bool ShowImage { get; set; } = true; // optional - for indicating whether an image thumbnail should be displayed - default is true [Parameter] - public int FileId { get; set; } = -1; // optional - for setting a specific file by default + public int FileId { get; set; } = -1; // optional - for selecting a specific file by default [Parameter] public string Filter { get; set; } // optional - comma delimited list of file types that can be selected or uploaded ie. "jpg,gif" @@ -122,6 +122,15 @@ [Parameter] public bool UploadMultiple { get; set; } = false; // optional - enable multiple file uploads - default false + [Parameter] + public EventCallback OnUpload { get; set; } // optional - executes a method in the calling component when a file is uploaded + + [Parameter] + public EventCallback OnChange { get; set; } // optional - executes a method in the calling component when a file is selected + + [Parameter] + public EventCallback OnDelete { get; set; } // optional - executes a method in the calling component when a file is deleted + protected override async Task OnInitializedAsync() { if (!string.IsNullOrEmpty(Id)) @@ -228,6 +237,7 @@ { _message = string.Empty; FileId = int.Parse((string)e.Value); + await OnChange.InvokeAsync(FileId); await SetImage(); StateHasChanged(); @@ -291,8 +301,13 @@ { FileId = file.FileId; await SetImage(); + await OnUpload.InvokeAsync(FileId); } } + else + { + await OnUpload.InvokeAsync(-1); + } StateHasChanged(); } else @@ -325,6 +340,7 @@ { await FileService.DeleteFileAsync(FileId); await logger.LogInformation("File Deleted {File}", FileId); + await OnDelete.InvokeAsync(FileId); _message = Localizer["Success.File.Delete"]; _messagetype = MessageType.Success;