Switch archive file inputs to use new file manager

dhcp-server
Pat Hartl 2023-09-11 01:56:50 -05:00
parent d3f13c6493
commit 3b7a0db74e
9 changed files with 65 additions and 41 deletions

View File

@ -1,14 +0,0 @@
@inherits FeedbackComponent<ArchiveBrowserOptions, IEnumerable<ZipArchiveEntry>>
@using System.IO.Compression;
@using LANCommander.Models;
<ArchiveBrowser ArchiveId="Options.ArchiveId" @bind-SelectedFiles="SelectedFiles" Select="Options.Select" Multiple="Options.Multiple" AllowDirectories="Options.AllowDirectories" />
@code {
private IEnumerable<ZipArchiveEntry> SelectedFiles { get; set; }
public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args)
{
await base.OkCancelRefWithResult!.OnOk(SelectedFiles);
}
}

View File

@ -1,4 +1,5 @@
@using LANCommander.Models;
@using LANCommander.Components.FileManagerComponents;
@using LANCommander.Models;
@using System.IO.Compression;
@inject ModalService ModalService
@inject ArchiveService ArchiveService
@ -20,6 +21,7 @@
[Parameter] public Guid ArchiveId { get; set; }
[Parameter] public string ArchiveBrowserTitle { get; set; } = "Choose File";
[Parameter] public bool AllowDirectories { get; set; } = false;
[Parameter] public string Prefix { get; set; }
bool ArchiveExists { get; set; } = false;
@ -32,15 +34,16 @@
private async void BrowseForFile()
{
var modalOptions = new ModalOptions()
{
Title = ArchiveBrowserTitle,
Maximizable = false,
DefaultMaximized = true,
Closable = true,
OkText = "Select File"
};
{
Title = ArchiveBrowserTitle,
Maximizable = false,
DefaultMaximized = true,
Closable = true,
OkText = "Select File",
WrapClassName = "archive-file-picker-dialog"
};
var browserOptions = new ArchiveBrowserOptions()
var browserOptions = new ArchiveFilePickerOptions()
{
ArchiveId = ArchiveId,
Select = true,
@ -48,11 +51,12 @@
AllowDirectories = AllowDirectories
};
var modalRef = await ModalService.CreateModalAsync<ArchiveBrowserDialog, ArchiveBrowserOptions, IEnumerable<ZipArchiveEntry>>(modalOptions, browserOptions);
var modalRef = await ModalService.CreateModalAsync<ArchiveFilePickerDialog, ArchiveFilePickerOptions, IEnumerable<IFileManagerEntry>>(modalOptions, browserOptions);
modalRef.OnOk = async (results) =>
{
Value = "{InstallDir}/" + results.FirstOrDefault().FullName;
if (!String.IsNullOrWhiteSpace(Prefix))
Value = "{InstallDir}/" + results.FirstOrDefault().Path;
if (ValueChanged.HasDelegate)
await ValueChanged.InvokeAsync(Value);

View File

@ -0,0 +1,23 @@
@inherits FeedbackComponent<ArchiveFilePickerOptions, IEnumerable<IFileManagerEntry>>
@using System.IO.Compression;
@using LANCommander.Components.FileManagerComponents;
@using LANCommander.Models;
<FileManager ArchiveId="Options.ArchiveId" @bind-Selected="SelectedFiles" EntryVisible="IsEntryVisible" SelectMultiple="Options.Multiple" Features="@(FileManagerFeatures.NavigationBack | FileManagerFeatures.NavigationForward | FileManagerFeatures.UpALevel | FileManagerFeatures.Breadcrumbs)" />
@code {
private IEnumerable<IFileManagerEntry> SelectedFiles { get; set; }
public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args)
{
await base.OkCancelRefWithResult!.OnOk(SelectedFiles);
}
bool IsEntryVisible(IFileManagerEntry entry)
{
if (!Options.AllowDirectories && entry is FileManagerDirectory)
return false;
else
return true;
}
}

View File

@ -1,6 +1,6 @@
namespace LANCommander.Models
{
public class ArchiveBrowserOptions
public class ArchiveFilePickerOptions
{
public Guid ArchiveId { get; set; }
public bool Select { get; set; }

View File

@ -1,4 +1,5 @@
@using LANCommander.Data.Models
@using LANCommander.Components.FileManagerComponents;
@using LANCommander.Data.Models
@using LANCommander.Extensions
@using LANCommander.Models;
@using System.IO.Compression;
@ -11,7 +12,7 @@
<Input Type="text" @bind-Value="context.Name" />
</PropertyColumn>
<PropertyColumn Property="a => a.Path">
<InputArchiveFile @bind-Value="context.Path" ArchiveId="@ArchiveId" AllowDirectories="true" />
<ArchiveFilePicker @bind-Value="context.Path" ArchiveId="@ArchiveId" AllowDirectories="true" />
</PropertyColumn>
<PropertyColumn Property="a => a.Arguments">
<Input Type="text" @bind-Value="context.Arguments" />
@ -100,18 +101,18 @@
OkText = "Select File"
};
var browserOptions = new ArchiveBrowserOptions()
var browserOptions = new ArchiveFilePickerOptions()
{
ArchiveId = ArchiveId,
Select = true,
Multiple = false
};
var modalRef = await ModalService.CreateModalAsync<ArchiveBrowserDialog, ArchiveBrowserOptions, IEnumerable<ZipArchiveEntry>>(modalOptions, browserOptions);
var modalRef = await ModalService.CreateModalAsync<ArchiveFilePickerDialog, ArchiveFilePickerOptions, IEnumerable<IFileManagerEntry>>(modalOptions, browserOptions);
modalRef.OnOk = (results) =>
{
action.Path = results.FirstOrDefault().FullName;
action.Path = results.FirstOrDefault().Path;
var parts = action.Path.Split('/');

View File

@ -14,7 +14,7 @@
}
else
{
<InputArchiveFile @bind-Value="context.Path" ArchiveId="@ArchiveId" AllowDirectories="true" />
<ArchiveFilePicker @bind-Value="context.Path" ArchiveId="@ArchiveId" AllowDirectories="true" />
}
</PropertyColumn>
<ActionColumn>

View File

@ -1,4 +1,5 @@
@using LANCommander.Data.Enums;
@using LANCommander.Components.FileManagerComponents;
@using LANCommander.Data.Enums;
@using LANCommander.Extensions;
@using LANCommander.Models
@using LANCommander.Services
@ -213,18 +214,18 @@
OkText = "Insert File Path"
};
var browserOptions = new ArchiveBrowserOptions()
var browserOptions = new ArchiveFilePickerOptions()
{
ArchiveId = ArchiveId,
Select = true,
Multiple = false
};
var modalRef = await ModalService.CreateModalAsync<ArchiveBrowserDialog, ArchiveBrowserOptions, IEnumerable<ZipArchiveEntry>>(modalOptions, browserOptions);
var modalRef = await ModalService.CreateModalAsync<ArchiveFilePickerDialog, ArchiveFilePickerOptions, IEnumerable<IFileManagerEntry>>(modalOptions, browserOptions);
modalRef.OnOk = (results) =>
{
var path = results.FirstOrDefault().FullName;
var path = results.FirstOrDefault().Path;
Editor.Trigger("keyboard", "type", new
{

View File

@ -1,6 +1,7 @@
@page "/Games/{id:guid}"
@page "/Games/{id:guid}/{panel}"
@page "/Games/Add"
@using LANCommander.Components.FileManagerComponents;
@using LANCommander.Models;
@using LANCommander.Pages.Games.Components
@using System.IO.Compression;
@ -70,7 +71,7 @@
<Input @bind-Value="@context.SortTitle" />
</FormItem>
<FormItem Label="Icon">
<InputArchiveFile @bind-Value="context.Icon" ArchiveId="@LatestArchiveId" AllowDirectories="true" />
<ArchiveFilePicker @bind-Value="context.Icon" ArchiveId="@LatestArchiveId" AllowDirectories="true" />
</FormItem>
<FormItem Label="Notes">
<TextArea @bind-Value="@context.Notes" MaxLength=2000 ShowCount />
@ -160,7 +161,7 @@ else
IEnumerable<Genre> Genres;
IEnumerable<Data.Models.Tag> Tags;
ArchiveBrowserDialog ArchiveBrowserDialog;
ArchiveFilePickerDialog ArchiveFilePickerDialog;
Modal FileSelectorModal;
@ -250,18 +251,18 @@ else
OkText = "Select File"
};
var browserOptions = new ArchiveBrowserOptions()
var browserOptions = new ArchiveFilePickerOptions()
{
ArchiveId = Game.Archives.FirstOrDefault().Id,
Select = true,
Multiple = false
};
var modalRef = await ModalService.CreateModalAsync<ArchiveBrowserDialog, ArchiveBrowserOptions, IEnumerable<ZipArchiveEntry>>(modalOptions, browserOptions);
var modalRef = await ModalService.CreateModalAsync<ArchiveFilePickerDialog, ArchiveFilePickerOptions, IEnumerable<IFileManagerEntry>>(modalOptions, browserOptions);
modalRef.OnOk = (results) =>
{
Game.Icon = results.FirstOrDefault().FullName;
Game.Icon = results.FirstOrDefault().Path;
StateHasChanged();
return Task.CompletedTask;
};

View File

@ -142,6 +142,14 @@
margin-top: 4px;
}
.archive-file-picker-dialog .ant-modal-body {
padding: 0;
}
.archive-file-picker-dialog .file-manager {
height: calc(100vh - 55px - 53px);
}
@media screen and (min-width: 768px) {
.mobile-menu {
display: none;