diff --git a/Oqtane.Client/Modules/Admin/Files/Add.razor b/Oqtane.Client/Modules/Admin/Files/Add.razor index a01b9b1c..653f5cf3 100644 --- a/Oqtane.Client/Modules/Admin/Files/Add.razor +++ b/Oqtane.Client/Modules/Admin/Files/Add.razor @@ -12,7 +12,7 @@ - + diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor index a63784bc..db9186bd 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor @@ -35,7 +35,7 @@ - + diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index e4bae61e..3f3425f6 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -39,7 +39,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -185,7 +185,7 @@ - + @@ -193,7 +193,7 @@ - + diff --git a/Oqtane.Client/Modules/Admin/Themes/Add.razor b/Oqtane.Client/Modules/Admin/Themes/Add.razor index 5ad4f5c6..da47d8a9 100644 --- a/Oqtane.Client/Modules/Admin/Themes/Add.razor +++ b/Oqtane.Client/Modules/Admin/Themes/Add.razor @@ -35,7 +35,7 @@ - + diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor index 6f3ab545..fec53f62 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor @@ -64,7 +64,7 @@ else - + diff --git a/Oqtane.Client/Modules/Admin/Users/Edit.razor b/Oqtane.Client/Modules/Admin/Users/Edit.razor index 3aa30e1b..95449f2d 100644 --- a/Oqtane.Client/Modules/Admin/Users/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Users/Edit.razor @@ -63,7 +63,7 @@ else - + diff --git a/Oqtane.Client/Modules/Controls/FileManager.razor b/Oqtane.Client/Modules/Controls/FileManager.razor index 8dc70ffb..35f04706 100644 --- a/Oqtane.Client/Modules/Controls/FileManager.razor +++ b/Oqtane.Client/Modules/Controls/FileManager.razor @@ -1,5 +1,6 @@ @namespace Oqtane.Modules.Controls -@inherits ModuleBase +@inherits ModuleBase + @attribute [OqtaneIgnore] @inject IFolderService FolderService @inject IFileService FileService @@ -10,33 +11,36 @@
-
- + @if (string.IsNullOrEmpty(Folder)) { - + } - else + @foreach (Folder folder in _folders) { - + if (folder.FolderId == FolderId) + { + + } + else + { + + } } - } - -
- @if (_showfiles) + +
+ } + @if (ShowFiles) {
} - @if (_haseditpermission) + @if (ShowUpload && _haseditpermission) {
- @if (_uploadmultiple) + @if (UploadMultiple) { - + } else { - + } - - @if (_showfiles && GetFileId() != -1) - { - - } + + @if (_showfiles && GetFileId() != -1) + { + + }
- @((MarkupString)_message) } + @((MarkupString) _message)
@if (_image != string.Empty) {
- @((MarkupString)_image) + @((MarkupString) _image)
}
@@ -84,19 +88,19 @@ @code { private string _id; private List _folders; - private int _folderid = -1; private List _files = new List(); - private int _fileid = -1; private bool _showfiles = true; private string _fileinputid = string.Empty; private string _progressinfoid = string.Empty; private string _progressbarid = string.Empty; private string _filter = "*"; - private bool _uploadmultiple = false; private bool _haseditpermission = false; private string _message = string.Empty; private string _image = string.Empty; private string _guid; + private int _folderId = -1; + private bool _uploadMultiple; + private int _fileId; [Parameter] public string Id { get; set; } // optional - for setting the id of the FileManager component for accessibility @@ -105,19 +109,25 @@ public string Folder { get; set; } // optional - for setting a specific folder by default [Parameter] - public string FolderId { get; set; } // optional - for setting a specific folderid by default + public int FolderId { get; set; } = -1; // optional - for setting a specific folderid by default [Parameter] - public string ShowFiles { get; set; } // optional - for indicating whether a list of files should be displayed - default is true + public bool ShowFiles { get; set; } = true; // optional - for indicating whether a list of files should be displayed - default is true [Parameter] - public string FileId { get; set; } // optional - for setting a specific file by default + public bool ShowUpload { get; set; } = true; // optional - for indicating whether a Upload controls should be displayed - default is true + + [Parameter] + public bool ShowFolders { get; set; } = true; // optional - for indicating whether a list of folders should be displayed - default is true + + [Parameter] + public int FileId { get; set; } = -1; // optional - for setting a specific file by default [Parameter] public string Filter { get; set; } // optional - comma delimited list of file types that can be selected or uploaded ie. "jpg,gif" [Parameter] - public string UploadMultiple { get; set; } // optional - enable multiple file uploads - default false + public bool UploadMultiple { get; set; } = false; // optional - enable multiple file uploads - default false protected override async Task OnInitializedAsync() { @@ -129,56 +139,39 @@ if (!string.IsNullOrEmpty(Folder)) { _folders = new List {new Folder {FolderId = -1, Name = Folder}}; - _folderid = -1; + FolderId = -1; } else { _folders = await FolderService.GetFoldersAsync(ModuleState.SiteId); - if (!string.IsNullOrEmpty(FolderId)) - { - _folderid = int.Parse(FolderId); - } } - if (!string.IsNullOrEmpty(FileId)) + if (FileId != -1) { - _fileid = int.Parse(FileId); - if (_fileid != -1) + File file = await FileService.GetFileAsync(FileId); + if (file != null) { - File file = await FileService.GetFileAsync(int.Parse(FileId)); - if (file != null) - { - _folderid = file.FolderId; - } - else - { - _fileid = -1; // file does not exist - } + FolderId = file.FolderId; + } + else + { + FileId = -1; // file does not exist } - await SetImage(); - } - if (!string.IsNullOrEmpty(ShowFiles)) - { - _showfiles = bool.Parse(ShowFiles); } + await SetImage(); if (!string.IsNullOrEmpty(Filter)) { - _filter = "." + Filter.Replace(",",",."); + _filter = "." + Filter.Replace(",", ",."); } await GetFiles(); - // create unique id for component + // create unique id for component _guid = Guid.NewGuid().ToString("N"); _fileinputid = _guid + "FileInput"; _progressinfoid = _guid + "ProgressInfo"; _progressbarid = _guid + "ProgressBar"; - - if (!string.IsNullOrEmpty(UploadMultiple)) - { - _uploadmultiple = bool.Parse(UploadMultiple); - } } private async Task GetFiles() @@ -191,11 +184,11 @@ } else { - Folder folder = _folders.FirstOrDefault(item => item.FolderId == _folderid); + Folder folder = _folders.FirstOrDefault(item => item.FolderId == FolderId); if (folder != null) { - _haseditpermission = UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, folder.Permissions); - _files = await FileService.GetFilesAsync(_folderid); + _haseditpermission = UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, folder.Permissions); + _files = await FileService.GetFilesAsync(FolderId); } else { @@ -222,9 +215,9 @@ _message = string.Empty; try { - _folderid = int.Parse((string)e.Value); + FolderId = int.Parse((string) e.Value); await GetFiles(); - _fileid = -1; + FileId = -1; _image = string.Empty; StateHasChanged(); } @@ -238,7 +231,7 @@ private async Task FileChanged(ChangeEventArgs e) { _message = string.Empty; - _fileid = int.Parse((string)e.Value); + FileId = int.Parse((string) e.Value); await SetImage(); StateHasChanged(); @@ -247,21 +240,21 @@ private async Task SetImage() { _image = string.Empty; - if (_fileid != -1) + if (FileId != -1) { - File file = await FileService.GetFileAsync(_fileid); + File file = await FileService.GetFileAsync(FileId); if (file != null && file.ImageHeight != 0 && file.ImageWidth != 0) { var maxwidth = 200; var maxheight = 200; - var ratioX = (double)maxwidth / (double)file.ImageWidth; - var ratioY = (double)maxheight / (double)file.ImageHeight; + var ratioX = (double) maxwidth / (double) file.ImageWidth; + var ratioY = (double) maxheight / (double) file.ImageHeight; var ratio = ratioX < ratioY ? ratioX : ratioY; - _image = "\"""; + _image = "\"""; } } } @@ -281,7 +274,7 @@ } else { - result = await FileService.UploadFilesAsync(_folderid, upload, _guid); + result = await FileService.UploadFilesAsync(FolderId, upload, _guid); } if (result == string.Empty) @@ -295,7 +288,7 @@ var file = _files.Where(item => item.Name == upload[0]).FirstOrDefault(); if (file != null) { - _fileid = file.FileId; + FileId = file.FileId; await SetImage(); } } @@ -325,21 +318,21 @@ try { - await FileService.DeleteFileAsync(_fileid); - await logger.LogInformation("File Deleted {File}", _fileid); + await FileService.DeleteFileAsync(FileId); + await logger.LogInformation("File Deleted {File}", FileId); _message = "
File Deleted
"; await GetFiles(); - _fileid = -1; + FileId = -1; await SetImage(); StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting File {File} {Error}", _fileid, ex.Message); + await logger.LogError(ex, "Error Deleting File {File} {Error}", FileId, ex.Message); _message = "
Error Deleting File
"; } } - public int GetFileId() => _fileid; + public int GetFileId() => FileId; }