Implements directory browser dialog, part 6: hidden file system items toggle

This commit is contained in:
BinaryAlley committed 2024-09-24 11:10:03 +03:00
1 parent cd44f11d9e
commit debad9ef74
74 files changed
+596 -427

No files matched your search

@@ -1,4 +1,4 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Exceptions;
using Lumina.Presentation.Web.Common.Models.Common;
using Lumina.Presentation.Web.Common.Models.Configuration;
@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Components.WebAssembly.Http;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.CompilerServices;
@@ -90,7 +91,7 @@ public class ApiHttpClient : IApiHttpClient
// send the request and expect only headers initially - this prevents the client from buffering the entire response
using HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
await using System.IO.Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await using Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
// Deserialize the JSON content asynchronously as an enumerable of TResponse items
await foreach (TResponse? item in JsonSerializer.DeserializeAsyncEnumerable<TResponse>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false))
{
@@ -215,4 +216,4 @@ public class ApiHttpClient : IApiHttpClient
}
}
#endregion
}
}
@@ -37,7 +37,7 @@ internal static class PresentationWebLayerConfiguration
internal static IServiceCollection BindConfiguration(this IServiceCollection serviceCollection, IConfiguration configuration)
{
serviceCollection.AddOptions<ServerConfigurationModel>()
.Bind(configuration.GetRequiredSection(ServerConfigurationModel.SectionName))
.Bind(configuration.GetRequiredSection(ServerConfigurationModel.SECTION_NAME))
.ValidateFluently()
.ValidateOnStart();
return serviceCollection;
@@ -1,10 +1,13 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Services;
using Lumina.Presentation.Web.Core.Services.UI;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using Polly.CircuitBreaker;
using Polly.Retry;
using Polly.Wrap;
using System;
using System.Net;
using System.Net.Http;
@@ -29,7 +32,7 @@ public static class PresentationWebLayerServices
services.AddValidatorsFromAssemblyContaining<Program>(ServiceLifetime.Singleton);
// handle transient errors like network timeouts or intermittent failures
Polly.Retry.AsyncRetryPolicy<HttpResponseMessage> retryPolicy = Policy
AsyncRetryPolicy<HttpResponseMessage> retryPolicy = Policy
.Handle<HttpRequestException>()
.OrResult<HttpResponseMessage>(r =>
!r.IsSuccessStatusCode &&
@@ -39,12 +42,12 @@ public static class PresentationWebLayerServices
TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
// use a circuit breaker to prevent repeatedly calling a failing service
Polly.CircuitBreaker.AsyncCircuitBreakerPolicy<HttpResponseMessage> circuitBreakerPolicy = Policy
AsyncCircuitBreakerPolicy<HttpResponseMessage> circuitBreakerPolicy = Policy
.Handle<HttpRequestException>()
.OrResult<HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.InternalServerError)
.CircuitBreakerAsync(3, TimeSpan.FromSeconds(30));
Polly.Wrap.AsyncPolicyWrap<HttpResponseMessage> policy = Policy.WrapAsync(retryPolicy, circuitBreakerPolicy);
AsyncPolicyWrap<HttpResponseMessage> policy = Policy.WrapAsync(retryPolicy, circuitBreakerPolicy);
// register the typed client used for the API interaction
services.AddHttpClient<IApiHttpClient, ApiHttpClient>()
@@ -57,4 +60,4 @@ public static class PresentationWebLayerServices
return services;
}
#endregion
}
}
@@ -7,11 +7,11 @@ namespace Lumina.Presentation.Web.Common.Models.Configuration;
/// <summary>
/// Model for deserializing server configuration settings.
/// </summary>
[DebuggerDisplay("{SectionName}")]
[DebuggerDisplay("{SECTION_NAME}")]
public class ServerConfigurationModel
{
#region ================================================================== FIELD MEMBERS ================================================================================
public const string SectionName = "ServerConfiguration";
public const string SECTION_NAME = "ServerConfiguration";
#endregion
#region ==================================================================== PROPERTIES =================================================================================
@@ -30,4 +30,4 @@ public class ServerConfigurationModel
/// </summary>
public required ushort Port { get; init; }
#endregion
}
}
@@ -1,4 +1,4 @@
@using Lumina.Presentation.Web.Common.Models.Common
@using Lumina.Presentation.Web.Common.Models.Common
@using Lumina.Presentation.Web.Common.Api
@using Lumina.Presentation.Web.Common.Enums.FileSystem
@using Lumina.Presentation.Web.Common.Enums.Notifications
@@ -39,14 +39,10 @@
</div>
<img src="images/ui/toggle-tree-view.svg" id="navigator-toggle-tree-view-button" alt="Toggle Tree View" title="Toggle Tree View" class="navigator-icon" />
<img src="images/ui/toggle-thumbnails.svg" id="navigator-toggle-thumbnails-button" alt="Toggle Thumbnails" title="Toggle Thumbanils" class="navigator-icon" />
<img src="images/ui/toggle-hidden.svg" id="navigator-toggle-hidden-button" alt="Toggle Hidden Files" title="Toggle Hidden Files" class="navigator-icon" />
@* <img src="images/ui/toggle-selection.svg" id="navigator-toggle-selection-button" alt="Toggle Selection Mode" title="Toggle Selection Mode" class="navigator-icon" /> *@
@* <img src="images/ui/toggle-hidden.svg" id="navigator-toggle-hidden-button" alt="Toggle Hidden Files" title="Toggle Hidden Files" class="navigator-icon" /> *@
<svg @onclick="ToggleSelectionModeAsync" id="navigator-toggle-selection-button" alt="Toggle Selection Mode" title="Toggle Selection Mode" class="navigator-icon" width="30" height="30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg @onclick="ToggleHiddenElementsModeAsync" id="navigator-toggle-hidden-button" class="navigator-icon" width="30" height="30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Toggle Hidden Files</title>
<defs>
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%">
<feComponentTransfer in="SourceAlpha" result="adjustedAlpha">
@@ -60,7 +56,8 @@
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
<linearGradient id="linearGradient1299" x1="5" x2="195" y1="174.76" y2="174.76" gradientTransform="matrix(.32632 0 0 .095367 -.63187 42.834)" gradientUnits="userSpaceOnUse">
<linearGradient id="linearGradient" x1="5" x2="195" y1="174.76" y2="174.76" gradientTransform="matrix(.32632 0 0 .095367 -.63187 42.834)" gradientUnits="userSpaceOnUse">
<stop stop-color="#039bfc" stop-opacity="0" offset="0" />
<stop stop-color="#039bfc" offset=".225" />
<stop stop-color="#039bfc" offset=".5" />
@@ -70,7 +67,44 @@
</defs>
<g transform="translate(0,-0.5) scale(0.475)">
<rect x=".99971" y="59" width="62.001" height="1" ry="0" fill="url(#linearGradient1299)" stroke-width="3.7796" style="mix-blend-mode:normal;paint-order:stroke fill markers" filter="url(#glow)" />
<rect x=".99971" y="59" width="62.001" height="1" ry="0" fill="url(#linearGradient)" stroke-width="3.7796" style="mix-blend-mode:normal;paint-order:stroke fill markers" filter="url(#glow)" />
</g>
<g stroke-linecap="round" stroke-linejoin="round" stroke-width="0.5">
<rect x="4.5" y="4.5" width="21" height="21" ry="2.5" fill="none" stroke="#039bfc" style="paint-order:stroke fill markers" filter="url(#glow)" />
</g>
<g transform="translate(5,5) scale(0.85)">
<path xmlns="http://www.w3.org/2000/svg" style="fill:currentColor;" class="navigator-icon-fill @(showHiddenElements ? " enabled" : string.Empty)" filter="url(#glow)" d="M14.3307 7.16929C13.5873 7.05887 12.806 7 12 7C7.02944 7 3 9.23858 3 12C3 13.4401 4.09589 14.738 5.84963 15.6504L8.21192 13.2881C8.07452 12.8839 8 12.4506 8 12C8 9.79086 9.79086 8 12 8C12.4506 8 12.8839 8.07452 13.2881 8.21192L14.3307 7.16929Z" />
<path xmlns="http://www.w3.org/2000/svg" style="fill:currentColor;" class="navigator-icon-fill @(showHiddenElements ? " enabled" : string.Empty)" filter="url(#glow)" d="M11.2308 15.9261C11.4797 15.9746 11.7369 16 12 16C14.2091 16 16 14.2091 16 12C16 11.7369 15.9746 11.4797 15.9261 11.2308L18.5726 8.58427C20.0782 9.47809 21 10.6792 21 12C21 14.7614 16.9706 17 12 17C11.4016 17 10.8169 16.9676 10.2512 16.9057L11.2308 15.9261Z" />
<path xmlns="http://www.w3.org/2000/svg" style="fill:currentColor;" class="navigator-icon-fill @(showHiddenElements ? " enabled" : string.Empty)" filter="url(#glow)" d="M17.7929 5.20711C18.1834 4.81658 18.8166 4.81658 19.2071 5.20711C19.5976 5.59763 19.5976 6.2308 19.2071 6.62132L6.47919 19.3492C6.08866 19.7398 5.4555 19.7398 5.06497 19.3492C4.67445 18.9587 4.67445 18.3256 5.06497 17.935L17.7929 5.20711Z" />
</g>
</svg>
<svg @onclick="ToggleSelectionModeAsync" id="navigator-toggle-selection-button" class="navigator-icon" width="30" height="30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Toggle Selection Mode</title>
<defs>
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%">
<feComponentTransfer in="SourceAlpha" result="adjustedAlpha">
<feFuncA type="table" tableValues="0 0.5 1" />
</feComponentTransfer>
<feGaussianBlur in="adjustedAlpha" stdDeviation="2" result="blur" />
<feFlood flood-color="#039bfc" result="color" />
<feComposite in="color" in2="blur" operator="in" result="softGlowColored" />
<feMerge>
<feMergeNode in="softGlowColored" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
<linearGradient id="linearGradient1" x1="5" x2="195" y1="174.76" y2="174.76" gradientTransform="matrix(.32632 0 0 .095367 -.63187 42.834)" gradientUnits="userSpaceOnUse">
<stop stop-color="#039bfc" stop-opacity="0" offset="0" />
<stop stop-color="#039bfc" offset=".225" />
<stop stop-color="#039bfc" offset=".5" />
<stop stop-color="#039bfc" offset=".775" />
<stop stop-color="#039bfc" stop-opacity="0" offset="1" />
</linearGradient>
</defs>
<g transform="translate(0,-0.5) scale(0.475)">
<rect x=".99971" y="59" width="62.001" height="1" ry="0" fill="url(#linearGradient)" stroke-width="3.7796" style="mix-blend-mode:normal;paint-order:stroke fill markers" filter="url(#glow)" />
</g>
<g stroke-linecap="round" stroke-linejoin="round" stroke-width="0.5">
<rect x="4.5" y="4.5" width="21" height="21" ry="2.5" fill="none" stroke="#039bfc" style="paint-order:stroke fill markers" filter="url(#glow)" />
@@ -229,6 +263,7 @@
private string? selectedNodePath;
private string? _path;
private bool isSelectionMode;
private bool showHiddenElements;
private bool showPathSegmentDowpDown;
private bool isNavigationPathEditMode;
private int? expandedPathSegmentIndex;
@@ -312,7 +347,7 @@
{
try
{
await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>($"directories/get-tree-directories?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false))
await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>($"directories/get-tree-directories?path={Uri.EscapeDataString(node.Path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false))
{
if (childNode is not null)
{
@@ -322,7 +357,7 @@
}
if (IncludeFiles)
{
await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>($"files/get-tree-files?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false))
await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>($"files/get-tree-files?path={Uri.EscapeDataString(node.Path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false))
{
if (childNode is not null)
{
@@ -386,7 +421,7 @@
// add current and parent directories too
List<FileSystemTreeNodeModel> directories = [new() { Path = concatenatedPath, Name = ".", }, new() { Path = parentConcatenatedPath, Name = ".." }];
// add the rest of the subdirectories of the expanded path node
await foreach (FileSystemTreeNodeModel? directory in _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>($"directories/get-tree-directories?path={Uri.EscapeDataString(concatenatedPath)}").ConfigureAwait(false))
await foreach (FileSystemTreeNodeModel? directory in _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>($"directories/get-tree-directories?path={Uri.EscapeDataString(concatenatedPath)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false))
if (directory is not null)
directories.Add(directory);
// store the directories for this segment
@@ -622,7 +657,7 @@
});
}
// if there was an initial path saved from a previous session, load the full tree up to that initial path
List<FileSystemTreeNodeModel> initialTree = await _apiHttpClient.GetAsync<List<FileSystemTreeNodeModel>>($"directories/get-directory-tree?path={Uri.EscapeDataString(path!)}&includeFiles={IncludeFiles}").ConfigureAwait(false);
List<FileSystemTreeNodeModel> initialTree = await _apiHttpClient.GetAsync<List<FileSystemTreeNodeModel>>($"directories/get-directory-tree?path={Uri.EscapeDataString(path!)}&includeFiles={IncludeFiles}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false);
if (initialTree is not null && initialTree.Count > 0)
{
// take the root of the retrieved tree, and try to match it against a drive in the retrieved list of drives, on Windows; on Unix, add it as the unique root path
@@ -651,7 +686,7 @@
fileSystemItems.Clear();
try
{
await foreach (DirectoryModel? directory in _apiHttpClient.GetAsyncEnumerable<DirectoryModel>($"directories/get-directories?path={Uri.EscapeDataString(path)}").ConfigureAwait(false))
await foreach (DirectoryModel? directory in _apiHttpClient.GetAsyncEnumerable<DirectoryModel>($"directories/get-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false))
{
if (directory is not null)
{
@@ -661,7 +696,7 @@
}
if (IncludeFiles)
{
await foreach (FileModel? file in _apiHttpClient.GetAsyncEnumerable<FileModel>($"files/get-files?path={Uri.EscapeDataString(path)}").ConfigureAwait(false))
await foreach (FileModel? file in _apiHttpClient.GetAsyncEnumerable<FileModel>($"files/get-files?path={Uri.EscapeDataString(path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false))
{
if (file is not null)
{
@@ -774,6 +809,20 @@
await JSRuntime.InvokeVoidAsync("toggleSelectionMode").ConfigureAwait(false);
}
/// <summary>
/// Enables or disables the display of hidden file system files and directories.
/// </summary>
private async Task ToggleHiddenElementsModeAsync()
{
showHiddenElements = !showHiddenElements;
if (Path is not null)
{
if (!Path.EndsWith(pathSeparator))
Path += pathSeparator;
await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false);
}
}
/// <summary>
/// Handles API exceptions, presenting standard problem details in a user friendly way.
/// </summary>
@@ -820,4 +869,4 @@
{
reference?.Dispose();
}
}
}
@@ -21,5 +21,10 @@
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Polly" Version="8.4.1" />
</ItemGroup>
</ItemGroup>
<!--disable warnings generated by Mediator source generator-->
<PropertyGroup>
<NoWarn>$(NoWarn);TS6385</NoWarn>
</PropertyGroup>
</Project>
@@ -1,51 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<style type="text/css" id="current-color-scheme">
.ColorScheme-Text {
color:#039bfc;
}
</style>
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%">
<feComponentTransfer in="SourceAlpha" result="adjustedAlpha">
<feFuncA type="table" tableValues="0 0.5 1"/>
</feComponentTransfer>
<feGaussianBlur in="adjustedAlpha" stdDeviation="2" result="blur"/>
<feFlood flood-color="#039bfc" result="color"/>
<feComposite in="color" in2="blur" operator="in" result="softGlowColored"/>
<feMerge>
<feMergeNode in="softGlowColored"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
<linearGradient id="b" x1="399.57" x2="399.57" y1="545.8" y2="517.8" gradientTransform="matrix(2.1429 0 0 2.1429 -723.44 -1107.5)" gradientUnits="userSpaceOnUse">
<stop stop-color="#3889e9" offset="0"/>
<stop stop-color="#5ea5fb" offset="1"/>
</linearGradient>
<linearGradient id="b-3" x1="399.57" x2="399.57" y1="545.8" y2="517.8" gradientTransform="matrix(2.1429 0 0 2.1429 -753.02 -1107.5)" gradientUnits="userSpaceOnUse">
<stop stop-color="#3889e9" offset="0"/>
<stop stop-color="#5ea5fb" offset="1"/>
</linearGradient>
<linearGradient id="linearGradient1299" x1="5" x2="195" y1="174.76" y2="174.76" gradientTransform="matrix(.32632 0 0 .095367 -.63187 42.834)" gradientUnits="userSpaceOnUse">
<stop stop-color="#039bfc" stop-opacity="0" offset="0"/>
<stop stop-color="#039bfc" offset=".225"/>
<stop stop-color="#039bfc" offset=".5"/>
<stop stop-color="#039bfc" offset=".775"/>
<stop stop-color="#039bfc" stop-opacity="0" offset="1"/>
</linearGradient>
</defs>
<circle cx="134.94" cy="32.044" r="0" fill="url(#b)" stroke-width="1.5715"/>
<circle cx="105.36" cy="32.044" r="0" fill="url(#b-3)" stroke-width="1.5715"/>
<rect x=".99971" y="59" width="62.001" height="1" ry="0" fill="url(#linearGradient1299)" stroke-width="3.7796" style="mix-blend-mode:normal;paint-order:stroke fill markers" filter="url(#glow)"/>
<g stroke-linecap="round" stroke-linejoin="round">
<rect x="9.5" y="9.5" width="45" height="45" ry="5" fill="none" stroke="#039bfc" style="paint-order:stroke fill markers" filter="url(#glow)"/>
</g>
<g transform="translate(8,8) scale(2)">
<path style="fill:currentColor;fill-opacity:1;stroke:none" d="M14.3307 7.16929C13.5873 7.05887 12.806 7 12 7C7.02944 7 3 9.23858 3 12C3 13.4401 4.09589 14.738 5.84963 15.6504L8.21192 13.2881C8.07452 12.8839 8 12.4506 8 12C8 9.79086 9.79086 8 12 8C12.4506 8 12.8839 8.07452 13.2881 8.21192L14.3307 7.16929Z" class="ColorScheme-Text" filter="url(#glow)"/>
<path style="fill:currentColor;fill-opacity:1;stroke:none" d="M11.2308 15.9261C11.4797 15.9746 11.7369 16 12 16C14.2091 16 16 14.2091 16 12C16 11.7369 15.9746 11.4797 15.9261 11.2308L18.5726 8.58427C20.0782 9.47809 21 10.6792 21 12C21 14.7614 16.9706 17 12 17C11.4016 17 10.8169 16.9676 10.2512 16.9057L11.2308" class="ColorScheme-Text" filter="url(#glow)"/>
<path style="fill:currentColor;fill-opacity:1;stroke:none" d="M17.7929 5.20711C18.1834 4.81658 18.8166 4.81658 19.2071 5.20711C19.5976 5.59763 19.5976 6.2308 19.2071 6.62132L6.47919 19.3492C6.08866 19.7398 5.4555 19.7398 5.06497 19.3492C4.67445 18.9587 4.67445 18.3256 5.06497 17.935L17.7929 5.20711Z" class="ColorScheme-Text" filter="url(#glow)"/>
</g>
</svg>