diff --git a/README.md b/README.md index fa70731f..7b74e4bd 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,15 @@ Any modifications or adaptations made to the original graphics and styles are my To explore more about Enlightenment and their contributions to the open-source community, please visit the [official Enlightenment website](https://www.enlightenment.org/). +### Icons + +Most icons were taken from [Lyra Icon Theme](https://github.com/yeyushengfan258/Lyra-icon-theme/tree/master/src), a beautiful icon theme for Linux desktops. + +Several icons used in this project were adapted from icons sourced from [svgrepo](https://www.svgrepo.com/). + +- [`toggle-thumbnails.svg`](https://www.svgrepo.com/svg/370469/page-image) (Public Domain license) +- [`toggle-hidden.svg`](https://www.svgrepo.com/svg/470389/hidden) (MIT License) + ## License This project is licensed under the GPLv3.0. See the [LICENSE](./docs/LICENSE.md) file for details. \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQuery.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQuery.cs new file mode 100644 index 00000000..2ab3470e --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQuery.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Responses.FileManagement; +using Mediator; +using System.Collections.Generic; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Query for retrieving the parent of a file system path. +/// +/// The path for which to get the parent. +public record GetPathParentQuery(string Path) : IRequest>>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQueryHandler.cs new file mode 100644 index 00000000..92fa47b3 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQueryHandler.cs @@ -0,0 +1,50 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Responses.FileManagement; +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; +using Mapster; +using Mediator; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Handler for the query to get the parent of a file system path. +/// +public class GetPathParentQueryHandler : IRequestHandler>> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IPathService _pathService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for managing file system paths. + public GetPathParentQueryHandler(IPathService pathService) + { + _pathService = pathService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the parent of the specified file system path. + /// + /// The query containing the requested path. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either a collection of , or an error message. + /// + public ValueTask>> Handle(GetPathParentQuery request, CancellationToken cancellationToken) + { + ErrorOr> result = _pathService.GoUpOneLevel(request.Path); + return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt>()), errors => errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQueryValidator.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQueryValidator.cs new file mode 100644 index 00000000..7063cf8d --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathParentQueryValidator.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Validates the needed validation rules for . +/// +public class GetPathParentQueryValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public GetPathParentQueryValidator() + { + RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQueryValidator.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQueryValidator.cs new file mode 100644 index 00000000..5445e2b8 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQueryValidator.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Validates the needed validation rules for . +/// +public class GetPathRootQueryValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public GetPathRootQueryValidator() + { + RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQuery.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQuery.cs new file mode 100644 index 00000000..7c786b8a --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQuery.cs @@ -0,0 +1,12 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Responses.FileManagement; +using Mediator; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Query for validating a path. +/// +/// The path to be validated. +public record ValidatePathQuery(string Path) : IRequest; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQueryHandler.cs new file mode 100644 index 00000000..767d5d2b --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQueryHandler.cs @@ -0,0 +1,45 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Responses.FileManagement; +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; +using Mediator; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Handler for the query to validate a file system path. +/// +public class ValidatePathQueryHandler : IRequestHandler +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IPathService _pathService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for managing file system paths. + public ValidatePathQueryHandler(IPathService pathService) + { + _pathService = pathService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Validates the specified file system path. + /// + /// The query containing the request. + /// Cancellation token that can be used to stop the execution. + /// + /// if the specified path is valid, otherwise. + /// + public ValueTask Handle(ValidatePathQuery request, CancellationToken cancellationToken) + { + return ValueTask.FromResult(new PathValidResponse(_pathService.IsValidPath(request.Path))); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQueryValidator.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQueryValidator.cs new file mode 100644 index 00000000..ee86b0d4 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/ValidatePathQueryValidator.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Validates the needed validation rules for . +/// +public class ValidatePathQueryValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public ValidatePathQueryValidator() + { + RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/FileSystemTypeResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/FileSystemTypeResponse.cs index 0e0ca42e..73477def 100644 --- a/src/Lumina.Contracts/Responses/FileManagement/FileSystemTypeResponse.cs +++ b/src/Lumina.Contracts/Responses/FileManagement/FileSystemTypeResponse.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Contracts.Enums.FileSystem; +using System.Diagnostics; #endregion namespace Lumina.Contracts.Responses.FileManagement; @@ -8,6 +9,7 @@ namespace Lumina.Contracts.Responses.FileManagement; /// Represents a response containing the file system platform type. /// /// The returned file system platform type. +[DebuggerDisplay("{PlatformType}")] public record FileSystemTypeResponse( PlatformType PlatformType ); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/PathSegmentResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/PathSegmentResponse.cs index 58e5827d..1cf90572 100644 --- a/src/Lumina.Contracts/Responses/FileManagement/PathSegmentResponse.cs +++ b/src/Lumina.Contracts/Responses/FileManagement/PathSegmentResponse.cs @@ -1,9 +1,14 @@ -namespace Lumina.Contracts.Responses.FileManagement; +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.FileManagement; /// /// Represents a response containing a file system path. /// /// The returned path. +[DebuggerDisplay("{Path}")] public record PathSegmentResponse( string Path ); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/PathSeparatorResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/PathSeparatorResponse.cs index f60fac5a..663f4d49 100644 --- a/src/Lumina.Contracts/Responses/FileManagement/PathSeparatorResponse.cs +++ b/src/Lumina.Contracts/Responses/FileManagement/PathSeparatorResponse.cs @@ -1,9 +1,14 @@ -namespace Lumina.Contracts.Responses.FileManagement; +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.FileManagement; /// /// Represents a response to the inquiry about the system's path separator. /// /// The system's path separator. +[DebuggerDisplay("{Separator}")] public record PathSeparatorResponse( string Separator ); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/PathValidResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/PathValidResponse.cs new file mode 100644 index 00000000..0b72e8a5 --- /dev/null +++ b/src/Lumina.Contracts/Responses/FileManagement/PathValidResponse.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.FileManagement; + +/// +/// Represents a response to the inquiry about the validity of a file system path. +/// +/// Whether a file system path is valid or not. +[DebuggerDisplay("{IsValid}")] +public record PathValidResponse( + bool IsValid +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/SplitPathResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/SplitPathResponse.cs index 49bfdc9d..2416699c 100644 --- a/src/Lumina.Contracts/Responses/FileManagement/SplitPathResponse.cs +++ b/src/Lumina.Contracts/Responses/FileManagement/SplitPathResponse.cs @@ -1,9 +1,14 @@ -namespace Lumina.Contracts.Responses.FileManagement; +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.FileManagement; /// /// Represents a response containing the result of splitting a file system path. /// /// The returned path segments. +[DebuggerDisplay("{PathSegments}")] public record SplitPathResponse( string[] PathSegments ); \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/PathController.cs b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/PathController.cs index 4bf7ab83..26282297 100644 --- a/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/PathController.cs +++ b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/PathController.cs @@ -50,6 +50,29 @@ public class PathController : ApiController return result.Match(result => Ok(result), errors => Problem(errors)); } + /// + /// Gets the path separator character of the file system. + /// + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-path-separator")] + public async Task GetPathSeparator(CancellationToken cancellationToken) + { + PathSeparatorResponse result = await _mediator.Send(new GetPathSeparatorQuery(), cancellationToken).ConfigureAwait(false); + return Ok(result); + } + + /// + /// Gets the path separator character of the file system. + /// + /// The path for which to get the parent path. + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-path-parent")] + public async Task GetPathParent([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken) + { + ErrorOr> result = await _mediator.Send(new GetPathParentQuery(path), cancellationToken).ConfigureAwait(false); + return result.Match(result => Ok(result), errors => Problem(errors)); + } + /// /// Combines with . /// @@ -63,17 +86,6 @@ public class PathController : ApiController return result.Match(result => Ok(result), errors => Problem(errors)); } - /// - /// Gets the path separator character of the file system. - /// - /// Cancellation token that can be used to stop the execution. - [HttpGet("get-path-separator")] - public async Task GetPathSeparator(CancellationToken cancellationToken) - { - PathSeparatorResponse result = await _mediator.Send(new GetPathSeparatorQuery(), cancellationToken).ConfigureAwait(false); - return Ok(result); - } - /// /// Gets the path components of . /// @@ -85,5 +97,17 @@ public class PathController : ApiController ErrorOr> result = await _mediator.Send(new SplitPathCommand(path), cancellationToken).ConfigureAwait(false); return result.Match(result => Ok(result), errors => Problem(errors)); } + + /// + /// Validates the validity of . + /// + /// The path to be validated. + /// Cancellation token that can be used to stop the execution. + [HttpGet("validate")] + public async Task ValidatePath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken) + { + PathValidResponse result = await _mediator.Send(new ValidatePathQuery(path), cancellationToken).ConfigureAwait(false); + return Ok(result); + } #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTypeModel.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTypeModel.cs index 8fe57906..c668f12e 100644 --- a/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTypeModel.cs +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTypeModel.cs @@ -7,7 +7,7 @@ namespace Lumina.Presentation.Web.Common.Models.FileManagement; /// /// Model containing the file system platform type. -/// +/// ` [DebuggerDisplay("{PlatformType}")] public class FileSystemTypeModel { diff --git a/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathValidModel.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathValidModel.cs new file mode 100644 index 00000000..6cae38df --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathValidModel.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.FileManagement; + +/// +/// Represents a response to the inquiry about the validity of a file system path. +/// +/// Whether a file system path is valid or not. +[DebuggerDisplay("{IsValid}")] +public record PathValidModel( + bool IsValid +); \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor index 542c4efa..c6de661f 100644 --- a/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor +++ b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor @@ -1,40 +1,104 @@ -@using Lumina.Presentation.Web.Common.Models.UI +@using Lumina.Presentation.Web.Common.Api +@using Lumina.Presentation.Web.Common.Enums.FileSystem +@using Lumina.Presentation.Web.Common.Exceptions +@using Lumina.Presentation.Web.Common.Models.Common +@using Lumina.Presentation.Web.Common.Models.FileManagement +@using Lumina.Presentation.Web.Common.Models.UI +@using Microsoft.AspNetCore.Components + +@inject IJSRuntime JSRuntime +@inject IApiHttpClient _apiHttpClient
-
-
- Back - Forward - Up one level +
+ + -
- -
- Favorite directory - New Directory + + +
+
- +
+ @foreach (FileSystemTreeNodeModel node in treeViewRootNodes) + { + + } +
+
- +
Cancel @@ -51,12 +115,205 @@ Confirm *@
+ +@if (showPathSegmentDowpDown && expandedPathSegmentIndex.HasValue && pathSegmentsSubdirectoriesCache.ContainsKey(expandedPathSegmentIndex.Value)) +{ + +} @code { - private ComboboxItem? selectedValue; - private string savedPath = string.Empty; + [Parameter] + public string? Path { get; set; } - private void HandleNodeSelected(string path) + public EventCallback OnNodeSelected { get; set; } + + private List treeViewRootNodes = []; + private FileSystemTypeModel fileSystemType = null!; + private ComboboxItem? selectedValue; + private PathSegmentModel[]? pathSegments; + private string pathSeparator = "/"; + private string? selectedNodePath; + private string? _path; + private bool showPathSegmentDowpDown; + private int? expandedPathSegmentIndex; + private Dictionary> pathSegmentsSubdirectoriesCache = []; + + + /// + /// Initializes the component. + /// + protected override async Task OnInitializedAsync() { + fileSystemType = await _apiHttpClient.GetAsync("file-system/get-type").ConfigureAwait(false); + // ask the API server for the system path separator + PathSeparatorModel apiPathSeparator = await _apiHttpClient.GetAsync("path/get-path-separator").ConfigureAwait(false); + pathSeparator = apiPathSeparator.Separator; // TODO: handle error + + // treeview + // on Windows, ask the list of drives + if (fileSystemType?.PlatformType == PlatformType.Windows) + { + List drives = await _apiHttpClient.GetAsync>("drives/get-drives").ConfigureAwait(false); + treeViewRootNodes.AddRange(drives); + } + else + { + // on UNIX, just add the root "/" + treeViewRootNodes.Add(new FileSystemTreeNodeModel() + { + Path = pathSeparator!, + IsExpanded = true, + ItemType = FileSystemItemType.Root, + Name = pathSeparator! + }); + } + if (Path is not null) + { + var isPathValidResponse = await _apiHttpClient.GetAsync($"path/validate?path={Uri.EscapeDataString(Path)}").ConfigureAwait(false); + if (!isPathValidResponse.IsValid) + { + // TODO: display error message to user + Console.WriteLine("specified path is not valid!"); + } + else + { + // if there was an initial path saved from a previous session, load the full tree up to that initial path + // ask the whole tree for the saved path + List initialTree = await _apiHttpClient.GetAsync>($"directories/get-directory-tree?path={Uri.EscapeDataString(Path!)}").ConfigureAwait(false); + if (initialTree is not null && initialTree.Count > 0) + { + pathSegments = await _apiHttpClient.GetAsync($"path/split?path={Uri.EscapeDataString(Path!)}").ConfigureAwait(false); + StateHasChanged(); + // 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 + PathSegmentModel pathRoot = await _apiHttpClient.GetAsync($"path/get-path-root?path={Uri.EscapeDataString(Path!)}").ConfigureAwait(false); + if (fileSystemType?.PlatformType == PlatformType.Windows) + { + FileSystemTreeNodeModel? driveNode = treeViewRootNodes.FirstOrDefault(drive => drive.Path.Equals(pathRoot.Path, StringComparison.OrdinalIgnoreCase)); + // if a drive was matched, make the retrieved tree a child of it + if (driveNode is not null) + { + int index = treeViewRootNodes.IndexOf(driveNode); + treeViewRootNodes[index] = initialTree[0]; + } + } + else + treeViewRootNodes[0] = initialTree[0]; + } + } + } + await JSRuntime.InvokeVoidAsync("makeAddressBarHorizontallyScrollable").ConfigureAwait(false); + } + + /// + /// Expands or collapses a node in the tree view. + /// + /// The node to expand or collapse. + private async Task ExpandNode(FileSystemTreeNodeModel node) + { + if (!node.IsExpanded && !node.ChildrenLoaded) + { + node.Children = new List(); + node.IsExpanded = true; + StateHasChanged(); + try + { + await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"directories/get-directories?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false)) + { + if (childNode is not null) + { + node.Children.Add(childNode); + StateHasChanged(); + } + } + await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"files/get-files?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false)) + { + if (childNode is not null) + { + node.Children.Add(childNode); + StateHasChanged(); + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error expanding node: {ex.Message}"); // TODO: display to the user when notification system is implemented + } + finally + { + node.ChildrenLoaded = true; + } + } + else + node.IsExpanded = !node.IsExpanded; + StateHasChanged(); + } + + /// + /// Handles the selection of a node in the tree view. + /// + /// The path of the selected node. + private async Task HandleNodeSelected(string path) + { + selectedNodePath = path; Console.WriteLine($"Selected node: {path}"); + await OnNodeSelected.InvokeAsync(path).ConfigureAwait(false); + } + + /// + /// Handles the change event. + /// + /// The event arguments. + private async Task OnNavigatorPathSegmentCheckChangeHandler(ChangeEventArgs e, int toggledIndex) + { + await JSRuntime.InvokeVoidAsync("uncheckAllExcept", $"segment-toggle-{toggledIndex}").ConfigureAwait(false); + // check if the checkbox is checked + bool isChecked = (bool)e.Value!; + showPathSegmentDowpDown = isChecked; + expandedPathSegmentIndex = null; + // if it's checked, get the subdirectories for the toggled path segment + if (isChecked && pathSegments?.Length > 0) + { + // initialize the path with the first segment + string concatenatedPath = pathSegments[0].Path; + // concatenate only up to the toggled index + for (int i = 1; i <= toggledIndex; i++) + concatenatedPath = $"{(concatenatedPath != pathSeparator ? concatenatedPath : string.Empty)}{pathSeparator}{pathSegments[i].Path}"; + string parentConcatenatedPath = concatenatedPath; + try + { + if (concatenatedPath != pathSeparator) // on UNIX, dont get the parent, if we are at root path + { + List parentLocation = await _apiHttpClient.GetAsync>($"path/get-path-parent?path={Uri.EscapeDataString(concatenatedPath)}").ConfigureAwait(false); + parentConcatenatedPath = parentLocation[0].Path; + for (int i = 1; i < parentLocation.Count; i++) + parentConcatenatedPath = $"{(parentConcatenatedPath != pathSeparator ? parentConcatenatedPath : string.Empty)}{pathSeparator}{pathSegments[i].Path}"; + } + } + catch (ApiException ex) + { + Console.WriteLine(ex.Message); + } + // fetch directories for the expanded path segment + List directories = [ + new() { Path = concatenatedPath, Name = ".", }, // current directory + new() { Path = parentConcatenatedPath, Name = ".." } // parent directory + ]; + // add the rest of the subdirectories of the expanded path node + await foreach (FileSystemTreeNodeModel? directory in _apiHttpClient.GetAsyncEnumerable($"directories/get-directories?path={Uri.EscapeDataString(concatenatedPath)}").ConfigureAwait(false)) + if (directory is not null) + directories.Add(directory); + // store the directories for this segment + pathSegmentsSubdirectoriesCache[toggledIndex] = directories; + expandedPathSegmentIndex = toggledIndex; + StateHasChanged(); + // invoke the javascript function that positions the dropdown underneath the toggled path segment + await JSRuntime.InvokeVoidAsync("updateDropdownPosition", $"path-segment-{toggledIndex}").ConfigureAwait(false); + } + else + StateHasChanged(); } } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor.css b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor.css index ef1747fc..5c095121 100644 --- a/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor.css +++ b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor.css @@ -6,6 +6,7 @@ right: 10%; padding: 10px; border: 1px solid var(--border-color-dialog); + box-shadow: 30px 30px 25px var(--shadow-color); } #directory-browser-content { @@ -64,9 +65,10 @@ } ::deep .directory-browser-content-new-directory { - min-width: 120px; - flex-basis: 120px; + min-width: 35px; + flex-basis: 35px; flex-shrink: 0; + margin-left: 5px; } .navigation-icon { @@ -277,22 +279,386 @@ } } -@media screen and (max-width: 600px) { +/*File System Navigator*/ +#navigator-navigation-controls-container { + width: 195px; + display: flex; + align-items: center; +} + +#navigator-history { + display: flex; + align-items: center; + margin-right: 10px; +} + +#navigator-history, ::deep .navigator-navigate-button, ::deep .navigator-edit-path-button { + flex-shrink: 0; /* don't let them shrink */ +} + + #navigator-history img { + width: 26px; + height: 26px; + margin-left: 5px; + } + +.navigator-icon { + width: 30px; + height: 30px; + cursor: pointer; +} + +#navigator-new-directory-icon { + width: 22px; + height: 22px; +} + +#navigator-navigate-icon, +#navigator-edit-icon { + width: 24px; + height: 24px; +} + +::deep .navigator-navigate-button, ::deep .navigator-edit-path-button { + text-align: end !important; + flex-shrink: 0; +} + +::deep .navigator-navigate-button, +::deep .directory-browser-content-new-directory { + margin: 0px 10px 2px 0px; + flex-shrink: 0; +} + +::deep .directory-browser-content-favorite-directory { + margin: 0px 2px 2px 0px; + flex-shrink: 0; +} + +::deep .navigator-edit-path-button { + margin: 0px 10px 2px 12px; + flex-shrink: 0; +} + +#navigator-address-bar-container { + flex-grow: 1; + display: flex; + height: 28px; + align-items: center; + overflow-x: hidden; + margin-right: 5px; +} + + + #navigator-address-bar-container::-webkit-scrollbar, + #navigator-address-bar-group::-webkit-scrollbar { + display: none; + width: 0; + } + +#navigator-address-bar-container, +#navigator-address-bar-group { + scrollbar-width: none; /* Firefox 64+ */ +} + +#navigator-address-bar-container, +#navigator-address-bar-group { + -ms-overflow-style: none; /* IE 10+ */ +} + + +/* for Webkit browsers like Chrome, Safari */ +#navigator-address-bar::-webkit-scrollbar { + height: 0; +} + +/* for Internet Explorer and Edge */ +#navigator-address-bar { + -ms-overflow-style: none; /*IE and Edge */ +} + + /* for Firefox */ + #navigator-address-bar ::-moz-scrollbar { + width: 0; + display: none; + } + + +#navigator-address-bar-group { + flex-grow: 1; /* let it take the remaining space */ + display: flex; /* use flex for its children */ + flex-wrap: nowrap; + align-items: center; /* vertically center its children */ + height: 30px; + overflow-x: hidden; +} + + +#navigator-view-mode-container { + display: flex; + margin-right: 0px; + align-items: center; + width: 125px; + margin-left: 5px; +} + + #navigator-view-mode-container img { + margin-right: 5px; + width: 16px; + height: 16px; + cursor: pointer; + } + + +::deep .navigator-address-bar-input { + display: none; + width: 100%; +} + + +#navigator-address-bar { + background-color: #23232355; + margin-top: -2px; + padding-left: 2px; + vertical-align: middle; + height: 30px; + flex-grow: 1; + overflow-x: auto; + overflow-y: hidden; + -webkit-overflow-scrolling: touch; +} + + #navigator-address-bar ul { + height: 100%; + list-style-type: none; + padding: 0; + display: flex; + align-items: center; + } + +#navigator-path-segments { + margin: 0px !important; +} + +.navigator-combobox { + position: relative; + font-family: Arial, sans-serif; + padding: 0; + margin: 0; + box-sizing: border-box; +} + +.navigator-toggle-checkbox { + display: none; +} + + .navigator-toggle-checkbox:checked + .navigator-toggle + .navigator-dropdown { + display: block; + } + + .navigator-toggle-checkbox:checked + .navigator-toggle .navigator-arrow { + background-size: 9px 11px; + background-position: 3px -2px; + transform: rotate(90deg); + } + +.navigator-toggle { + display: flex; + align-items: center; + justify-content: space-between; + cursor: pointer; + font-family: Arial, sans-serif; + font-size: 14px; + border-top-left-radius: 2px; + border-top-right-radius: 4px; + border-bottom-right-radius: 3px; + border-bottom-left-radius: 3px; + box-shadow: 0 0 3px rgba(0, 0, 0, 0.5); + color: #6DCBFE; + padding: 3px 8px 3px 8px; + width: 100%; + border: none; + outline: none; + appearance: none; + border-top: #989898 1px solid; + border-bottom: #151515 1px solid; + border-left: #878787 1px solid; + border-right: #202020 1px solid; + background-image: linear-gradient(180deg, #606060, #555555, #4C4C4C, #414141); + background-repeat: repeat; + background-position: 0 0; + background-size: 100%; + user-select: none; + box-sizing: border-box; +} + +.navigator-arrow { /**/ + display: inline-block; + width: 12px; + height: 9px; + background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%22545%20-32.5%2027.5%2065%22%3E%3Cpath%20fill%3D%22%23FFF%22%20d%3D%22M568.254,-7.43524%20568.159,-7.34277%20567.977,-7.52246%20546.559,-28.9417%20525.484,-28.9417%20549.787,-4.63446%20557.439,3.01532%20557.619,3.19629%20550.067,10.7549%20525.758,35.0583%20546.834,35.0583%20568.254,13.6429%20578.792,3.10254%20568.254,-7.43524z%22%2F%3E%3C%2Fsvg%3E'); + background-size: 10px 9px; + background-repeat: no-repeat; + background-position: 3px -0px; + transition: transform 0.3s ease; +} + +.navigator-toggle-checkbox:checked + .navigator-toggle .navigator-arrow { /**/ + transform: rotate(90deg); +} + +.navigator-selected-text { + flex: 1; + text-align: right; + white-space: nowrap; +} + +.navigator-dropdown { + display: none; + position: absolute; + top: 0; + left: 0; + min-width: 150px; + max-width: 800px; + box-sizing: border-box; + background-image: url('../images/ui/metal-plate.png'), linear-gradient(180deg, #505050, #464646, #404040, #363636); + background-repeat: repeat, no-repeat; + background-position: 3px 3px, 0 0; /* offset the metal-plate image by 3 pixels from the top and left */ + background-clip: content-box, border-box; /* clip the metal-plate image to the content box */ + border-top: #989898 1px solid; + border-bottom: #151515 1px solid; + border-left: #878787 1px solid; + border-right: #202020 1px solid; + padding: 3px; + z-index: 999; + max-height: calc(100vh - 100px); /* Subtracting a small value ensures a little space is left on top and bottom */ + overflow-y: auto; +} + .navigator-dropdown.opened { + display: block; + } + +.navigator-option { + display: block; + border-left: 1px solid #232323; + border-right: 1px solid #777777; + border-top: 1px solid #232323; + border-bottom: 1px solid #777777; + color: #FFFFFF; + padding: 5px 10px; + min-width: 100%; + /*width: auto;*/ + box-sizing: border-box; + user-select: none; + cursor: pointer; + text-align: start; + white-space: nowrap; +} + + .navigator-option.first-option { + border-top: 1px solid #232323; + margin-top: -1px; + } + + .navigator-option.last-option { + border-bottom: 1px solid #777777; + } + + .navigator-option.disabled { + color: #AAAAAA; /* Gray color */ + } + + .navigator-option:hover { + background-image: none; + background: linear-gradient(to bottom, #505050, #464646, #404040, #363636); + color: #1D8AF9; + box-shadow: inset 1px 0 0 0 #777777, /* left */ + inset -1px 0 0 0 #232323, /* right */ + inset 0 1px 0 0 #989898, /* top */ + inset 0 -1px 0 0 #151515; /* bottom */ + } + +.navigator-combobox > .shine-effect:first-child { + opacity: 0; + transition: opacity 0.5s; +} + +.navigator-combobox:hover > .shine-effect:first-child { + opacity: 1; +} + +.navigator-combobox > .shine-effect::before, +.navigator-combobox > .shine-effect::after { + content: ""; + position: absolute; + top: -1px; + left: 50%; + transform: translateX(-50%); + opacity: 0; + transition: opacity 0.5s; +} + +.navigator-combobox > .shine-effect::before { + width: 3px; + height: 2px; + border-radius: 5px 5px 0 0; + background-color: #FFFFFF; +} + +.navigator-combobox > .shine-effect::after { + width: 10px; + height: 3px; + border-radius: 5px 5px 0 0; + background-color: #FFFFFF; + filter: blur(3px); +} + +.navigator-combobox:hover > .shine-effect::before, +.navigator-combobox:hover > .shine-effect::after { + opacity: 1; +} + +@media screen and (max-width: 768px) { + #directory-browser-dialog { + top: 0; + bottom: 0; + left: 0; + right: 0; + } + #directory-browser-header { height: auto; } #directory-browser-header-navigation-container { - flex-direction: column; + flex-wrap: wrap; align-items: flex-start; } - #directory-browser-header-address-bar-container { - flex-direction: column; - align-items: stretch; - width: 100%; + #navigator-view-mode-container { + flex: 1; + order: 1; } + #navigator-navigation-controls-container { + flex: 1; + order: 2; + /*text-align: right;*/ + justify-content: flex-end; + width: auto; + } + + #navigator-address-bar-container { + flex-basis: 100%; + order: 3; + } + + #directory-browser-header-address-bar-container { + flex-direction: column; + align-items: stretch; + width: 100%; + } + .directory-browser-header-address-bar-url { width: 100%; margin-bottom: 5px; @@ -314,5 +680,37 @@ ::deep .directory-browser-content-new-directory { min-width: 0; flex-basis: auto; + margin-right: 10px; + margin-left: 0px; + } + + /*File System Navigator*/ + #navigator-view-mode-container { + height: 26px; + margin-left: 11px; + } + + #navigator-address-bar-container { + width: 100%; + flex-basis: 100%; + } + + #navigator-address-bar-group { + margin-left: 10px; + } + + #navigator-toggle-hidden-button { + margin-right: 4px; + } + + #navigator-history { + margin-right: 2px; } } + + +@media screen and (max-width: 399px) { + #directory-browser-dialog { + min-width: 400px + } +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/FileSystemNavigator.razor b/src/Lumina.Presentation.Web/Components/FileSystemNavigator.razor new file mode 100644 index 00000000..f1f619fa --- /dev/null +++ b/src/Lumina.Presentation.Web/Components/FileSystemNavigator.razor @@ -0,0 +1,60 @@ +@using Lumina.Presentation.Web.Common.Models.FileManagement + + + + +@code { + [CascadingParameter(Name = "Path")] private string? Path { get; set; } + [CascadingParameter(Name = "PathSeparator")] private string? PathSeparator { get; set; } + [CascadingParameter(Name = "FileSystemType")] private FileSystemTypeModel? FileSystemType { get; set; } + + /// + /// Method invoked when parameters receive values from the parent. + /// + protected override async Task OnParametersSetAsync() + { + if (Path is not null && PathSeparator is not null && FileSystemType is not null) + { + if (!Path.EndsWith(PathSeparator)) + Path += PathSeparator; + Console.WriteLine("param path:" + Path); + Console.WriteLine("param PathSeparator:" + PathSeparator); + Console.WriteLine("param FileSystemType:" + FileSystemType?.PlatformType); + } + await base.OnParametersSetAsync().ConfigureAwait(false); + } +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/FileSystemNavigator.razor.css b/src/Lumina.Presentation.Web/Components/FileSystemNavigator.razor.css new file mode 100644 index 00000000..26d2635e --- /dev/null +++ b/src/Lumina.Presentation.Web/Components/FileSystemNavigator.razor.css @@ -0,0 +1,154 @@ +#navigator-navigation-controls-container { + width: 180px; + display: flex; + align-items: center; + margin-right: 5px; +} + +#navigator-history { + display: flex; + align-items: center; + margin-right: 10px; +} + +#navigator-history, ::deep .navigator-navigate-button, ::deep .navigator-edit-path-button { + flex-shrink: 0; /* don't let them shrink */ +} + + #navigator-history img { + width: 26px; + height: 26px; + margin-left: 5px; + } + +.navigator-icon { + width: 30px; + height: 30px; + cursor: pointer; +} + +::deep .navigator-navigate-button, ::deep .navigator-edit-path-button { + text-align: end !important; +} + +::deep .navigator-navigate-button { + margin: 0px 10px 2px 0px; +} + +::deep .navigator-edit-path-button { + margin: 0px 10px 2px 12px; +} + +#navigator-address-bar-container { + flex-grow: 1; + display: flex; + height: 28px; + align-items: center; + overflow-x: hidden; +} + + + #navigator-address-bar-container::-webkit-scrollbar, + #navigator-address-bar-group::-webkit-scrollbar { + display: none; + width: 0; + } + +#navigator-address-bar-container, +#navigator-address-bar-group { + scrollbar-width: none; /* Firefox 64+ */ +} + +#navigator-address-bar-container, +#navigator-address-bar-group { + -ms-overflow-style: none; /* IE 10+ */ +} + + +/* for Webkit browsers like Chrome, Safari */ +#navigator-address-bar::-webkit-scrollbar { + height: 0; +} + +/* for Internet Explorer and Edge */ +#navigator-address-bar { + -ms-overflow-style: none; /*IE and Edge */ +} + + /* for Firefox */ + #navigator-address-bar ::-moz-scrollbar { + width: 0; + display: none; + } + + +#navigator-address-bar-group { + flex-grow: 1; /* let it take the remaining space */ + display: flex; /* use flex for its children */ + flex-wrap: nowrap; + align-items: center; /* vertically center its children */ + height: 30px; + overflow-x: hidden; +} + + +#navigator-view-mode-container { + display: flex; + margin-right: 10px; + align-items: center; + width: 125px; +} + + #navigator-view-mode-container img { + margin-right: 5px; + width: 16px; + height: 16px; + cursor: pointer; + } + + +#navigator-address-bar-group, #navigator-view-mode-container { + margin-left: 10px; +} + + +::deep .navigator-address-bar-input { + display: none; + width: 100%; +} + + +#navigator-address-bar { + background-color: #23232355; + margin-top: -2px; + padding-left: 2px; + vertical-align: middle; + height: 30px; + flex-grow: 1; + overflow-x: auto; + overflow-y: hidden; + -webkit-overflow-scrolling: touch; +} + + #navigator-address-bar ul { + height: 100%; + list-style-type: none; + padding: 0; + display: flex; + align-items: center; + } + +#navigator-path-segments { + margin: 0px !important; +} + +@media (max-width: 768px) { + #navigator-view-mode-container { + height: 26px; + } + + #navigator-address-bar-container { + flex-basis: 100%; /* Make navigator-address-bar-container take the full width on wrap, hence pushing it to a new line */ + } + +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/FileSystemTreeView.razor b/src/Lumina.Presentation.Web/Components/FileSystemTreeView.razor deleted file mode 100644 index 03d18902..00000000 --- a/src/Lumina.Presentation.Web/Components/FileSystemTreeView.razor +++ /dev/null @@ -1,142 +0,0 @@ -@using System.Collections.Generic -@using Lumina.Presentation.Web.Common.Api -@using Lumina.Presentation.Web.Common.Enums -@using Lumina.Presentation.Web.Common.Enums.FileSystem -@using Lumina.Presentation.Web.Common.Models.FileManagement - -@inject IApiHttpClient _apiHttpClient - -
- @foreach (FileSystemTreeNodeModel node in RootNodes) - { - - } -
- -@code { - [Parameter] public string? InitialPath { get; set; } - [Parameter] public List RootNodes { get; set; } = new List(); - [Parameter] public EventCallback OnNodeSelected { get; set; } - - private string? SelectedNodePath { get; set; } - private string PathSeparator { get; set; } = "/"; - private FileSystemTypeModel fileSystemType = null!; - - /// - /// Initializes the component. - /// - protected override async Task OnInitializedAsync() - { - fileSystemType = await _apiHttpClient.GetAsync("file-system/get-type").ConfigureAwait(false); - // ask the API server for the system path separator - PathSeparatorModel pathSeparator = await _apiHttpClient.GetAsync("path/get-path-separator").ConfigureAwait(false); - PathSeparator = pathSeparator.Separator; // TODO: handle error - // on Windows, ask the list of drives - if (fileSystemType.PlatformType == PlatformType.Windows) - { - List drives = await _apiHttpClient.GetAsync>("drives/get-drives").ConfigureAwait(false); - RootNodes.AddRange(drives); - } - else - { - // on UNIX, just add the root "/" - RootNodes.Add(new FileSystemTreeNodeModel() - { - Path = pathSeparator.Separator, - IsExpanded = true, - ItemType = FileSystemItemType.Root, - Name = pathSeparator.Separator - }); - } - // if there was an initial path saved from a previous session, load the full tree up to that initial path - if (InitialPath is not null) - { - // ask the whole tree for the saved path - List initialTree = await _apiHttpClient.GetAsync>($"directories/get-directory-tree?path={Uri.EscapeDataString(InitialPath)}").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 - PathSegmentModel pathRoot = await _apiHttpClient.GetAsync($"path/get-path-root?path={Uri.EscapeDataString(InitialPath)}").ConfigureAwait(false); - if (fileSystemType.PlatformType == PlatformType.Windows) - { - FileSystemTreeNodeModel? driveNode = RootNodes.FirstOrDefault(drive => drive.Path.Equals(pathRoot.Path, StringComparison.OrdinalIgnoreCase)); - // if a drive was matched, make the retrieved tree a child of it - if (driveNode is not null) - { - int index = RootNodes.IndexOf(driveNode); - RootNodes[index] = initialTree[0]; - } - } - else - RootNodes[0] = initialTree[0]; - } - } - } - - /// - /// Expands or collapses a node in the tree view. - /// - /// The node to expand or collapse. - private async Task ExpandNode(FileSystemTreeNodeModel node) - { - if (!node.IsExpanded && !node.ChildrenLoaded) - { - node.Children = new List(); - node.IsExpanded = true; - StateHasChanged(); - try - { - await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"directories/get-directories?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false)) - { - if (childNode is not null) - { - node.Children.Add(childNode); - StateHasChanged(); - } - } - await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"files/get-files?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false)) - { - if (childNode is not null) - { - node.Children.Add(childNode); - StateHasChanged(); - } - } - } - catch (Exception ex) - { - Console.Error.WriteLine($"Error expanding node: {ex.Message}"); // TODO: display to the user when notification system is implemented - } - finally - { - node.ChildrenLoaded = true; - } - } - else - node.IsExpanded = !node.IsExpanded; - StateHasChanged(); - } - - /// - /// Retrieves the child nodes for a given path. - /// - /// The path to get child nodes for. - /// A list of representing the child nodes. - private async Task> GetChildNodes(string path) - { - List directories = await _apiHttpClient.GetAsync>($"directories/get-directories?path={Uri.EscapeDataString(path)}").ConfigureAwait(false); - List files = await _apiHttpClient.GetAsync>($"files/get-files?path={Uri.EscapeDataString(path)}").ConfigureAwait(false); - directories.AddRange(files); - return directories; - } - - /// - /// Handles the selection of a node in the tree view. - /// - /// The path of the selected node. - private async Task HandleNodeSelected(string path) - { - SelectedNodePath = path; - await OnNodeSelected.InvokeAsync(path).ConfigureAwait(false); - } -} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/check.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/check.svg new file mode 100644 index 00000000..d7ac594b --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/check.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/details.png b/src/Lumina.Presentation.Web/wwwroot/images/ui/details.png new file mode 100644 index 00000000..ffbc05fc Binary files /dev/null and b/src/Lumina.Presentation.Web/wwwroot/images/ui/details.png differ diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/edit.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/edit.svg new file mode 100644 index 00000000..692370bf --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/edit.svg @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/extra-large-icons.png b/src/Lumina.Presentation.Web/wwwroot/images/ui/extra-large-icons.png new file mode 100644 index 00000000..6c6e45f4 Binary files /dev/null and b/src/Lumina.Presentation.Web/wwwroot/images/ui/extra-large-icons.png differ diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/large-icons.png b/src/Lumina.Presentation.Web/wwwroot/images/ui/large-icons.png new file mode 100644 index 00000000..905539f3 Binary files /dev/null and b/src/Lumina.Presentation.Web/wwwroot/images/ui/large-icons.png differ diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/list.png b/src/Lumina.Presentation.Web/wwwroot/images/ui/list.png new file mode 100644 index 00000000..90f0a1b1 Binary files /dev/null and b/src/Lumina.Presentation.Web/wwwroot/images/ui/list.png differ diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/medium-icons.png b/src/Lumina.Presentation.Web/wwwroot/images/ui/medium-icons.png new file mode 100644 index 00000000..b9a7de13 Binary files /dev/null and b/src/Lumina.Presentation.Web/wwwroot/images/ui/medium-icons.png differ diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/new-directory.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/new-directory.svg new file mode 100644 index 00000000..34103e3f --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/new-directory.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/small-icons.png b/src/Lumina.Presentation.Web/wwwroot/images/ui/small-icons.png new file mode 100644 index 00000000..1572b61c Binary files /dev/null and b/src/Lumina.Presentation.Web/wwwroot/images/ui/small-icons.png differ diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-hidden.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-hidden.svg new file mode 100644 index 00000000..807c69db --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-hidden.svg @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-thumbnails.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-thumbnails.svg new file mode 100644 index 00000000..19df57dd --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-thumbnails.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-tree-view.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-tree-view.svg new file mode 100644 index 00000000..eb9dd857 --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/toggle-tree-view.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Lumina.Presentation.Web/wwwroot/js/site.js b/src/Lumina.Presentation.Web/wwwroot/js/site.js index eb1fe9af..f125563a 100644 --- a/src/Lumina.Presentation.Web/wwwroot/js/site.js +++ b/src/Lumina.Presentation.Web/wwwroot/js/site.js @@ -1,25 +1,110 @@ /** * Adjusts the height of a dropdown identified by `comboboxId` to fit in the available space. - * @param {string} comboboxId The ID of the combobox whose dropdown should be adjusted. + * @param {string} comboboxId The Id of the combobox whose dropdown should be adjusted. */ -function adjustDropdownHeight(comboboxId) { - const combobox = document.getElementById(comboboxId); - const dropdown = combobox.querySelector('.enlightenment-dropdown'); - // get the bounds of the combobox and the height of the viewport - const comboboxRect = combobox.getBoundingClientRect(); - const viewportHeight = window.innerHeight; - // calculate the space available between the combobox and the bottom of the viewport, with a 10px margin - const dropdownTopPosition = comboboxRect.top + comboboxRect.height; - const availableSpace = viewportHeight - dropdownTopPosition - 10; // 10px margin - dropdown.style.maxHeight = `${availableSpace}px`; +function adjustDropdownHeight(comboboxId = null) { + const comboboxes = comboboxId + ? [document.getElementById(comboboxId)] // if comboboxId is provided, use only that element + : document.querySelectorAll('[id^="combobox_"]:not([id^="combobox_checkbox_"])'); // otherwise, select all dropdowns + if (comboboxes) { + comboboxes.forEach(combobox => { + if (!combobox) return; // skip if no element is found + const dropdown = combobox.querySelector('.enlightenment-dropdown'); + if (!dropdown) return; // skip if there's no dropdown inside + // get the bounds of the combobox and the height of the viewport + const comboboxRect = combobox.getBoundingClientRect(); + const viewportHeight = window.innerHeight; + // calculate the space available between the combobox and the bottom of the viewport, with a 10px margin + const dropdownTopPosition = comboboxRect.top + comboboxRect.height; + const availableSpace = viewportHeight - dropdownTopPosition - 10; // 10px margin + // adjust the dropdown height + dropdown.style.maxHeight = `${availableSpace}px`; + }); + } } -window.showDirectoryPicker = async () => { - try { - const dirHandle = await window.showDirectoryPicker().ConfigureAwait(false); - return dirHandle.name; - } catch (err) { - console.error(err); - return null; +/** + * Gets the position and size of an element relative to the viewport. + * + * @param {string} id - The ID of the element to get the offset for. + * @returns {Object} An object with the top, left, width, and height of the element. + */ +function getElementOffset(id) { + const element = document.getElementById(id); + if (element) { + const rect = element.getBoundingClientRect(); + return { + top: rect.top + window.scrollY, + left: rect.left + window.scrollX, + width: rect.width, + height: rect.height + }; } -}; \ No newline at end of file + return { + top: 0, + left: 0, + width: 0, + height: 0 + }; +} + +/** + * Updates the position and height of the dropdown relative to the specified path segment. + * + * @param {string} pathSegmentId - The ID of the path segment element to position the dropdown relative to. + */ +function updateDropdownPosition(pathSegmentId) { + const element = document.getElementById(pathSegmentId); + const dropdown = document.getElementById('navigatorDropdown'); + if (element && dropdown) { + const rect = getElementOffset(pathSegmentId); + dropdown.style.top = `${rect.top + rect.height}px`; + dropdown.style.left = `${rect.left}px`; + // calculate the available height between the dropdown and the bottom of the viewport + const viewportHeight = window.innerHeight; + const availableHeight = viewportHeight - (rect.top + rect.height) - 10; // 10 px margin + // set the dropdown's max height, ensuring it doesn't exceed the available height + dropdown.style.maxHeight = `${availableHeight}px`; + } +} + +/** + * Unchecks all checkboxes except the one with the specified ID. + * + * @param {string} id - The Id of the checkbox to leave checked. + */ +function uncheckAllExcept(id) { + const checkboxes = document.querySelectorAll('.navigator-toggle-checkbox'); + checkboxes.forEach((checkbox) => { + if (checkbox.id !== id) { + checkbox.checked = false; + } + }); +} + +/** + * Enables horizontal scrolling for the address bar using the mouse wheel. + */ +function makeAddressBarHorizontallyScrollable() { + const addressBar = document.getElementById('navigator-address-bar'); + if (addressBar) { + addressBar.addEventListener('wheel', function (event) { + event.preventDefault(); + this.scrollLeft += (event.deltaY > 0 ? 1 : -1) * 80; + }, { passive: false }); + } +} + +/** + * Handles the window resize event. + */ +window.addEventListener('resize', function () { + adjustDropdownHeight(); + // update all dropdowns' positions on resize + const dropdown = document.getElementById('navigatorDropdown'); + if (dropdown) { + const pathSegmentId = dropdown.getAttribute('data-path-segment-id'); + if (pathSegmentId) + updateDropdownPosition(pathSegmentId); + } +}); \ No newline at end of file