Add predicate for filtering selectable and visible entries in file manager. Start to fix support for archives.
This commit is contained in:
parent
acddc47a89
commit
1ac8513f95
2 changed files with 118 additions and 35 deletions
|
@ -1,6 +1,8 @@
|
||||||
@using AntDesign.TableModels;
|
@using AntDesign.TableModels;
|
||||||
|
@using LANCommander.Components.FileManagerComponents
|
||||||
@inject ArchiveService ArchiveService
|
@inject ArchiveService ArchiveService
|
||||||
@inject IMessageService MessageService
|
@inject IMessageService MessageService
|
||||||
|
@namespace LANCommander.Components
|
||||||
|
|
||||||
<div class="file-manager">
|
<div class="file-manager">
|
||||||
<GridRow Class="file-manager-nav">
|
<GridRow Class="file-manager-nav">
|
||||||
|
@ -124,6 +126,7 @@
|
||||||
Loading="Entries == null"
|
Loading="Entries == null"
|
||||||
OnRow="OnRow"
|
OnRow="OnRow"
|
||||||
@bind-SelectedRows="Selected"
|
@bind-SelectedRows="Selected"
|
||||||
|
RowSelectable="EntrySelectable"
|
||||||
Size="@TableSize.Small">
|
Size="@TableSize.Small">
|
||||||
<Selection Key="@context.Path" Type="@(SelectMultiple ? "checkbox" : "radio")" />
|
<Selection Key="@context.Path" Type="@(SelectMultiple ? "checkbox" : "radio")" />
|
||||||
<Column TData="string" Width="32">
|
<Column TData="string" Width="32">
|
||||||
|
@ -158,6 +161,10 @@
|
||||||
[Parameter] public FileManagerFeatures Features { get; set; } = FileManagerFeatures.NavigationBack | FileManagerFeatures.NavigationForward | FileManagerFeatures.UpALevel | FileManagerFeatures.Refresh | FileManagerFeatures.Breadcrumbs | FileManagerFeatures.NewFolder | FileManagerFeatures.UploadFile | FileManagerFeatures.Delete;
|
[Parameter] public FileManagerFeatures Features { get; set; } = FileManagerFeatures.NavigationBack | FileManagerFeatures.NavigationForward | FileManagerFeatures.UpALevel | FileManagerFeatures.Refresh | FileManagerFeatures.Breadcrumbs | FileManagerFeatures.NewFolder | FileManagerFeatures.UploadFile | FileManagerFeatures.Delete;
|
||||||
[Parameter] public IEnumerable<IFileManagerEntry> Selected { get; set; } = new List<IFileManagerEntry>();
|
[Parameter] public IEnumerable<IFileManagerEntry> Selected { get; set; } = new List<IFileManagerEntry>();
|
||||||
[Parameter] public EventCallback<IEnumerable<IFileManagerEntry>> SelectedChanged { get; set; }
|
[Parameter] public EventCallback<IEnumerable<IFileManagerEntry>> SelectedChanged { get; set; }
|
||||||
|
[Parameter] public Func<IFileManagerEntry, bool> EntrySelectable { get; set; } = _ => true;
|
||||||
|
[Parameter] public Func<IFileManagerEntry, bool> EntryVisible { get; set; } = _ => true;
|
||||||
|
|
||||||
|
FileManagerSource Source = FileManagerSource.FileSystem;
|
||||||
|
|
||||||
FileManagerDirectory Path { get; set; }
|
FileManagerDirectory Path { get; set; }
|
||||||
|
|
||||||
|
@ -184,16 +191,27 @@
|
||||||
protected override async Task OnParametersSetAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrWhiteSpace(WorkingDirectory))
|
if (!String.IsNullOrWhiteSpace(WorkingDirectory))
|
||||||
{
|
Source = FileManagerSource.FileSystem;
|
||||||
Directories = GetDirectories(WorkingDirectory);
|
|
||||||
}
|
|
||||||
else if (ArchiveId != Guid.Empty)
|
else if (ArchiveId != Guid.Empty)
|
||||||
{
|
Source = FileManagerSource.Archive;
|
||||||
Directories = await GetArchiveDirectories(ArchiveId);
|
|
||||||
}
|
Directories = await GetDirectoriesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<FileManagerDirectory> GetDirectories(string path)
|
async Task<HashSet<FileManagerDirectory>> GetDirectoriesAsync()
|
||||||
|
{
|
||||||
|
switch (Source)
|
||||||
|
{
|
||||||
|
case FileManagerSource.FileSystem:
|
||||||
|
return await GetFileSystemDirectoriesAsync(WorkingDirectory);
|
||||||
|
case FileManagerSource.Archive:
|
||||||
|
return await GetArchiveDirectoriesAsync(ArchiveId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HashSet<FileManagerDirectory>();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task<HashSet<FileManagerDirectory>> GetFileSystemDirectoriesAsync(string path)
|
||||||
{
|
{
|
||||||
var paths = Directory.EnumerateDirectories(path, "*", new EnumerationOptions
|
var paths = Directory.EnumerateDirectories(path, "*", new EnumerationOptions
|
||||||
{
|
{
|
||||||
|
@ -211,7 +229,7 @@
|
||||||
|
|
||||||
root.PopulateChildren(paths);
|
root.PopulateChildren(paths);
|
||||||
|
|
||||||
ChangeDirectory(root, true);
|
await ChangeDirectory(root, true);
|
||||||
|
|
||||||
return new HashSet<FileManagerDirectory>
|
return new HashSet<FileManagerDirectory>
|
||||||
{
|
{
|
||||||
|
@ -219,7 +237,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task<HashSet<FileManagerDirectory>> GetArchiveDirectories(Guid archiveId)
|
async Task<HashSet<FileManagerDirectory>> GetArchiveDirectoriesAsync(Guid archiveId)
|
||||||
{
|
{
|
||||||
var entries = await ArchiveService.GetContents(archiveId);
|
var entries = await ArchiveService.GetContents(archiveId);
|
||||||
var directories = new HashSet<FileManagerDirectory>();
|
var directories = new HashSet<FileManagerDirectory>();
|
||||||
|
@ -233,7 +251,7 @@
|
||||||
|
|
||||||
root.PopulateChildren(entries);
|
root.PopulateChildren(entries);
|
||||||
|
|
||||||
ChangeDirectory(root, true);
|
await ChangeDirectory(root, true);
|
||||||
|
|
||||||
return new HashSet<FileManagerDirectory>
|
return new HashSet<FileManagerDirectory>
|
||||||
{
|
{
|
||||||
|
@ -251,14 +269,14 @@
|
||||||
return entry.Name;
|
return entry.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChangeDirectory(FileManagerDirectory directory, bool clearFuture)
|
async Task ChangeDirectory(FileManagerDirectory directory, bool clearFuture)
|
||||||
{
|
{
|
||||||
if (Path != null && directory.Path != Path.Path)
|
if (Path != null && directory.Path != Path.Path)
|
||||||
Past.Add(Path);
|
Past.Add(Path);
|
||||||
|
|
||||||
Path = directory;
|
Path = directory;
|
||||||
|
|
||||||
UpdateEntries();
|
await UpdateEntries();
|
||||||
UpdateBreadcrumbs();
|
UpdateBreadcrumbs();
|
||||||
|
|
||||||
if (clearFuture)
|
if (clearFuture)
|
||||||
|
@ -284,9 +302,24 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateEntries()
|
async Task UpdateEntries()
|
||||||
{
|
{
|
||||||
Entries.Clear();
|
Entries.Clear();
|
||||||
|
|
||||||
|
switch (Source)
|
||||||
|
{
|
||||||
|
case FileManagerSource.FileSystem:
|
||||||
|
UpdateFileSystemEntries();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FileManagerSource.Archive:
|
||||||
|
await UpdateArchiveEntries();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateFileSystemEntries()
|
||||||
|
{
|
||||||
var entries = Directory.EnumerateFileSystemEntries(Path.Path);
|
var entries = Directory.EnumerateFileSystemEntries(Path.Path);
|
||||||
var separator = System.IO.Path.DirectorySeparatorChar;
|
var separator = System.IO.Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
|
@ -295,27 +328,69 @@
|
||||||
if (Directory.Exists(entry))
|
if (Directory.Exists(entry))
|
||||||
{
|
{
|
||||||
var info = new DirectoryInfo(entry);
|
var info = new DirectoryInfo(entry);
|
||||||
|
var directory = new FileManagerDirectory
|
||||||
Entries.Add(new FileManagerDirectory
|
|
||||||
{
|
{
|
||||||
Path = entry,
|
Path = entry,
|
||||||
Name = entry.Substring(Path.Path.Length).TrimStart(separator),
|
Name = entry.Substring(Path.Path.Length).TrimStart(separator),
|
||||||
ModifiedOn = info.LastWriteTime,
|
ModifiedOn = info.LastWriteTime,
|
||||||
CreatedOn = info.CreationTime,
|
CreatedOn = info.CreationTime,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (EntryVisible.Invoke(directory))
|
||||||
|
Entries.Add(directory);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var info = new FileInfo(entry);
|
var info = new FileInfo(entry);
|
||||||
|
var file = new FileManagerFile
|
||||||
Entries.Add(new FileManagerFile
|
|
||||||
{
|
{
|
||||||
Path = entry,
|
Path = entry,
|
||||||
Name = System.IO.Path.GetFileName(entry),
|
Name = System.IO.Path.GetFileName(entry),
|
||||||
ModifiedOn = info.LastWriteTime,
|
ModifiedOn = info.LastWriteTime,
|
||||||
CreatedOn = info.CreationTime,
|
CreatedOn = info.CreationTime,
|
||||||
Size = info.Length
|
Size = info.Length
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (EntryVisible.Invoke(file))
|
||||||
|
Entries.Add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task UpdateArchiveEntries()
|
||||||
|
{
|
||||||
|
var entries = await ArchiveService.GetContents(ArchiveId);
|
||||||
|
var separator = '/';
|
||||||
|
|
||||||
|
foreach (var entry in entries)
|
||||||
|
{
|
||||||
|
if (entry.FullName.EndsWith(separator))
|
||||||
|
{
|
||||||
|
var directory = new FileManagerDirectory
|
||||||
|
{
|
||||||
|
Path = entry.FullName,
|
||||||
|
Name = entry.Name,
|
||||||
|
ModifiedOn = entry.LastWriteTime.UtcDateTime.ToLocalTime(),
|
||||||
|
CreatedOn = entry.LastWriteTime.UtcDateTime.ToLocalTime(),
|
||||||
|
Size = entry.Length
|
||||||
|
};
|
||||||
|
|
||||||
|
if (EntryVisible.Invoke(directory))
|
||||||
|
Entries.Add(directory);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var file = new FileManagerFile
|
||||||
|
{
|
||||||
|
Path = entry.FullName,
|
||||||
|
Name = entry.Name,
|
||||||
|
ModifiedOn = entry.LastWriteTime.UtcDateTime.ToLocalTime(),
|
||||||
|
CreatedOn = entry.LastWriteTime.UtcDateTime.ToLocalTime(),
|
||||||
|
Size = entry.Length
|
||||||
|
};
|
||||||
|
|
||||||
|
if (EntryVisible.Invoke(file))
|
||||||
|
Entries.Add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,56 +411,56 @@
|
||||||
Breadcrumbs.Reverse();
|
Breadcrumbs.Reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigateBack()
|
async Task NavigateBack()
|
||||||
{
|
{
|
||||||
if (Past.Count > 0)
|
if (Past.Count > 0)
|
||||||
{
|
{
|
||||||
Future.Add(Path);
|
Future.Add(Path);
|
||||||
ChangeDirectory(Past.Last(), false);
|
await ChangeDirectory(Past.Last(), false);
|
||||||
Past = Past.Take(Past.Count - 1).ToList();
|
Past = Past.Take(Past.Count - 1).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigateForward()
|
async Task NavigateForward()
|
||||||
{
|
{
|
||||||
if (Future.Count > 0)
|
if (Future.Count > 0)
|
||||||
{
|
{
|
||||||
Past.Add(Path);
|
Past.Add(Path);
|
||||||
ChangeDirectory(Future.First(), false);
|
await ChangeDirectory(Future.First(), false);
|
||||||
Future = Future.Skip(1).ToList();
|
Future = Future.Skip(1).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigateUp()
|
async Task NavigateUp()
|
||||||
{
|
{
|
||||||
if (Path.Parent != null)
|
if (Path.Parent != null)
|
||||||
ChangeDirectory(Path.Parent, true);
|
await ChangeDirectory(Path.Parent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Refresh()
|
async Task Refresh()
|
||||||
{
|
{
|
||||||
ChangeDirectory(Path, false);
|
await ChangeDirectory(Path, false);
|
||||||
|
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddFolder(string name)
|
async Task AddFolder(string name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(System.IO.Path.Combine(Path.Path, name));
|
Directory.CreateDirectory(System.IO.Path.Combine(Path.Path, name));
|
||||||
|
|
||||||
Refresh();
|
await Refresh();
|
||||||
|
|
||||||
MessageService.Success("Folder created!");
|
await MessageService.Success("Folder created!");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
MessageService.Error("Error creating folder!");
|
await MessageService.Error("Error creating folder!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Delete()
|
async Task Delete()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -398,13 +473,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
Selected = new List<IFileManagerEntry>();
|
Selected = new List<IFileManagerEntry>();
|
||||||
MessageService.Success("Deleted!");
|
await MessageService.Success("Deleted!");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
MessageService.Error("Error deleting!");
|
await MessageService.Error("Error deleting!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh();
|
await Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace LANCommander.Components.FileManagerComponents
|
||||||
|
{
|
||||||
|
public enum FileManagerSource
|
||||||
|
{
|
||||||
|
FileSystem,
|
||||||
|
Archive
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue