From 02f6386f959b206620bff696d00f53e857ca899c Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Wed, 29 Mar 2023 21:34:14 +0200 Subject: [PATCH] Implementing new file manager. Not completed --- Moonlight/App/Helpers/Files/ContextAction.cs | 8 + Moonlight/App/Helpers/Files/FileData.cs | 8 + Moonlight/App/Helpers/Files/IFileAccess.cs | 19 + .../App/Helpers/Files/WingsFileAccess.cs | 118 ++++ .../App/Models/Files/FileContextAction.cs | 8 + .../FileManagerPartials/FileManager.razor | 523 ++--------------- .../FileManagerPartials/FileManager2.razor | 529 ++++++++++++++++++ .../FileManagerPartials/FileView.razor | 223 ++++++++ ...ServerPlugins.razor => ServerAddons.razor} | 2 +- .../ServerControl/ServerFiles.razor | 2 +- .../ServerControl/ServerNavigation.razor | 4 +- Moonlight/Shared/Views/Server/Index.razor | 6 +- Moonlight/Shared/Views/Test.razor | 58 +- Moonlight/resources/lang/de_de.lang | 2 + 14 files changed, 1002 insertions(+), 508 deletions(-) create mode 100644 Moonlight/App/Helpers/Files/ContextAction.cs create mode 100644 Moonlight/App/Helpers/Files/FileData.cs create mode 100644 Moonlight/App/Helpers/Files/IFileAccess.cs create mode 100644 Moonlight/App/Helpers/Files/WingsFileAccess.cs create mode 100644 Moonlight/App/Models/Files/FileContextAction.cs create mode 100644 Moonlight/Shared/Components/FileManagerPartials/FileManager2.razor create mode 100644 Moonlight/Shared/Components/FileManagerPartials/FileView.razor rename Moonlight/Shared/Components/ServerControl/{ServerPlugins.razor => ServerAddons.razor} (83%) diff --git a/Moonlight/App/Helpers/Files/ContextAction.cs b/Moonlight/App/Helpers/Files/ContextAction.cs new file mode 100644 index 00000000..704c4250 --- /dev/null +++ b/Moonlight/App/Helpers/Files/ContextAction.cs @@ -0,0 +1,8 @@ +namespace Moonlight.App.Helpers.Files; + +public class ContextAction +{ + public string Id { get; set; } = ""; + public string Name { get; set; } = ""; + public Action Action { get; set; } +} \ No newline at end of file diff --git a/Moonlight/App/Helpers/Files/FileData.cs b/Moonlight/App/Helpers/Files/FileData.cs new file mode 100644 index 00000000..f0bb75f0 --- /dev/null +++ b/Moonlight/App/Helpers/Files/FileData.cs @@ -0,0 +1,8 @@ +namespace Moonlight.App.Helpers.Files; + +public class FileData +{ + public string Name { get; set; } = ""; + public long Size { get; set; } + public bool IsFile { get; set; } +} \ No newline at end of file diff --git a/Moonlight/App/Helpers/Files/IFileAccess.cs b/Moonlight/App/Helpers/Files/IFileAccess.cs new file mode 100644 index 00000000..62b6ba5c --- /dev/null +++ b/Moonlight/App/Helpers/Files/IFileAccess.cs @@ -0,0 +1,19 @@ +namespace Moonlight.App.Helpers.Files; + +public interface IFileAccess +{ + public Task Ls(); + public Task Cd(string dir); + public Task Up(); + public Task SetDir(string dir); + public Task Read(FileData fileData); + public Task Write(FileData fileData, string content); + public Task Upload(string name, Stream stream, Action? progressUpdated = null); + public Task MkDir(string name); + public Task Pwd(); + public Task DownloadUrl(FileData fileData); + public Task DownloadStream(FileData fileData); + public Task Delete(FileData fileData); + public Task Move(FileData fileData, string newPath); + public Task GetLaunchUrl(); +} \ No newline at end of file diff --git a/Moonlight/App/Helpers/Files/WingsFileAccess.cs b/Moonlight/App/Helpers/Files/WingsFileAccess.cs new file mode 100644 index 00000000..2ddc57c8 --- /dev/null +++ b/Moonlight/App/Helpers/Files/WingsFileAccess.cs @@ -0,0 +1,118 @@ +using Moonlight.App.Database.Entities; +using Moonlight.App.Models.Wings.Resources; + +namespace Moonlight.App.Helpers.Files; + +public class WingsFileAccess : IFileAccess +{ + private readonly WingsApiHelper WingsApiHelper; + private readonly WingsJwtHelper WingsJwtHelper; + private readonly Server Server; + + private string CurrentPath = "/"; + + public WingsFileAccess(WingsApiHelper wingsApiHelper, WingsJwtHelper wingsJwtHelper,Server server) + { + WingsApiHelper = wingsApiHelper; + WingsJwtHelper = wingsJwtHelper; + Server = server; + + if (server.Node == null) + { + throw new ArgumentException("The wings file access server model needs to include the node data"); + } + } + + public async Task Ls() + { + var res = await WingsApiHelper.Get( + Server.Node, + $"api/servers/{Server.Uuid}/files/list-directory?directory={CurrentPath}" + ); + + var x = new List(); + + foreach (var response in res) + { + x.Add(new() + { + Name = response.Name, + Size = response.File ? response.Size : 0, + IsFile = response.File, + }); + } + + return x.ToArray(); + } + + public Task Cd(string dir) + { + var x = Path.Combine(CurrentPath, dir).Replace("\\", "/") + "/"; + x = x.Replace("//", "/"); + CurrentPath = x; + + return Task.CompletedTask; + } + + public Task Up() + { + CurrentPath = Path.GetFullPath(Path.Combine(CurrentPath, "..")).Replace("\\", "/").Replace("C:", ""); + return Task.CompletedTask; + } + + public Task SetDir(string dir) + { + CurrentPath = dir; + return Task.CompletedTask; + } + + public async Task Read(FileData fileData) + { + return await WingsApiHelper.GetRaw(Server.Node,$"api/servers/{Server.Uuid}/files/contents?file={CurrentPath}{fileData.Name}"); + } + + public async Task Write(FileData fileData, string content) + { + await WingsApiHelper.PostRaw(Server.Node,$"api/servers/{Server.Uuid}/files/write?file={CurrentPath}{fileData.Name}", content); + } + + public Task Upload(string name, Stream stream, Action? progressUpdated = null) + { + throw new NotImplementedException(); + } + + public Task MkDir(string name) + { + throw new NotImplementedException(); + } + + public Task Pwd() + { + return Task.FromResult(CurrentPath); + } + + public Task DownloadUrl(FileData fileData) + { + throw new NotImplementedException(); + } + + public Task DownloadStream(FileData fileData) + { + throw new NotImplementedException(); + } + + public Task Delete(FileData fileData) + { + throw new NotImplementedException(); + } + + public Task Move(FileData fileData, string newPath) + { + throw new NotImplementedException(); + } + + public Task GetLaunchUrl() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/Moonlight/App/Models/Files/FileContextAction.cs b/Moonlight/App/Models/Files/FileContextAction.cs new file mode 100644 index 00000000..7570013a --- /dev/null +++ b/Moonlight/App/Models/Files/FileContextAction.cs @@ -0,0 +1,8 @@ +namespace Moonlight.App.Models.Files; + +public class FileContextAction +{ + public string Id { get; set; } + public string Name { get; set; } + public Action Action { get; set; } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/FileManagerPartials/FileManager.razor b/Moonlight/Shared/Components/FileManagerPartials/FileManager.razor index cf8c13b6..64635cd0 100644 --- a/Moonlight/Shared/Components/FileManagerPartials/FileManager.razor +++ b/Moonlight/Shared/Components/FileManagerPartials/FileManager.razor @@ -1,97 +1,20 @@ -@using Moonlight.App.Helpers -@using BlazorContextMenu -@using BlazorDownloadFile +@using Moonlight.App.Helpers.Files +@using Moonlight.App.Helpers @using Logging.Net -@using Moonlight.App.Models.Files -@using Moonlight.App.Services -@using Moonlight.App.Services.Interop -@inject AlertService AlertService -@inject ToastService ToastService -@inject NavigationManager NavigationManager -@inject SmartTranslateService TranslationService -@inject IBlazorDownloadFileService FileService - -
-@if (Editing == null) +@if (Editing) { -
-
-
- - - - - - - -
-
-
- @if (SelectedFiles.Count == 0) - { -
- - - - -
- } - else - { -
-
- - @(SelectedFiles.Count) - - Selected -
- - -
- } -
-
-
+ + +} +else +{ +
@@ -124,406 +47,84 @@
- +
+ +
} -else -{ - if (Loading) - { -
- - Loading - -
- } - else - { - - } -} -
- - - Rename - Move - Archive - Unarchive - Download - Delete - @code { [Parameter] - public IFileAccess FileAccess { get; set; } + public IFileAccess Access { get; set; } - // Data + private bool Editing = false; + private string EditorInitialData = ""; + private string EditorLanguage = ""; + private FileData EditingFile; + private FileEditor Editor; - private List SelectedFiles { get; set; } = new(); - private List Objects { get; set; } = new(); - private string CurrentPath = ""; + private FileView View; + private string CurrentPath = "/"; - // Search - private string SearchValue = ""; - - private string Search + private ContextAction[] Actions = { - get { return SearchValue; } - set + new() { - SearchValue = value; - InvokeAsync(StateHasChanged); + Id = "rename", + Name = "Rename", + Action = (x) => { } } - } + }; - // States - private bool Loading = false; - - // States - Editor - private FileManagerObject? Editing = null; - private string InitialEditorData = ""; - private string Language = "plaintext"; - - // States - File Upload - private bool Uploading = false; - private int Percent = 0; - - protected override async Task OnAfterRenderAsync(bool firstRender) + private async Task OnElementClicked(FileData fileData) { - if (firstRender) + if (fileData.IsFile) { - await RefreshActive(); - } - } + EditorInitialData = await Access.Read(fileData); + EditorLanguage = MonacoTypeHelper.GetEditorType(fileData.Name); + EditingFile = fileData; - private async Task RefreshActive() - { - Loading = true; - await InvokeAsync(StateHasChanged); - - await Refresh(false); - - Loading = false; - await InvokeAsync(StateHasChanged); - } - - private async Task Refresh(bool rerender = true) - { - SelectedFiles.Clear(); - Objects.Clear(); - CurrentPath = await FileAccess.GetCurrentPath(); - - var data = await FileAccess.GetDirectoryContent(); - Objects = data.ToList(); - - if (rerender) + Editing = true; await InvokeAsync(StateHasChanged); - } - private async Task CdPath(string path) - { - await FileAccess.ChangeDirectory(path); - await RefreshActive(); - } - - private async Task SetPath(string path) - { - await FileAccess.SetDirectory(path); - await RefreshActive(); - } - - private async Task OnContextMenuClick(ItemClickEventArgs e) - { - var data = e.Data as FileManagerObject; - - if (data == null) - return; - - switch (e.MenuItem.Id) - { - case "delete": - await FileAccess.Delete(data); - break; - case "download": - if (data.IsFile) - { - try - { - var stream = await FileAccess.GetDownloadStream(data); - await ToastService.Info(TranslationService.Translate("Starting download")); - await FileService.AddBuffer(stream); - await FileService.DownloadBinaryBuffers(data.Name); - } - catch (NotImplementedException) - { - try - { - var url = await FileAccess.GetDownloadUrl(data); - NavigationManager.NavigateTo(url, true); - await ToastService.Info(TranslationService.Translate("Starting download")); - } - catch (Exception exception) - { - await ToastService.Error(TranslationService.Translate("Error starting download")); - Logger.Error("Error downloading file"); - Logger.Error(exception.Message); - } - } - catch (Exception exception) - { - await ToastService.Error(TranslationService.Translate("Error starting download")); - Logger.Error("Error downloading file stream"); - Logger.Error(exception.Message); - } - } - break; - case "rename": - var newName = await AlertService.Text(TranslationService.Translate("Rename"), TranslationService.Translate("Enter a new name"), data.Name); - var path = await FileAccess.GetCurrentPath(); - await FileAccess.Move(data, path + "/" + newName); - break; - } - - await Refresh(false); - } - - private async Task OnFileToggle(ChangeEventArgs obj, FileManagerObject o) - { - if ((bool)obj.Value) - { - if (SelectedFiles.Contains(o)) - return; - - SelectedFiles.Add(o); - await InvokeAsync(StateHasChanged); + return true; } else { - if (!SelectedFiles.Contains(o)) - return; - - SelectedFiles.Remove(o); - await InvokeAsync(StateHasChanged); + return false; } } - private async Task OnAllFileToggle(ChangeEventArgs obj) + public async Task SetPath(string path) { - if ((bool)obj.Value) + await Access.SetDir(path); + CurrentPath = await Access.Pwd(); + + await InvokeAsync(StateHasChanged); + } + + private async void Cancel(bool save = false) + { + if (save) { - foreach (var o in Objects) - { - if (SelectedFiles.Contains(o)) - continue; - - SelectedFiles.Add(o); - } - - await InvokeAsync(StateHasChanged); - } - else - { - foreach (var o in Objects) - { - if (!SelectedFiles.Contains(o)) - continue; - - SelectedFiles.Remove(o); - } - - - await InvokeAsync(StateHasChanged); - } - } - - private async Task CreateFolder() - { - var name = await AlertService.Text(TranslationService.Translate("Create a new folder"), TranslationService.Translate("Enter a name"), ""); - - if (string.IsNullOrEmpty(name)) - return; - - await FileAccess.CreateDirectory(name); - await Refresh(); - } - - private async void SaveFile(string data) - { - if (Editing == null) - return; - - await FileAccess.WriteFile(Editing, data); - Editing = null; - await Refresh(); - } - - private async Task OpenFile(FileManagerObject o) - { - Editing = o; - Loading = true; - await InvokeAsync(StateHasChanged); - - InitialEditorData = await FileAccess.ReadFile(Editing); - Language = MonacoTypeHelper.GetEditorType(Editing.Name); - - Loading = false; - await InvokeAsync(StateHasChanged); - } - - private async void CloseFile() - { - Editing = null; - await InvokeAsync(StateHasChanged); - } - - private async Task Launch() - { - NavigationManager.NavigateTo(await FileAccess.GetLaunchUrl()); - } - - private async Task OnFileChanged(InputFileChangeEventArgs arg) - { - Uploading = true; - await InvokeAsync(StateHasChanged); - - foreach (var browserFile in arg.GetMultipleFiles()) - { - if (browserFile.Size < 1024 * 1024 * 100) - { - Percent = 0; - - try - { - await FileAccess.UploadFile( - browserFile.Name, - browserFile.OpenReadStream(1024 * 1024 * 100), - async (i) => - { - Percent = i; - - Task.Run(() => { InvokeAsync(StateHasChanged); }); - }); - - await Refresh(); - } - catch (Exception e) - { - await ToastService.Error(TranslationService.Translate("An unknown error occured while uploading a file")); - Logger.Error("Error uploading file"); - Logger.Error(e); - } - } - else - { - await ToastService.Error(TranslationService.Translate("The uploaded file should not be bigger than 100MB")); - } + var data = await Editor.GetData(); + await Access.Write(EditingFile, data); } - Uploading = false; + Editing = false; await InvokeAsync(StateHasChanged); + } - await ToastService.Success(TranslationService.Translate("File upload complete")); + private async void OnPathChanged(string path) + { + CurrentPath = path; + await InvokeAsync(StateHasChanged); } } \ No newline at end of file diff --git a/Moonlight/Shared/Components/FileManagerPartials/FileManager2.razor b/Moonlight/Shared/Components/FileManagerPartials/FileManager2.razor new file mode 100644 index 00000000..cf8c13b6 --- /dev/null +++ b/Moonlight/Shared/Components/FileManagerPartials/FileManager2.razor @@ -0,0 +1,529 @@ +@using Moonlight.App.Helpers +@using BlazorContextMenu +@using BlazorDownloadFile +@using Logging.Net +@using Moonlight.App.Models.Files +@using Moonlight.App.Services +@using Moonlight.App.Services.Interop + +@inject AlertService AlertService +@inject ToastService ToastService +@inject NavigationManager NavigationManager +@inject SmartTranslateService TranslationService +@inject IBlazorDownloadFileService FileService + +
+@if (Editing == null) +{ +
+
+
+ + + + + + + +
+
+
+ @if (SelectedFiles.Count == 0) + { +
+ + + + +
+ } + else + { +
+
+ + @(SelectedFiles.Count) + + Selected +
+ + +
+ } +
+
+
+
+
+
+ @{ + var vx = "/"; + } + / + + + + + + @{ + var cp = "/"; + var lp = "/"; + var pathParts = CurrentPath.Replace("\\", "/").Split('/', StringSplitOptions.RemoveEmptyEntries); + foreach (var path in pathParts) + { + lp = cp; + @(path) + + + + + + + cp += path + "/"; + } + } +
+
+
+ +
+} +else +{ + if (Loading) + { +
+ + Loading + +
+ } + else + { + + } +} +
+ + + Rename + Move + Archive + Unarchive + Download + Delete + + +@code +{ + [Parameter] + public IFileAccess FileAccess { get; set; } + + // Data + + private List SelectedFiles { get; set; } = new(); + private List Objects { get; set; } = new(); + private string CurrentPath = ""; + + // Search + private string SearchValue = ""; + + private string Search + { + get { return SearchValue; } + set + { + SearchValue = value; + InvokeAsync(StateHasChanged); + } + } + + // States + private bool Loading = false; + + // States - Editor + private FileManagerObject? Editing = null; + private string InitialEditorData = ""; + private string Language = "plaintext"; + + // States - File Upload + private bool Uploading = false; + private int Percent = 0; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await RefreshActive(); + } + } + + private async Task RefreshActive() + { + Loading = true; + await InvokeAsync(StateHasChanged); + + await Refresh(false); + + Loading = false; + await InvokeAsync(StateHasChanged); + } + + private async Task Refresh(bool rerender = true) + { + SelectedFiles.Clear(); + Objects.Clear(); + CurrentPath = await FileAccess.GetCurrentPath(); + + var data = await FileAccess.GetDirectoryContent(); + Objects = data.ToList(); + + if (rerender) + await InvokeAsync(StateHasChanged); + } + + private async Task CdPath(string path) + { + await FileAccess.ChangeDirectory(path); + await RefreshActive(); + } + + private async Task SetPath(string path) + { + await FileAccess.SetDirectory(path); + await RefreshActive(); + } + + private async Task OnContextMenuClick(ItemClickEventArgs e) + { + var data = e.Data as FileManagerObject; + + if (data == null) + return; + + switch (e.MenuItem.Id) + { + case "delete": + await FileAccess.Delete(data); + break; + case "download": + if (data.IsFile) + { + try + { + var stream = await FileAccess.GetDownloadStream(data); + await ToastService.Info(TranslationService.Translate("Starting download")); + await FileService.AddBuffer(stream); + await FileService.DownloadBinaryBuffers(data.Name); + } + catch (NotImplementedException) + { + try + { + var url = await FileAccess.GetDownloadUrl(data); + NavigationManager.NavigateTo(url, true); + await ToastService.Info(TranslationService.Translate("Starting download")); + } + catch (Exception exception) + { + await ToastService.Error(TranslationService.Translate("Error starting download")); + Logger.Error("Error downloading file"); + Logger.Error(exception.Message); + } + } + catch (Exception exception) + { + await ToastService.Error(TranslationService.Translate("Error starting download")); + Logger.Error("Error downloading file stream"); + Logger.Error(exception.Message); + } + } + break; + case "rename": + var newName = await AlertService.Text(TranslationService.Translate("Rename"), TranslationService.Translate("Enter a new name"), data.Name); + var path = await FileAccess.GetCurrentPath(); + await FileAccess.Move(data, path + "/" + newName); + break; + } + + await Refresh(false); + } + + private async Task OnFileToggle(ChangeEventArgs obj, FileManagerObject o) + { + if ((bool)obj.Value) + { + if (SelectedFiles.Contains(o)) + return; + + SelectedFiles.Add(o); + await InvokeAsync(StateHasChanged); + } + else + { + if (!SelectedFiles.Contains(o)) + return; + + SelectedFiles.Remove(o); + await InvokeAsync(StateHasChanged); + } + } + + private async Task OnAllFileToggle(ChangeEventArgs obj) + { + if ((bool)obj.Value) + { + foreach (var o in Objects) + { + if (SelectedFiles.Contains(o)) + continue; + + SelectedFiles.Add(o); + } + + await InvokeAsync(StateHasChanged); + } + else + { + foreach (var o in Objects) + { + if (!SelectedFiles.Contains(o)) + continue; + + SelectedFiles.Remove(o); + } + + + await InvokeAsync(StateHasChanged); + } + } + + private async Task CreateFolder() + { + var name = await AlertService.Text(TranslationService.Translate("Create a new folder"), TranslationService.Translate("Enter a name"), ""); + + if (string.IsNullOrEmpty(name)) + return; + + await FileAccess.CreateDirectory(name); + await Refresh(); + } + + private async void SaveFile(string data) + { + if (Editing == null) + return; + + await FileAccess.WriteFile(Editing, data); + Editing = null; + await Refresh(); + } + + private async Task OpenFile(FileManagerObject o) + { + Editing = o; + Loading = true; + await InvokeAsync(StateHasChanged); + + InitialEditorData = await FileAccess.ReadFile(Editing); + Language = MonacoTypeHelper.GetEditorType(Editing.Name); + + Loading = false; + await InvokeAsync(StateHasChanged); + } + + private async void CloseFile() + { + Editing = null; + await InvokeAsync(StateHasChanged); + } + + private async Task Launch() + { + NavigationManager.NavigateTo(await FileAccess.GetLaunchUrl()); + } + + private async Task OnFileChanged(InputFileChangeEventArgs arg) + { + Uploading = true; + await InvokeAsync(StateHasChanged); + + foreach (var browserFile in arg.GetMultipleFiles()) + { + if (browserFile.Size < 1024 * 1024 * 100) + { + Percent = 0; + + try + { + await FileAccess.UploadFile( + browserFile.Name, + browserFile.OpenReadStream(1024 * 1024 * 100), + async (i) => + { + Percent = i; + + Task.Run(() => { InvokeAsync(StateHasChanged); }); + }); + + await Refresh(); + } + catch (Exception e) + { + await ToastService.Error(TranslationService.Translate("An unknown error occured while uploading a file")); + Logger.Error("Error uploading file"); + Logger.Error(e); + } + } + else + { + await ToastService.Error(TranslationService.Translate("The uploaded file should not be bigger than 100MB")); + } + } + + Uploading = false; + await InvokeAsync(StateHasChanged); + + await ToastService.Success(TranslationService.Translate("File upload complete")); + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/FileManagerPartials/FileView.razor b/Moonlight/Shared/Components/FileManagerPartials/FileView.razor new file mode 100644 index 00000000..97cdbf3e --- /dev/null +++ b/Moonlight/Shared/Components/FileManagerPartials/FileView.razor @@ -0,0 +1,223 @@ +@using Moonlight.App.Helpers.Files +@using Logging.Net +@using BlazorContextMenu +@using Moonlight.App.Helpers + +
+
+
+
+ + + + + + + + +
+
+
+ + + + + + + + + + @foreach (var file in Data) + { + + + + + + + } + + + +
+
+
+ + + @foreach (var action in ContextActions) + { + + @action.Name + + } + + +@code +{ + [Parameter] + public IFileAccess Access { get; set; } + + [Parameter] + public Func>? OnElementClicked { get; set; } + + [Parameter] + public Action? OnPathChanged { get; set; } + + [Parameter] + public ContextAction[] ContextActions { get; set; } = Array.Empty(); + + private FileData[] Data = Array.Empty(); + + private Dictionary ToggleStatusCache = new(); + private bool AllToggled = false; + + public async Task Refresh() + { + Data = await Access.Ls(); + ToggleStatusCache.Clear(); + + foreach (var fileData in Data) + { + ToggleStatusCache.Add(fileData, false); + } + + await InvokeAsync(StateHasChanged); + } + + private async Task Load(LazyLoader arg) + { + await Refresh(); + } + + private async Task SetToggleState(FileData fileData, bool status) + { + if (ToggleStatusCache.ContainsKey(fileData)) + ToggleStatusCache[fileData] = status; + else + ToggleStatusCache.Add(fileData, status); + + await InvokeAsync(StateHasChanged); + } + + private async Task SetToggleState(bool status) + { + AllToggled = status; + + foreach (var fd in ToggleStatusCache.Keys) + { + ToggleStatusCache[fd] = status; + } + + await InvokeAsync(StateHasChanged); + } + + private async Task OnClicked(FileData fileData) + { + if (OnElementClicked != null) + { + var canceled = await OnElementClicked.Invoke(fileData); + + if (canceled) + return; + } + + if (!fileData.IsFile) + { + await Access.Cd(fileData.Name); + await Refresh(); + OnPathChanged?.Invoke(await Access.Pwd()); + } + } + + private async Task GoUp() + { + await Access.Up(); + await Refresh(); + + OnPathChanged?.Invoke(await Access.Pwd()); + } + + private Task OnContextMenuClick(ItemClickEventArgs eventArgs) + { + var action = ContextActions.FirstOrDefault(x => x.Id == eventArgs.MenuItem.Id); + + if (action != null) + { + action.Action.Invoke((FileData)eventArgs.Data); + } + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/ServerControl/ServerPlugins.razor b/Moonlight/Shared/Components/ServerControl/ServerAddons.razor similarity index 83% rename from Moonlight/Shared/Components/ServerControl/ServerPlugins.razor rename to Moonlight/Shared/Components/ServerControl/ServerAddons.razor index 3168bf98..cb51e2a4 100644 --- a/Moonlight/Shared/Components/ServerControl/ServerPlugins.razor +++ b/Moonlight/Shared/Components/ServerControl/ServerAddons.razor @@ -1,7 +1,7 @@ 
-

Plugins

+

Addons

This feature is currently not available
diff --git a/Moonlight/Shared/Components/ServerControl/ServerFiles.razor b/Moonlight/Shared/Components/ServerControl/ServerFiles.razor index 3fa42fe2..ed0e1d11 100644 --- a/Moonlight/Shared/Components/ServerControl/ServerFiles.razor +++ b/Moonlight/Shared/Components/ServerControl/ServerFiles.razor @@ -9,7 +9,7 @@ @inject IdentityService IdentityService - + @code diff --git a/Moonlight/Shared/Components/ServerControl/ServerNavigation.razor b/Moonlight/Shared/Components/ServerControl/ServerNavigation.razor index 927cfeea..6d8bcc86 100644 --- a/Moonlight/Shared/Components/ServerControl/ServerNavigation.razor +++ b/Moonlight/Shared/Components/ServerControl/ServerNavigation.razor @@ -134,10 +134,10 @@ diff --git a/Moonlight/Shared/Views/Server/Index.razor b/Moonlight/Shared/Views/Server/Index.razor index 3c101178..94efbf46 100644 --- a/Moonlight/Shared/Views/Server/Index.razor +++ b/Moonlight/Shared/Views/Server/Index.razor @@ -96,8 +96,8 @@ case "network": break; - case "plugins": - + case "addons": + break; case "settings": @@ -185,7 +185,7 @@ .Include(x => x.Owner) .First(x => x.Uuid == uuid); - if (CurrentServer.Owner.Id != User!.Id) + if (CurrentServer.Owner.Id != User!.Id && User.Admin) CurrentServer = null; } catch (Exception) diff --git a/Moonlight/Shared/Views/Test.razor b/Moonlight/Shared/Views/Test.razor index 948e8c30..ce2ede87 100644 --- a/Moonlight/Shared/Views/Test.razor +++ b/Moonlight/Shared/Views/Test.razor @@ -1,55 +1,33 @@ @page "/test" -@using Moonlight.App.Services.Interop -@using Moonlight.App.Database.Entities -@using Moonlight.App.Repositories.Domains -@inject ToastService ToastService -@inject SharedDomainRepository SharedDomainRepository +@using Moonlight.Shared.Components.FileManagerPartials +@using Moonlight.App.Repositories.Servers +@using Moonlight.App.Helpers.Files +@using Microsoft.EntityFrameworkCore +@using Moonlight.App.Helpers + +@inject ServerRepository ServerRepository +@inject WingsApiHelper WingsApiHelper +@inject WingsJwtHelper WingsJwtHelper - -
- - -
-
- - - -
-
- -
-
+ +
@code { - private App.Database.Entities.Domain Domain = new(); - - private SharedDomain[] SharedDomains; - - private async Task Callback(EditContext obj) - { - Console.WriteLine(Domain.Name); - Console.WriteLine(Domain.SharedDomain.Name); - - await ToastService.Success("SUCCESS"); - } + private IFileAccess FileAccess; private Task Load(LazyLoader arg) { - SharedDomains = SharedDomainRepository + var server = ServerRepository .Get() - .ToArray(); - + .Include(x => x.Node) + .First(); + + FileAccess = new WingsFileAccess(WingsApiHelper, WingsJwtHelper, server); + return Task.CompletedTask; } } \ No newline at end of file diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 1a6ac108..6bb3356e 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -409,3 +409,5 @@ Street and house number requered;Street and house number requered Max lenght reached;Max lenght reached Server not found;Server not found A server with that id cannot be found or you have no access for this server;A server with that id cannot be found or you have no access for this server +Addons;Addons +Go up;Go up