2025-11-17 22:09:03 -06:00
|
|
|
@inject ArchiveService ArchiveService
|
2024-03-30 14:41:30 -05:00
|
|
|
@inject ModalService ModalService
|
|
|
|
|
|
|
|
|
|
@if (ArchiveId != Guid.Empty)
|
|
|
|
|
{
|
2024-12-31 18:21:41 -06:00
|
|
|
<Button OnClick="BrowseForFile" Type="Type" Icon="@Icon" Disabled="@(!ArchiveExists || Disabled)" ChildContent="ChildContent" />
|
2024-03-30 14:41:30 -05:00
|
|
|
}
|
|
|
|
|
else if (!String.IsNullOrWhiteSpace(Root))
|
|
|
|
|
{
|
2024-12-31 18:21:41 -06:00
|
|
|
<Button OnClick="BrowseForFile" Type="Type" Icon="@Icon" Disabled="@Disabled" ChildContent="ChildContent" />
|
2024-03-30 14:41:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
[Parameter] public string Value { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<string> ValueChanged { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<string> OnSelected { get; set; }
|
|
|
|
|
[Parameter] public Guid ArchiveId { get; set; }
|
|
|
|
|
[Parameter] public string Title { get; set; } = "Choose File";
|
|
|
|
|
[Parameter] public string OkText { get; set; } = "Select File";
|
|
|
|
|
[Parameter] public bool AllowDirectories { get; set; } = false;
|
|
|
|
|
[Parameter] public string Prefix { get; set; }
|
|
|
|
|
[Parameter] public string Root { get; set; }
|
|
|
|
|
[Parameter] public Func<IFileManagerEntry, bool> EntrySelectable { get; set; } = _ => true;
|
|
|
|
|
[Parameter] public Func<IFileManagerEntry, bool> EntryVisible { get; set; } = _ => true;
|
|
|
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
|
|
|
|
[Parameter] public string Icon { get; set; }
|
2024-12-31 18:21:41 -06:00
|
|
|
[Parameter] public ButtonType Type { get; set; }
|
2024-03-30 14:58:32 -05:00
|
|
|
[Parameter] public bool Disabled { get; set; }
|
2024-03-30 14:41:30 -05:00
|
|
|
|
|
|
|
|
bool ArchiveExists { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2025-02-01 02:21:34 -06:00
|
|
|
if (ArchiveId != Guid.Empty)
|
2025-12-03 23:41:51 -06:00
|
|
|
ArchiveExists = await ArchiveService.FileExistsAsync(ArchiveId);
|
2024-03-30 14:41:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void BrowseForFile()
|
|
|
|
|
{
|
|
|
|
|
var modalOptions = new ModalOptions()
|
2024-11-25 22:29:56 -06:00
|
|
|
{
|
|
|
|
|
Title = Title,
|
|
|
|
|
Maximizable = false,
|
|
|
|
|
DefaultMaximized = true,
|
|
|
|
|
Closable = true,
|
|
|
|
|
OkText = OkText,
|
|
|
|
|
WrapClassName = "file-picker-dialog"
|
|
|
|
|
};
|
2024-03-30 14:41:30 -05:00
|
|
|
|
|
|
|
|
var browserOptions = new FilePickerOptions()
|
2024-11-25 22:29:56 -06:00
|
|
|
{
|
|
|
|
|
ArchiveId = ArchiveId,
|
|
|
|
|
Root = Root,
|
|
|
|
|
Select = true,
|
|
|
|
|
Multiple = false,
|
|
|
|
|
EntrySelectable = EntrySelectable,
|
|
|
|
|
EntryVisible = EntryVisible
|
|
|
|
|
};
|
2024-03-30 14:41:30 -05:00
|
|
|
|
|
|
|
|
var modalRef = await ModalService.CreateModalAsync<FilePickerDialog, FilePickerOptions, IEnumerable<IFileManagerEntry>>(modalOptions, browserOptions);
|
|
|
|
|
|
|
|
|
|
modalRef.OnOk = async (results) =>
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(Prefix))
|
|
|
|
|
Value = Prefix + results?.FirstOrDefault()?.Path;
|
|
|
|
|
else
|
|
|
|
|
Value = results?.FirstOrDefault()?.Path;
|
|
|
|
|
|
|
|
|
|
if (ValueChanged.HasDelegate)
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
|
|
|
|
|
|
if (OnSelected.HasDelegate)
|
|
|
|
|
await OnSelected.InvokeAsync(Value);
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|