diff --git a/.gitignore b/.gitignore index 33c751ad..8f8f91ba 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ Oqtane.Server/appsettings.json Oqtane.Server/Data/*.mdf Oqtane.Server/Data/*.ldf +/Oqtane.Server/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/LICENSE b/LICENSE index 02a0812b..9a5062f7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 .NET Foundation +Copyright (c) 2018-2020 .NET Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Oqtane.Client/App.razor b/Oqtane.Client/App.razor index 0723e1e7..3d13adff 100644 --- a/Oqtane.Client/App.razor +++ b/Oqtane.Client/App.razor @@ -1,8 +1,8 @@ @inject IInstallationService InstallationService -@if (Initialized) +@if (_initialized) { - @if (!Installed) + @if (!_installed) { } @@ -17,20 +17,21 @@ } @code { - private bool Initialized = false; - private bool Installed = false; + private bool _initialized; + private bool _installed; + private PageState PageState { get; set; } protected override async Task OnParametersSetAsync() { - var response = await InstallationService.IsInstalled(); - Installed = response.Success; - Initialized = true; + var installation = await InstallationService.IsInstalled(); + _installed = installation.Success; + _initialized = true; } - private void ChangeState(PageState pagestate) + private void ChangeState(PageState pageState) { - PageState = pagestate; + PageState = pageState; StateHasChanged(); } } diff --git a/Oqtane.Client/Modules/Admin/Dashboard/Index.razor b/Oqtane.Client/Modules/Admin/Dashboard/Index.razor index a0ad0257..7e3004fb 100644 --- a/Oqtane.Client/Modules/Admin/Dashboard/Index.razor +++ b/Oqtane.Client/Modules/Admin/Dashboard/Index.razor @@ -4,9 +4,9 @@ @inject IUserService UserService
- @foreach (var p in pages) + @foreach (var p in _pages) { - if (UserSecurity.IsAuthorized(PageState.User, "View", p.Permissions)) + if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) { string url = NavigateUrl(p.Path);
@@ -19,13 +19,13 @@
@code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - - List pages; + private List _pages; + + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override void OnInitialized() { - Page admin = PageState.Pages.Where(item => item.Path == "admin").FirstOrDefault(); - pages = PageState.Pages.Where(item => item.ParentId == admin.PageId).ToList(); + var admin = PageState.Pages.FirstOrDefault(item => item.Path == "admin"); + _pages = PageState.Pages.Where(item => item.ParentId == admin?.PageId).ToList(); } } diff --git a/Oqtane.Client/Modules/Admin/Error/Index.razor b/Oqtane.Client/Modules/Admin/Error/Index.razor new file mode 100644 index 00000000..9e0df574 --- /dev/null +++ b/Oqtane.Client/Modules/Admin/Error/Index.razor @@ -0,0 +1,19 @@ +@namespace Oqtane.Modules.Admin.Error +@inherits ModuleBase +@inject IModuleService ModuleService + +@code { + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous; + + protected override async Task OnInitializedAsync() + { + Module module = await ModuleService.GetModuleAsync(ModuleState.ModuleId); + if (UserSecurity.IsAuthorized(PageState.User, Constants.HostRole)) + { + string message = "A Problem Was Encountered Loading Module " + module.ModuleDefinitionName; + AddModuleMessage(message, MessageType.Error); + } + + await logger.LogCritical("Error Loading Module {Module}", module); + } +} diff --git a/Oqtane.Client/Modules/Admin/Files/Add.razor b/Oqtane.Client/Modules/Admin/Files/Add.razor index 26feaf57..9f19370d 100644 --- a/Oqtane.Client/Modules/Admin/Files/Add.razor +++ b/Oqtane.Client/Modules/Admin/Files/Add.razor @@ -1,56 +1,107 @@ @namespace Oqtane.Modules.Admin.Files +@using System.IO @inherits ModuleBase @inject NavigationManager NavigationManager @inject IFileService FileService +@inject IFolderService FolderService - - - - - -
- - - -
- -Cancel + + + + + + + +
+ + + +
+ Cancel +
+ + @if (_folders != null) + { + + + + + + + + + +
+ + + +
+ + + +
+ + Cancel + } +
+
@code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private string url = string.Empty; + private List _folders; + private int _folderId = -1; - FileUpload fileupload; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; - private async Task UploadFile() + protected override async Task OnInitializedAsync() { - string[] files = await fileupload.GetFiles(); - if (files.Length > 0) - { - try - { - ShowProgressIndicator(); + _folders = await FolderService.GetFoldersAsync(ModuleState.SiteId); - string result = await FileService.UploadFilesAsync(PageState.Site.SiteRootPath, files, ""); - if (result == "") - { - await logger.LogInformation("Files Uploaded Successfully"); - AddModuleMessage("Files Uploaded Successfully", MessageType.Success); - } - else - { - await logger.LogError("Upload Failed For {Files}", result.Replace(",",", ")); - AddModuleMessage("Upload Failed For " + result.Replace(",",", ") + ". This Could Be Due To A Network Error Or Because A File Type Is Restricted.", MessageType.Error); - } - } - catch (Exception ex) - { - await logger.LogError(ex, "Upload Failed {Error}", ex.Message); - AddModuleMessage("Upload Failed. " + ex.Message, MessageType.Error); - } - } - else + if (PageState.QueryString.ContainsKey("id")) { - AddModuleMessage("You Must Select Some Files To Upload", MessageType.Warning); + _folderId = int.Parse(PageState.QueryString["id"]); + } + } + + private async Task Download() + { + if (url == string.Empty || _folderId == -1) + { + AddModuleMessage("You Must Enter A Url And Select A Folder", MessageType.Warning); + return; + } + + var filename = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1); + + if (!Constants.UploadableFiles.Split(',') + .Contains(Path.GetExtension(filename).ToLower().Replace(".", ""))) + { + AddModuleMessage("File Could Not Be Downloaded From Url Due To Its File Extension", MessageType.Warning); + return ; + } + + if (!filename.IsPathOrFileValid()) + { + AddModuleMessage("You Must Enter A Url With A Valid File Name", MessageType.Warning); + return; + } + + try + { + await FileService.UploadFileAsync(url, _folderId); + await logger.LogInformation("File Downloaded Successfully From Url {Url}", url); + AddModuleMessage("File Downloaded Successfully From Url", MessageType.Success); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Downloading File From Url {Url} {Error}", url, ex.Message); + AddModuleMessage("Error Downloading File From Url. Please Verify That The Url Is Valid.", MessageType.Error); } } } diff --git a/Oqtane.Client/Modules/Admin/Files/Edit.razor b/Oqtane.Client/Modules/Admin/Files/Edit.razor index 8ad0f1ca..5d42485b 100644 --- a/Oqtane.Client/Modules/Admin/Files/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Files/Edit.razor @@ -3,83 +3,193 @@ @inject IFolderService FolderService @inject NavigationManager NavigationManager - - - - - - - - - -
- - - -
- - - -
- -Cancel -
-
- +@if (_folders != null) +{ + + + + + + + + + + + + +
+ + + +
+ + + +
+ + +
+ @if (!_isSystem) + { + + } + Cancel + @if (!_isSystem && PageState.QueryString.ContainsKey("id")) + { + + } +
+
+ @if (PageState.QueryString.ContainsKey("id")) + { + + } +} @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private List _folders; + private int _folderId = -1; + private string _name; + private int _parentId = -1; + private bool _isSystem; + private string _permissions = string.Empty; + private string _createdBy; + private DateTime _createdOn; + private string _modifiedBy; + private DateTime _modifiedOn; - int FolderId; - string name; - string permissions; - string createdby; - DateTime createdon; - string modifiedby; - DateTime modifiedon; +#pragma warning disable 649 + private PermissionGrid _permissionGrid; +#pragma warning restore 649 - PermissionGrid permissiongrid; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + + public override string Title => "Folder Management"; protected override async Task OnInitializedAsync() { try { - FolderId = Int32.Parse(PageState.QueryString["id"]); - Folder folder = await FolderService.GetFolderAsync(FolderId); - if (folder != null) + _folders = await FolderService.GetFoldersAsync(PageState.Site.SiteId); + + if (PageState.QueryString.ContainsKey("id")) { - name = folder.Name; - permissions = folder.Permissions; - createdby = folder.CreatedBy; - createdon = folder.CreatedOn; - modifiedby = folder.ModifiedBy; - modifiedon = folder.ModifiedOn; + _folderId = Int32.Parse(PageState.QueryString["id"]); + Folder folder = await FolderService.GetFolderAsync(_folderId); + if (folder != null) + { + _parentId = folder.ParentId ?? -1; + _name = folder.Name; + _isSystem = folder.IsSystem; + _permissions = folder.Permissions; + _createdBy = folder.CreatedBy; + _createdOn = folder.CreatedOn; + _modifiedBy = folder.ModifiedBy; + _modifiedOn = folder.ModifiedOn; + } + } + else + { + _parentId = _folders[0].FolderId; + _permissions = string.Empty; } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Folder {FolderId} {Error}", FolderId, ex.Message); - AddModuleMessage("Error Loading Module", MessageType.Error); + await logger.LogError(ex, "Error Loading Folder {FolderId} {Error}", _folderId, ex.Message); + AddModuleMessage("Error Loading Folder", MessageType.Error); } } private async Task SaveFolder() { + if (_name == string.Empty || _parentId == -1) + { + AddModuleMessage("Folders Must Have A Parent And A Name", MessageType.Warning); + return; + } + + if (!_name.IsPathOrFileValid()) + { + AddModuleMessage("Folder Name Not Valid.", MessageType.Warning); + return; + } + try { - Folder folder = await FolderService.GetFolderAsync(FolderId); + Folder folder; + if (_folderId != -1) + { + folder = await FolderService.GetFolderAsync(_folderId); + } + else + { + folder = new Folder(); + } + + folder.SiteId = PageState.Site.SiteId; + + if (_parentId == -1) + { + folder.ParentId = null; + } + else + { + folder.ParentId = _parentId; + } + + folder.Name = _name; + folder.IsSystem = _isSystem; + folder.Permissions = _permissionGrid.GetPermissions(); + + if (_folderId != -1) + { + folder = await FolderService.UpdateFolderAsync(folder); + } + else + { + folder = await FolderService.AddFolderAsync(folder); + } + if (folder != null) { - folder.Permissions = permissiongrid.GetPermissions(); - await FolderService.UpdateFolderAsync(folder); + await FolderService.UpdateFolderOrderAsync(folder.SiteId, folder.FolderId, folder.ParentId); await logger.LogInformation("Folder Saved {Folder}", folder); - NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); + NavigationManager.NavigateTo(NavigateUrl()); + } + else + { + AddModuleMessage("An Error Was Encountered Saving The Folder", MessageType.Error); } } catch (Exception ex) { - await logger.LogError(ex, "Error Saving Folder {FolderId} {Error}", FolderId, ex.Message); + await logger.LogError(ex, "Error Saving Folder {FolderId} {Error}", _folderId, ex.Message); AddModuleMessage("Error Saving Module", MessageType.Error); } } + + private async Task DeleteFolder() + { + try + { + await FolderService.DeleteFolderAsync(_folderId); + await logger.LogInformation("Folder Deleted {Folder}", _folderId); + AddModuleMessage("Folder Deleted", MessageType.Success); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Deleting Folder {Folder} {Error}", _folderId, ex.Message); + AddModuleMessage("Error Deleting Folder", MessageType.Error); + } + } } diff --git a/Oqtane.Client/Modules/Admin/Files/Index.razor b/Oqtane.Client/Modules/Admin/Files/Index.razor index 35269a70..d92e0994 100644 --- a/Oqtane.Client/Modules/Admin/Files/Index.razor +++ b/Oqtane.Client/Modules/Admin/Files/Index.razor @@ -1,40 +1,71 @@ @namespace Oqtane.Modules.Admin.Files @inherits ModuleBase @inject NavigationManager NavigationManager +@inject IFolderService FolderService @inject IFileService FileService -@if (Files == null) +@if (_files != null) { -

Loading...

-} -else -{ - - - + + + + + + +
+ + + + +   +   + +
+
  Name + Modified + Type + Size
- - @context + + @context.Name + @context.ModifiedOn + @context.Extension.ToUpper() File + @(context.Size / 1000) KB
+ @if (_files.Count == 0) + { +
No Files Exist In Selected Folder
+ } } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private List _folders; + private int _folderId = -1; + private List _files; - List Files; - Uri uri; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnParametersSetAsync() { try { - Files = await FileService.GetFilesAsync(PageState.Site.SiteRootPath); - uri = new Uri(NavigationManager.Uri); + _folders = await FolderService.GetFoldersAsync(PageState.Site.SiteId); + + if (_folderId == -1 && _folders.Count > 0) + { + _folderId = _folders[0].FolderId; + await GetFiles(); + } } catch (Exception ex) { @@ -43,19 +74,40 @@ else } } - private async Task DeleteFile(string filename) + private async Task GetFiles() + { + _files = await FileService.GetFilesAsync(_folderId); + } + + private async void FolderChanged(ChangeEventArgs e) { try { - await FileService.DeleteFileAsync(PageState.Site.SiteRootPath, filename); - Files = await FileService.GetFilesAsync(PageState.Site.SiteRootPath); - await logger.LogInformation("File Deleted {File}", filename); - AddModuleMessage("File " + filename + " Deleted", MessageType.Success); + _folderId = int.Parse((string)e.Value); + await GetFiles(); + StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting File {File} {Error}", filename, ex.Message); - AddModuleMessage("Error Deleting File " + filename, MessageType.Error); + await logger.LogError(ex, "Error Loading Files {Error}", ex.Message); + AddModuleMessage("Error Loading Files", MessageType.Error); } } -} \ No newline at end of file + + private async Task DeleteFile(File file) + { + try + { + await FileService.DeleteFileAsync(file.FileId); + await logger.LogInformation("File Deleted {File}", file.Name); + AddModuleMessage("File " + file.Name + " Deleted", MessageType.Success); + await GetFiles(); + StateHasChanged(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Deleting File {File} {Error}", file.Name, ex.Message); + AddModuleMessage("Error Deleting File " + file.Name, MessageType.Error); + } + } +} diff --git a/Oqtane.Client/Modules/Admin/Jobs/Add.razor b/Oqtane.Client/Modules/Admin/Jobs/Add.razor index 29c77c6a..65361e41 100644 --- a/Oqtane.Client/Modules/Admin/Jobs/Add.razor +++ b/Oqtane.Client/Modules/Admin/Jobs/Add.razor @@ -3,115 +3,118 @@ @inject NavigationManager NavigationManager @inject IJobService JobService - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - - -
- - - -
- - - -
- - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + + +
+ + + +
+ + + +
+ + + +
Cancel @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private string _name = string.Empty; + private string _jobType = string.Empty; + private string _isEnabled = "True"; + private string _interval = string.Empty; + private string _frequency = string.Empty; + private string _startDate = string.Empty; + private string _endDate = string.Empty; + private string _retentionHistory = "10"; - string name = ""; - string jobtype = ""; - string isenabled = "True"; - string interval = ""; - string frequency = ""; - string startdate = ""; - string enddate = ""; - string retentionhistory = "10"; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; private async Task SaveJob() { - if (name != "" && !string.IsNullOrEmpty(jobtype) && frequency != "" && interval != "" && retentionhistory != "") + if (_name != string.Empty && !string.IsNullOrEmpty(_jobType) && _frequency != string.Empty && _interval != string.Empty && _retentionHistory != string.Empty) { - Job job = new Job(); - job.Name = name; - job.JobType = jobtype; - job.IsEnabled = Boolean.Parse(isenabled); - job.Frequency = frequency; - job.Interval = int.Parse(interval); - if (startdate == "") + var job = new Job(); + job.Name = _name; + job.JobType = _jobType; + job.IsEnabled = Boolean.Parse(_isEnabled); + job.Frequency = _frequency; + job.Interval = int.Parse(_interval); + + if (_startDate == string.Empty) { job.StartDate = null; } else { - job.StartDate = DateTime.Parse(startdate); + job.StartDate = DateTime.Parse(_startDate); } - if (enddate == "") + + if (_endDate == string.Empty) { job.EndDate = null; } else { - job.EndDate = DateTime.Parse(enddate); + job.EndDate = DateTime.Parse(_endDate); } - job.RetentionHistory = int.Parse(retentionhistory); + + job.RetentionHistory = int.Parse(_retentionHistory); job.IsStarted = false; job.IsExecuting = false; job.NextExecution = null; diff --git a/Oqtane.Client/Modules/Admin/Jobs/Edit.razor b/Oqtane.Client/Modules/Admin/Jobs/Edit.razor index a2651e87..ae1f3d9b 100644 --- a/Oqtane.Client/Modules/Admin/Jobs/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Jobs/Edit.razor @@ -3,141 +3,144 @@ @inject NavigationManager NavigationManager @inject IJobService JobService - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - - -
- - - -
- - - -
- - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + + +
+ + + +
+ + + +
+ + + +
Cancel @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private int _jobId; + private string _name = string.Empty; + private string _jobType = string.Empty; + private string _isEnabled = "True"; + private string _interval = string.Empty; + private string _frequency = string.Empty; + private string _startDate = string.Empty; + private string _endDate = string.Empty; + private string _retentionHistory = string.Empty; - int jobid; - string name = ""; - string jobtype = ""; - string isenabled = "True"; - string interval = ""; - string frequency = ""; - string startdate = ""; - string enddate = ""; - string retentionhistory = ""; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { try { - jobid = Int32.Parse(PageState.QueryString["id"]); - Job job = await JobService.GetJobAsync(jobid); + _jobId = Int32.Parse(PageState.QueryString["id"]); + Job job = await JobService.GetJobAsync(_jobId); if (job != null) { - name = job.Name; - jobtype = job.JobType; - isenabled = job.IsEnabled.ToString(); - interval = job.Interval.ToString(); - frequency = job.Frequency; - startdate = (job.StartDate != null) ? job.StartDate.ToString() : ""; - enddate = (job.EndDate != null) ? job.EndDate.ToString() : ""; - retentionhistory = job.RetentionHistory.ToString(); + _name = job.Name; + _jobType = job.JobType; + _isEnabled = job.IsEnabled.ToString(); + _interval = job.Interval.ToString(); + _frequency = job.Frequency; + _startDate = (job.StartDate != null) ? job.StartDate.ToString() : string.Empty; + _endDate = (job.EndDate != null) ? job.EndDate.ToString() : string.Empty; + _retentionHistory = job.RetentionHistory.ToString(); } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Job {JobId} {Error}", jobid, ex.Message); + await logger.LogError(ex, "Error Loading Job {JobId} {Error}", _jobId, ex.Message); AddModuleMessage("Error Loading Job", MessageType.Error); } } private async Task SaveJob() { - if (name != "" && !string.IsNullOrEmpty(jobtype) && frequency != "" && interval != "" && retentionhistory != "") + if (_name != string.Empty && !string.IsNullOrEmpty(_jobType) && _frequency != string.Empty && _interval != string.Empty && _retentionHistory != string.Empty) { - Job job = await JobService.GetJobAsync(jobid); - job.Name = name; - job.JobType = jobtype; - job.IsEnabled = Boolean.Parse(isenabled); - job.Frequency = frequency; - job.Interval = int.Parse(interval); - if (startdate == "") + var job = await JobService.GetJobAsync(_jobId); + job.Name = _name; + job.JobType = _jobType; + job.IsEnabled = Boolean.Parse(_isEnabled); + job.Frequency = _frequency; + job.Interval = int.Parse(_interval); + + if (_startDate == string.Empty) { job.StartDate = null; } else { - job.StartDate = DateTime.Parse(startdate); + job.StartDate = DateTime.Parse(_startDate); } - if (enddate == "") + + if (_endDate == string.Empty) { job.EndDate = null; } else { - job.EndDate = DateTime.Parse(enddate); + job.EndDate = DateTime.Parse(_endDate); } - job.RetentionHistory = int.Parse(retentionhistory); + + job.RetentionHistory = int.Parse(_retentionHistory); try { diff --git a/Oqtane.Client/Modules/Admin/Jobs/Index.razor b/Oqtane.Client/Modules/Admin/Jobs/Index.razor index e908225d..f15c50df 100644 --- a/Oqtane.Client/Modules/Admin/Jobs/Index.razor +++ b/Oqtane.Client/Modules/Admin/Jobs/Index.razor @@ -2,7 +2,7 @@ @inherits ModuleBase @inject IJobService JobService -@if (Jobs == null) +@if (_jobs == null) {

Loading...

} @@ -13,7 +13,7 @@ else

- +
    @@ -47,25 +47,25 @@ else } @code { + private List _jobs; + public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } - List Jobs; - protected override async Task OnParametersSetAsync() { - Jobs = await JobService.GetJobsAsync(); + _jobs = await JobService.GetJobsAsync(); } - private string DisplayStatus(bool IsEnabled, bool IsExecuting) + private string DisplayStatus(bool isEnabled, bool isExecuting) { - string status = ""; - if (!IsEnabled) + var status = string.Empty; + if (!isEnabled) { status = "Disabled"; } else { - if (IsExecuting) + if (isExecuting) { status = "Executing"; } @@ -79,59 +79,61 @@ else } - private string DisplayFrequency(int Interval, string Frequency) + private string DisplayFrequency(int interval, string frequency) { - string frequency = "Every " + Interval.ToString() + " "; - switch (Frequency) + var result = "Every " + interval.ToString() + " "; + switch (frequency) { case "m": - frequency += "Minute"; + result += "Minute"; break; case "H": - frequency += "Hour"; + result += "Hour"; break; case "d": - frequency += "Day"; + result += "Day"; break; case "M": - frequency += "Month"; + result += "Month"; break; } - if (Interval > 1) + + if (interval > 1) { - frequency += "s"; + result += "s"; } - return frequency; + + return result; } - private async Task DeleteJob(Job Job) + private async Task DeleteJob(Job job) { try { - await JobService.DeleteJobAsync(Job.JobId); - await logger.LogInformation("Job Deleted {Job}", Job); + await JobService.DeleteJobAsync(job.JobId); + await logger.LogInformation("Job Deleted {Job}", job); StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Job {Job} {Error}", Job, ex.Message); + await logger.LogError(ex, "Error Deleting Job {Job} {Error}", job, ex.Message); AddModuleMessage("Error Deleting Job", MessageType.Error); } } - private async Task StartJob(int JobId) + private async Task StartJob(int jobId) { - await JobService.StartJobAsync(JobId); + await JobService.StartJobAsync(jobId); } - private async Task StopJob(int JobId) + private async Task StopJob(int jobId) { - await JobService.StopJobAsync(JobId); + await JobService.StopJobAsync(jobId); } private async Task Refresh() { - Jobs = await JobService.GetJobsAsync(); + _jobs = await JobService.GetJobsAsync(); StateHasChanged(); } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/Jobs/Log.razor b/Oqtane.Client/Modules/Admin/Jobs/Log.razor index d2177e94..9efc1486 100644 --- a/Oqtane.Client/Modules/Admin/Jobs/Log.razor +++ b/Oqtane.Client/Modules/Admin/Jobs/Log.razor @@ -2,13 +2,13 @@ @inherits ModuleBase @inject IJobLogService JobLogService -@if (JobLogs == null) +@if (_jobLogs == null) {

Loading...

} else { - +
Name Status @@ -28,30 +28,32 @@ else } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } - - List JobLogs; + private List _jobLogs; + + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnParametersSetAsync() { - JobLogs = await JobLogService.GetJobLogsAsync(); + _jobLogs = await JobLogService.GetJobLogsAsync(); + if (PageState.QueryString.ContainsKey("id")) { - JobLogs = JobLogs.Where(item => item.JobId == Int32.Parse(PageState.QueryString["id"])).ToList(); + _jobLogs = _jobLogs.Where(item => item.JobId == Int32.Parse(PageState.QueryString["id"])).ToList(); } - JobLogs = JobLogs.OrderByDescending(item => item.JobLogId).ToList(); + + _jobLogs = _jobLogs.OrderByDescending(item => item.JobLogId).ToList(); } - private string DisplayStatus(bool IsExecuting, bool? Succeeded) + private string DisplayStatus(bool isExecuting, bool? succeeded) { - string status = ""; - if (IsExecuting) + var status = string.Empty; + if (isExecuting) { status = "Executing"; } else { - if (Succeeded.Value) + if (succeeded != null && succeeded.Value) { status = "Succeeded"; } @@ -60,6 +62,7 @@ else status = "Failed"; } } + return status; } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/Login/Index.razor b/Oqtane.Client/Modules/Admin/Login/Index.razor index f2ffa020..106ee57f 100644 --- a/Oqtane.Client/Modules/Admin/Login/Index.razor +++ b/Oqtane.Client/Modules/Admin/Login/Index.razor @@ -1,35 +1,35 @@ @namespace Oqtane.Modules.Admin.Login @inherits ModuleBase @inject NavigationManager NavigationManager -@inject IJSRuntime jsRuntime +@inject IJSRuntime JsRuntime @inject IUserService UserService @inject IServiceProvider ServiceProvider -@if (Message != "") +@if (_message != string.Empty) { - + } ... - You are already logged in +
- +
- +
  - +
@@ -41,87 +41,90 @@ @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } } + private string _returnUrl = string.Empty; + private string _message = string.Empty; + private MessageType _type = MessageType.Info; + private string _username = string.Empty; + private string _password = string.Empty; + private bool _remember = false; - string ReturnUrl = ""; - public string Message = ""; - public MessageType Type = MessageType.Info; - public string Username = ""; - public string Password = ""; - public bool Remember = false; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous; protected override async Task OnInitializedAsync() { if (PageState.QueryString.ContainsKey("returnurl")) { - ReturnUrl = PageState.QueryString["returnurl"]; + _returnUrl = PageState.QueryString["returnurl"]; } + if (PageState.QueryString.ContainsKey("name")) { - Username = PageState.QueryString["name"]; + _username = PageState.QueryString["name"]; } + if (PageState.QueryString.ContainsKey("token")) { - User user = new User(); + var user = new User(); user.SiteId = PageState.Site.SiteId; - user.Username = Username; + user.Username = _username; user = await UserService.VerifyEmailAsync(user, PageState.QueryString["token"]); if (user != null) { - Message = "User Account Verified Successfully. You Can Now Login With Your Username And Password Below."; + _message = "User Account Verified Successfully. You Can Now Login With Your Username And Password Below."; } else { - Message = "User Account Could Not Be Verified. Please Contact Your Administrator For Further Instructions."; - Type = MessageType.Warning; + _message = "User Account Could Not Be Verified. Please Contact Your Administrator For Further Instructions."; + _type = MessageType.Warning; } } } private async Task Login() { - var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider)); - if (authstateprovider == null) + if (PageState.Runtime == Runtime.Server) { // server-side Blazor - User user = new User(); + var user = new User(); user.SiteId = PageState.Site.SiteId; - user.Username = Username; - user.Password = Password; + user.Username = _username; + user.Password = _password; user = await UserService.LoginUserAsync(user, false, false); + if (user.IsAuthenticated) { - await logger.LogInformation("Login Successful For Username {Username}", Username); + await logger.LogInformation("Login Successful For Username {Username}", _username); // complete the login on the server so that the cookies are set correctly on SignalR - var interop = new Interop(jsRuntime); + var interop = new Interop(JsRuntime); string antiforgerytoken = await interop.GetElementByName("__RequestVerificationToken"); - var fields = new { __RequestVerificationToken = antiforgerytoken, username = Username, password = Password, remember = Remember, returnurl = ReturnUrl }; - await interop.SubmitForm("/pages/login/", fields); + var fields = new { __RequestVerificationToken = antiforgerytoken, username = _username, password = _password, remember = _remember, returnurl = _returnUrl }; + await interop.SubmitForm($"/{PageState.Alias.AliasId}/pages/login/", fields); } else { - await logger.LogInformation("Login Failed For Username {Username}", Username); + await logger.LogInformation("Login Failed For Username {Username}", _username); AddModuleMessage("Login Failed. Please Remember That Passwords Are Case Sensitive And User Accounts Require Email Verification When They Initially Created.", MessageType.Error); } } else { // client-side Blazor - User user = new User(); + var user = new User(); user.SiteId = PageState.Site.SiteId; - user.Username = Username; - user.Password = Password; - user = await UserService.LoginUserAsync(user, true, Remember); + user.Username = _username; + user.Password = _password; + user = await UserService.LoginUserAsync(user, true, _remember); if (user.IsAuthenticated) { - await logger.LogInformation("Login Successful For Username {Username}", Username); + await logger.LogInformation("Login Successful For Username {Username}", _username); + var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider)); authstateprovider.NotifyAuthenticationChanged(); - NavigationManager.NavigateTo(NavigateUrl(ReturnUrl, Reload.Site)); + NavigationManager.NavigateTo(NavigateUrl(_returnUrl, "reload")); } else { - await logger.LogInformation("Login Failed For Username {Username}", Username); + await logger.LogInformation("Login Failed For Username {Username}", _username); AddModuleMessage("Login Failed. Please Remember That Passwords Are Case Sensitive And User Accounts Require Verification When They Are Initially Created So You May Wish To Check Your Email.", MessageType.Error); } } @@ -129,29 +132,30 @@ private void Cancel() { - NavigationManager.NavigateTo(ReturnUrl); + NavigationManager.NavigateTo(_returnUrl); } private async Task Forgot() { - if (Username != "") + if (_username != string.Empty) { - User user = await UserService.GetUserAsync(Username, PageState.Site.SiteId); + var user = await UserService.GetUserAsync(_username, PageState.Site.SiteId); if (user != null) { await UserService.ForgotPasswordAsync(user); - Message = "Please Check The Email Address Associated To Your User Account For A Password Reset Notification"; + _message = "Please Check The Email Address Associated To Your User Account For A Password Reset Notification"; } else { - Message = "User Does Not Exist"; - Type = MessageType.Warning; + _message = "User Does Not Exist"; + _type = MessageType.Warning; } } else { - Message = "Please Enter The Username Related To Your Account And Then Select The Forgot Password Option Again"; + _message = "Please Enter The Username Related To Your Account And Then Select The Forgot Password Option Again"; } + StateHasChanged(); } - } +} diff --git a/Oqtane.Client/Modules/Admin/Logs/Detail.razor b/Oqtane.Client/Modules/Admin/Logs/Detail.razor index 28aa59a8..1baac265 100644 --- a/Oqtane.Client/Modules/Admin/Logs/Detail.razor +++ b/Oqtane.Client/Modules/Admin/Logs/Detail.razor @@ -1,4 +1,5 @@ @namespace Oqtane.Modules.Admin.Logs +@using System.Globalization @inherits ModuleBase @inject NavigationManager NavigationManager @inject ILogService LogService @@ -9,198 +10,202 @@ - @if (pagename != "") + @if (_pageName != string.Empty) { } - @if (moduletitle != "") + @if (_moduleTitle != string.Empty) { } - @if (username != "") + @if (_username != string.Empty) { } - @if (!string.IsNullOrEmpty(exception)) + @if (!string.IsNullOrEmpty(_exception)) { }
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
- + -
- + -
- + -
- + - +
Cancel @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private int _logId; + private string _logDate = string.Empty; + private string _level = string.Empty; + private string _feature = string.Empty; + private string _function = string.Empty; + private string _category = string.Empty; + private string _pageName = string.Empty; + private string _moduleTitle = string.Empty; + private string _username = string.Empty; + private string _url = string.Empty; + private string _template = string.Empty; + private string _message = string.Empty; + private string _exception = string.Empty; + private string _properties = string.Empty; + private string _server = string.Empty; - int logid; - string logdate = ""; - string level = ""; - string feature = ""; - string function = ""; - string category = ""; - string pagename = ""; - string moduletitle = ""; - string username = ""; - string url = ""; - string template = ""; - string message = ""; - string exception = ""; - string properties = ""; - string server = ""; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { try { - logid = Int32.Parse(PageState.QueryString["id"]); - Log log = await LogService.GetLogAsync(logid); + _logId = Int32.Parse(PageState.QueryString["id"]); + var log = await LogService.GetLogAsync(_logId); if (log != null) { - logdate = log.LogDate.ToString(); - level = log.Level; - feature = log.Feature; - function = log.Function; - category = log.Category; + _logDate = log.LogDate.ToString(CultureInfo.CurrentCulture); + _level = log.Level; + _feature = log.Feature; + _function = log.Function; + _category = log.Category; + if (log.PageId != null) { - Page page = await PageService.GetPageAsync(log.PageId.Value); + var page = await PageService.GetPageAsync(log.PageId.Value); if (page != null) { - pagename = page.Name; + _pageName = page.Name; } } + if (log.PageId != null && log.ModuleId != null) { - PageModule pagemodule = await PageModuleService.GetPageModuleAsync(log.PageId.Value, log.ModuleId.Value); + var pagemodule = await PageModuleService.GetPageModuleAsync(log.PageId.Value, log.ModuleId.Value); if (pagemodule != null) { - moduletitle = pagemodule.Title; + _moduleTitle = pagemodule.Title; } } + if (log.UserId != null) { - User user = await UserService.GetUserAsync(log.UserId.Value, PageState.Site.SiteId); + var user = await UserService.GetUserAsync(log.UserId.Value, PageState.Site.SiteId); if (user != null) { - username = user.Username; + _username = user.Username; } } - url = log.Url; - template = log.MessageTemplate; - message = log.Message; - exception = log.Exception; - properties = log.Properties; - server = log.Server; + + _url = log.Url; + _template = log.MessageTemplate; + _message = log.Message; + _exception = log.Exception; + _properties = log.Properties; + _server = log.Server; } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Log {LogId} {Error}", logid, ex.Message); + await logger.LogError(ex, "Error Loading Log {LogId} {Error}", _logId, ex.Message); AddModuleMessage("Error Loading Log", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/Logs/Index.razor b/Oqtane.Client/Modules/Admin/Logs/Index.razor index 6bb72e99..730c6d13 100644 --- a/Oqtane.Client/Modules/Admin/Logs/Index.razor +++ b/Oqtane.Client/Modules/Admin/Logs/Index.razor @@ -2,72 +2,81 @@ @inherits ModuleBase @inject ILogService LogService -@if (Logs == null) +@if (_logs == null) {

Loading...

} else { -
- - - - - - -
- @if (Logs.Any()) + + + + + + +
+ + + + + + + + +
+ + @if (_logs.Any()) { - -
-   - Date - Level - Feature - Function -
- - - @context.LogDate - @context.Level - @context.Feature - @context.Function - -
+ +
+   + Date + Level + Feature + Function +
+ + + @context.LogDate + @context.Level + @context.Feature + @context.Function + +
} else { -

No Logs Match The Criteria Specified

+

No Logs Match The Criteria Specified

} } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private string _level = "-"; + private string _function = "-"; + private string _rows = "10"; + private List _logs; - string level = "-"; - string function = "-"; - string rows = "10"; - List Logs; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { @@ -86,7 +95,7 @@ else { try { - level = (string)e.Value; + _level = (string)e.Value; await GetLogs(); StateHasChanged(); } @@ -101,7 +110,7 @@ else { try { - function = (string)e.Value; + _function = (string)e.Value; await GetLogs(); StateHasChanged(); } @@ -117,7 +126,7 @@ else { try { - rows = (string)e.Value; + _rows = (string)e.Value; await GetLogs(); StateHasChanged(); } @@ -130,12 +139,12 @@ else private async Task GetLogs() { - Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), ((function == "-") ? "" : function), int.Parse(rows)); + _logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((_level == "-") ? string.Empty : _level), ((_function == "-") ? string.Empty : _function), int.Parse(_rows)); } private string GetClass(string function) { - string classname = ""; + string classname = string.Empty; switch (function) { case "Create": @@ -154,9 +163,9 @@ else classname = "table-secondary"; break; default: - classname = ""; + classname = string.Empty; break; } return classname; } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/ModuleCreator/Index.razor b/Oqtane.Client/Modules/Admin/ModuleCreator/Index.razor new file mode 100644 index 00000000..9d26615a --- /dev/null +++ b/Oqtane.Client/Modules/Admin/ModuleCreator/Index.razor @@ -0,0 +1,124 @@ +@namespace Oqtane.Modules.Admin.ModuleCreator +@inherits ModuleBase +@inject NavigationManager NavigationManager +@inject IModuleDefinitionService ModuleDefinitionService +@inject IModuleService ModuleService +@inject ISystemService SystemService + + + + + + + + + + + + + + + + + + + @if (!string.IsNullOrEmpty(_location)) + { + + + + + } +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +@code { + private string _owner = string.Empty; + private string _module = string.Empty; + private string _description = string.Empty; + private string _template = "-"; + private string _location = string.Empty; + + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; + + protected override void OnInitialized() + { + AddModuleMessage("Please Note That Once You Select The Create Module Button The Application Must Restart In Order To Complete The Process. If You Create An External Module You Will Need To Compile The Source Code In Order To Make It Functional.", MessageType.Info); + } + + private async Task CreateModule() + { + try + { + if (!string.IsNullOrEmpty(_owner) && !string.IsNullOrEmpty(_module) && _template != "-") + { + var moduleDefinition = new ModuleDefinition { Owner = _owner.Replace(" ", ""), Name = _module.Replace(" ", ""), Description = _description, Template = _template }; + await ModuleDefinitionService.CreateModuleDefinitionAsync(moduleDefinition, ModuleState.ModuleId); + } + else + { + AddModuleMessage("You Must Provide An Owner, Module Name, And Template", MessageType.Warning); + } + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Creating Module"); + } + } + + private async void TemplateChanged(ChangeEventArgs e) + { + try + { + _location = string.Empty; + _template = (string)e.Value; + if (_template != "-") + { + Dictionary systeminfo = await SystemService.GetSystemInfoAsync(); + if (systeminfo != null) + { + string[] path = systeminfo["serverpath"].Split('\\'); + if (_template == "internal") + { + _location = string.Join("\\", path, 0, path.Length - 1) + "\\Oqtane.Client\\Modules\\" + _owner + "." + _module + "s"; + } + else + { + _location = string.Join("\\", path, 0, path.Length - 2) + "\\" + _owner + "." + _module + "s"; + } + } + } + StateHasChanged(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Getting System Info {Error}", ex.Message); + AddModuleMessage("Error Getting System Info", MessageType.Error); + } + } +} diff --git a/Oqtane.Client/Modules/Admin/ModuleCreator/ModuleInfo.cs b/Oqtane.Client/Modules/Admin/ModuleCreator/ModuleInfo.cs new file mode 100644 index 00000000..81b82a6d --- /dev/null +++ b/Oqtane.Client/Modules/Admin/ModuleCreator/ModuleInfo.cs @@ -0,0 +1,15 @@ +using Oqtane.Models; + +namespace Oqtane.Modules.Admin.ModuleCreator +{ + public class ModuleInfo : IModule + { + public ModuleDefinition ModuleDefinition => new ModuleDefinition + { + Name = "Module Creator", + Description = "Enables software developers to quickly create modules by automating many of the initial module creation tasks", + Version = "1.0.0", + Categories = "Developer" + }; + } +} diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor index e234650f..db9186bd 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor @@ -5,64 +5,64 @@ @inject IModuleDefinitionService ModuleDefinitionService @inject IPackageService PackageService - - - - - -
- - - -
- - -@if (packages != null) +@if (_packages != null) { -
-

Available Modules

+ + @if (_packages.Count > 0) + { + + + +
+ Name + Version + +
+ + @context.Name + @context.Version + + + + +
+
+ } + + + + + + +
+ + + +
+
+
- -
- Name - Version - -
- - @context.Name - @context.Version - - - - -
-} - -@if (uploaded) -{ + Cancel } -Cancel - @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private List _packages; - bool uploaded = false; - List packages; - FileUpload fileupload; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { try { - List moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId); - packages = await PackageService.GetPackagesAsync("module"); - foreach(Package package in packages.ToArray()) + var moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId); + _packages = await PackageService.GetPackagesAsync("module"); + + foreach (Package package in _packages.ToArray()) { if (moduledefinitions.Exists(item => Utilities.GetTypeName(item.ModuleDefinitionName) == package.PackageId)) { - packages.Remove(package); + _packages.Remove(package); } } } @@ -73,53 +73,12 @@ } } - private async Task UploadFile() - { - string[] files = await fileupload.GetFiles(); - if (files.Length > 0) - { - if (files[0].Contains(".Module.")) - { - try - { - string result = await FileService.UploadFilesAsync("Modules", files, ""); - if (result == "") - { - await logger.LogInformation("Module Uploaded Successfully {Package}", files[0]); - AddModuleMessage("Module Uploaded Successfully. Click Install To Complete Installation.", MessageType.Success); - uploaded = true; - StateHasChanged(); - } - else - { - await logger.LogError("Module Upload Failed For {Package}", files[0]); - AddModuleMessage("Module Upload Failed For " + result.Replace(",",", ") + ". This Could Be Due To A Network Error Or Because A File Type Is Restricted.", MessageType.Error); - } - } - catch (Exception ex) - { - await logger.LogError(ex, "Module Upload Failed For {Package} {Error}", files[0], ex.Message); - AddModuleMessage("Module Upload Failed.", MessageType.Error); - } - } - else - { - await logger.LogError("Invalid Module Package {Package}", files[0]); - AddModuleMessage("Invalid Module Package", MessageType.Error); - } - } - else - { - AddModuleMessage("You Must Select A Module To Upload", MessageType.Warning); - } - } - private async Task InstallModules() { try { await ModuleDefinitionService.InstallModuleDefinitionsAsync(); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { @@ -127,19 +86,18 @@ } } - private async Task DownloadModule(string moduledefinitionname, string version) + private async Task DownloadModule(string packageid, string version) { try { - await PackageService.DownloadPackageAsync(moduledefinitionname, version, "Modules"); - await logger.LogInformation("Module {ModuleDefinitionName} {Version} Downloaded Successfully", moduledefinitionname, version); - AddModuleMessage("Module Downloaded Successfully. Click Install To Complete Installation.", MessageType.Success); - uploaded = true; + await PackageService.DownloadPackageAsync(packageid, version, "Modules"); + await logger.LogInformation("Module {ModuleDefinitionName} {Version} Downloaded Successfully", packageid, version); + AddModuleMessage("Modules Downloaded Successfully. Click Install To Complete Installation.", MessageType.Success); StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Downloading Module {ModuleDefinitionName} {Version}", moduledefinitionname, version); + await logger.LogError(ex, "Error Downloading Module {ModuleDefinitionName} {Version}", packageid, version); AddModuleMessage("Error Downloading Module", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor index 21d90d91..743938bf 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor @@ -3,62 +3,152 @@ @inject IModuleDefinitionService ModuleDefinitionService @inject NavigationManager NavigationManager - - - - - - - - - -
- - - -
- - - -
+ + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+
+
+ + + + + +
+ +
+
+
Cancel -
-
- +

+ @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private int _moduleDefinitionId; + private string _name; + private string _version; + private string _categories; + private string _moduledefinitionname = ""; + private string _description = ""; + private string _owner = ""; + private string _url = ""; + private string _contact = ""; + private string _license = ""; + private string _permissions; + private string _createdby; + private DateTime _createdon; + private string _modifiedby; + private DateTime _modifiedon; - int ModuleDefinitionId; - string name; - string permissions; - string createdby; - DateTime createdon; - string modifiedby; - DateTime modifiedon; +#pragma warning disable 649 + private PermissionGrid _permissionGrid; +#pragma warning restore 649 - PermissionGrid permissiongrid; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() { try { - ModuleDefinitionId = Int32.Parse(PageState.QueryString["id"]); - ModuleDefinition moduledefinition = PageState.ModuleDefinitions.Where(item => item.ModuleDefinitionId == ModuleDefinitionId).FirstOrDefault(); - if (moduledefinition != null) + _moduleDefinitionId = Int32.Parse(PageState.QueryString["id"]); + var moduleDefinition = await ModuleDefinitionService.GetModuleDefinitionAsync(_moduleDefinitionId, ModuleState.SiteId); + if (moduleDefinition != null) { - name = moduledefinition.Name; - permissions = moduledefinition.Permissions; - createdby = moduledefinition.CreatedBy; - createdon = moduledefinition.CreatedOn; - modifiedby = moduledefinition.ModifiedBy; - modifiedon = moduledefinition.ModifiedOn; + _name = moduleDefinition.Name; + _version = moduleDefinition.Version; + _categories = moduleDefinition.Categories; + _moduledefinitionname = moduleDefinition.ModuleDefinitionName; + _description = moduleDefinition.Description; + _owner = moduleDefinition.Owner; + _url = moduleDefinition.Url; + _contact = moduleDefinition.Contact; + _license = moduleDefinition.License; + _permissions = moduleDefinition.Permissions; + _createdby = moduleDefinition.CreatedBy; + _createdon = moduleDefinition.CreatedOn; + _modifiedby = moduleDefinition.ModifiedBy; + _modifiedon = moduleDefinition.ModifiedOn; } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading ModuleDefinition {ModuleDefinitionId} {Error}", ModuleDefinitionId, ex.Message); + await logger.LogError(ex, "Error Loading ModuleDefinition {ModuleDefinitionId} {Error}", _moduleDefinitionId, ex.Message); AddModuleMessage("Error Loading Module", MessageType.Error); } } @@ -67,15 +157,27 @@ { try { - ModuleDefinition moduledefinition = PageState.ModuleDefinitions.Where(item => item.ModuleDefinitionId == ModuleDefinitionId).FirstOrDefault(); - moduledefinition.Permissions = permissiongrid.GetPermissions(); + var moduledefinition = await ModuleDefinitionService.GetModuleDefinitionAsync(_moduleDefinitionId, ModuleState.SiteId); + if (moduledefinition.Name != _name) + { + moduledefinition.Name = _name; + } + if (moduledefinition.Description != _description) + { + moduledefinition.Description = _description; + } + if (moduledefinition.Categories != _categories) + { + moduledefinition.Categories = _categories; + } + moduledefinition.Permissions = _permissionGrid.GetPermissions(); await ModuleDefinitionService.UpdateModuleDefinitionAsync(moduledefinition); await logger.LogInformation("ModuleDefinition Saved {ModuleDefinition}", moduledefinition); - NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); + NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Saving ModuleDefinition {ModuleDefinitionId} {Error}", ModuleDefinitionId, ex.Message); + await logger.LogError(ex, "Error Saving ModuleDefinition {ModuleDefinitionId} {Error}", _moduleDefinitionId, ex.Message); AddModuleMessage("Error Saving Module", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor index 3375eb3d..d348ddb4 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor @@ -4,7 +4,7 @@ @inject IModuleDefinitionService ModuleDefinitionService @inject IPackageService PackageService -@if (moduledefinitions == null) +@if (_moduleDefinitions == null) {

Loading...

} @@ -12,7 +12,7 @@ else { - +
    @@ -41,17 +41,17 @@ else } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private List _moduleDefinitions; + private List _packages; - List moduledefinitions; - List packages; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { try { - moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId); - packages = await PackageService.GetPackagesAsync("module"); + _moduleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId); + _packages = await PackageService.GetPackagesAsync("module"); } catch (Exception ex) { @@ -62,12 +62,13 @@ else private bool UpgradeAvailable(string moduledefinitionname, string version) { - bool upgradeavailable = false; - Package package = packages.Where(item => item.PackageId == Utilities.GetTypeName(moduledefinitionname)).FirstOrDefault(); + var upgradeavailable = false; + var package = _packages.Where(item => item.PackageId == Utilities.GetTypeName(moduledefinitionname)).FirstOrDefault(); if (package != null) { upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(version)) > 0); } + return upgradeavailable; } @@ -78,7 +79,7 @@ else await PackageService.DownloadPackageAsync(moduledefinitionname, version, "Modules"); await ModuleDefinitionService.InstallModuleDefinitionsAsync(); await logger.LogInformation("Module Downloaded {ModuleDefinitionName} {Version}", moduledefinitionname, version); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { @@ -87,18 +88,18 @@ else } } - private async Task DeleteModule(ModuleDefinition ModuleDefinition) + private async Task DeleteModule(ModuleDefinition moduleDefinition) { try { - await ModuleDefinitionService.DeleteModuleDefinitionAsync(ModuleDefinition.ModuleDefinitionId, ModuleDefinition.SiteId); - await logger.LogInformation("Module Deleted {ModuleDefinition}", ModuleDefinition); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + await ModuleDefinitionService.DeleteModuleDefinitionAsync(moduleDefinition.ModuleDefinitionId, moduleDefinition.SiteId); + await logger.LogInformation("Module Deleted {ModuleDefinition}", moduleDefinition); + NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Module {ModuleDefinition} {Error}", ModuleDefinition, ex.Message); + await logger.LogError(ex, "Error Deleting Module {ModuleDefinition} {Error}", moduleDefinition, ex.Message); AddModuleMessage("Error Deleting Module", MessageType.Error); } } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/Modules/Export.razor b/Oqtane.Client/Modules/Admin/Modules/Export.razor index c8368d40..eaa0bc92 100644 --- a/Oqtane.Client/Modules/Admin/Modules/Export.razor +++ b/Oqtane.Client/Modules/Admin/Modules/Export.razor @@ -7,10 +7,10 @@ - + - @@ -20,13 +20,14 @@ @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - public override string Title { get { return "Export Module"; } } + private string _content = string.Empty; + + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + public override string Title => "Export Module"; - string content = ""; private async Task ExportModule() { - content = await ModuleService.ExportModuleAsync(ModuleState.ModuleId); + _content = await ModuleService.ExportModuleAsync(ModuleState.ModuleId); } } diff --git a/Oqtane.Client/Modules/Admin/Modules/Import.razor b/Oqtane.Client/Modules/Admin/Modules/Import.razor index 2db62162..e341ad78 100644 --- a/Oqtane.Client/Modules/Admin/Modules/Import.razor +++ b/Oqtane.Client/Modules/Admin/Modules/Import.razor @@ -7,10 +7,10 @@ - + - @@ -20,20 +20,20 @@ @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - public override string Title { get { return "Import Module"; } } - - string content = ""; + private string _content = string.Empty; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + public override string Title => "Import Module"; private async Task ImportModule() { - if (content != "") + if (_content != string.Empty) { try { - await ModuleService.ImportModuleAsync(ModuleState.ModuleId, content); - NavigationManager.NavigateTo(NavigateUrl(Reload.Page)); + await ModuleService.ImportModuleAsync(ModuleState.ModuleId, _content); + StateHasChanged(); + NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { diff --git a/Oqtane.Client/Modules/Admin/Modules/Settings.razor b/Oqtane.Client/Modules/Admin/Modules/Settings.razor index 3c81ef2a..98e78bdf 100644 --- a/Oqtane.Client/Modules/Admin/Modules/Settings.razor +++ b/Oqtane.Client/Modules/Admin/Modules/Settings.razor @@ -5,117 +5,172 @@ @inject IModuleService ModuleService @inject IPageModuleService PageModuleService - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - -
- -@DynamicComponent - + + + @if (_containers != null) + { + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ } +
+ + @if (_containers != null) + { + + + + +
+ +
+ } +
+ @if (_settingsModuleType != null) + { + + @DynamicComponent + + } +
Cancel - @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } } - public override string Title { get { return "Module Settings"; } } + private Dictionary _containers; + private string _title; + private string _containerType; + private string _allPages = "false"; + private string _permissionNames = ""; + private string _permissions; + private string _pageId; + private PermissionGrid _permissionGrid; + private Type _settingsModuleType; + private string _settingstitle = "Other Settings"; + private object _settings; - Dictionary containers = new Dictionary(); - string title; - string containertype; - string permissionnames = ""; - string permissions; - string pageid; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit; + public override string Title => "Module Settings"; - PermissionGrid permissiongrid; - - RenderFragment DynamicComponent { get; set; } - object settings; + private RenderFragment DynamicComponent { get; set; } protected override async Task OnInitializedAsync() { - title = ModuleState.Title; - containers = ThemeService.GetContainerTypes(await ThemeService.GetThemesAsync()); - containertype = ModuleState.ContainerType; - permissions = ModuleState.Permissions; - permissionnames = PageState.ModuleDefinitions.Find(item => item.ModuleDefinitionName == ModuleState.ModuleDefinitionName).PermissionNames; - pageid = ModuleState.PageId.ToString(); - - DynamicComponent = builder => + _title = ModuleState.Title; + _containers = ThemeService.GetContainerTypes(await ThemeService.GetThemesAsync()); + _containerType = ModuleState.ContainerType; + if (!string.IsNullOrEmpty(PageState.Page.DefaultContainerType) && _containerType == PageState.Page.DefaultContainerType) { - Type moduleType = Type.GetType(ModuleState.ModuleType); - if (moduleType != null) + _containerType = "-"; + } + if (_containerType == PageState.Site.DefaultContainerType) + { + _containerType = "-"; + } + _allPages = ModuleState.AllPages.ToString(); + _permissions = ModuleState.Permissions; + _permissionNames = ModuleState.ModuleDefinition.PermissionNames; + _pageId = ModuleState.PageId.ToString(); + + _settingsModuleType = Type.GetType(ModuleState.ModuleType); + if (_settingsModuleType != null) + { + var moduleobject = Activator.CreateInstance(_settingsModuleType) as IModuleControl; + _settingstitle = moduleobject.Title; + if (string.IsNullOrEmpty(_settingstitle)) { - builder.OpenComponent(0, moduleType); - builder.AddComponentReferenceCapture(1, inst => { settings = Convert.ChangeType(inst, moduleType); }); - builder.CloseComponent(); + _settingstitle = "Other Settings"; } - }; + + DynamicComponent = builder => + { + builder.OpenComponent(0, _settingsModuleType); + builder.AddComponentReferenceCapture(1, inst => { _settings = Convert.ChangeType(inst, _settingsModuleType); }); + builder.CloseComponent(); + }; + } } private async Task SaveModule() { - Module module = ModuleState; - module.Permissions = permissiongrid.GetPermissions(); - await ModuleService.UpdateModuleAsync(module); - - PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); - pagemodule.PageId = int.Parse(pageid); - pagemodule.Title = title; - pagemodule.ContainerType = containertype; + var pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); + pagemodule.PageId = int.Parse(_pageId); + pagemodule.Title = _title; + pagemodule.ContainerType = (_containerType != "-") ? _containerType : string.Empty; + if (!string.IsNullOrEmpty(pagemodule.ContainerType) && pagemodule.ContainerType == PageState.Page.DefaultContainerType) + { + pagemodule.ContainerType = string.Empty; + } + if (!string.IsNullOrEmpty(pagemodule.ContainerType) && pagemodule.ContainerType == PageState.Site.DefaultContainerType) + { + pagemodule.ContainerType = string.Empty; + } await PageModuleService.UpdatePageModuleAsync(pagemodule); await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane); - Type moduleType = Type.GetType(ModuleState.ModuleType); - if (moduleType != null) + var module = ModuleState; + module.AllPages = bool.Parse(_allPages); + module.Permissions = _permissionGrid.GetPermissions(); + await ModuleService.UpdateModuleAsync(module); + + if (_settingsModuleType != null) { - moduleType.GetMethod("UpdateSettings").Invoke(settings, null); // method must be public in settings component + var moduleType = Type.GetType(ModuleState.ModuleType); + if (moduleType != null) + { + moduleType.GetMethod("UpdateSettings")?.Invoke(_settings, null); // method must be public in settings component + } } - NavigationManager.NavigateTo(NavigateUrl(Reload.Page)); + NavigationManager.NavigateTo(NavigateUrl()); } } diff --git a/Oqtane.Client/Modules/Admin/Pages/Add.razor b/Oqtane.Client/Modules/Admin/Pages/Add.razor index fe217df0..8761ff3a 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Add.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Add.razor @@ -4,184 +4,239 @@ @inject IPageService PageService @inject IThemeService ThemeService - - - - - - - - - - - - - - - - + + + + + + + + + + + + + +
- - - -
- - - -
- - - -
- - - - @if (children != null && children.Count > 0 && (insert == "<" || insert == ">")) - { - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + + +
+ + + +
+ + + + @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) { - + } - - } -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
+
+ + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+
+ } + + + + + + +
+ +
+
+ Cancel @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private Dictionary _themes; + private Dictionary _panelayouts; + private Dictionary _containers = new Dictionary(); + private List _themeList; + private List _pageList; + private string _name; + private string _title; + private string _path = string.Empty; + private string _parentid; + private string _insert = ">>"; + private List _children; + private int _childid = -1; + private string _isnavigation = "True"; + private string _url; + private string _ispersonalizable = "False"; + private string _mode = "view"; + private string _themetype = "-"; + private string _layouttype = "-"; + private string _containertype = "-"; + private string _icon = string.Empty; + private string _permissions = string.Empty; + private PermissionGrid _permissionGrid; - Dictionary themes = new Dictionary(); - Dictionary panelayouts = new Dictionary(); - - List pages; - string name; - string path = ""; - string parentid; - string insert = ">>"; - List children; - int childid = -1; - string isnavigation = "True"; - string ispersonalizable = "False"; - string mode = "view"; - string themetype = ""; - string layouttype = ""; - string icon = ""; - string permissions = ""; // need to set default permissions - - PermissionGrid permissiongrid; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() { try { - pages = PageState.Pages; - children = PageState.Pages.Where(item => item.ParentId == null).ToList(); + _themeList = await ThemeService.GetThemesAsync(); + _pageList = PageState.Pages; + _children = PageState.Pages.Where(item => item.ParentId == null).ToList(); - themes = ThemeService.GetThemeTypes(PageState.Themes); - themetype = PageState.Site.DefaultThemeType; + _themes = ThemeService.GetThemeTypes(_themeList); + _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype); + _containers = ThemeService.GetContainerTypes(_themeList); - panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype); - layouttype = PageState.Site.DefaultLayoutType; - - List permissionstrings = new List(); - permissionstrings.Add(new PermissionString { PermissionName = "View", Permissions = Constants.AdminRole }); - permissionstrings.Add(new PermissionString { PermissionName = "Edit", Permissions = Constants.AdminRole }); - permissions = UserSecurity.SetPermissionStrings(permissionstrings); + _permissions = string.Empty; } catch (Exception ex) { @@ -194,20 +249,33 @@ { try { - parentid = (string)e.Value; - if (parentid == "-1") + _parentid = (string)e.Value; + _children = new List(); + if (_parentid == "-1") { - children = PageState.Pages.Where(item => item.ParentId == null).ToList(); + foreach (Page p in PageState.Pages.Where(item => item.ParentId == null)) + { + if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) + { + _children.Add(p); + } + } } else { - children = PageState.Pages.Where(item => item.ParentId == int.Parse(parentid)).ToList(); + foreach (Page p in PageState.Pages.Where(item => item.ParentId == int.Parse(_parentid))) + { + if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) + { + _children.Add(p); + } + } } StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Child Pages For Parent {PageId} {Error}", parentid, ex.Message); + await logger.LogError(ex, "Error Loading Child Pages For Parent {PageId} {Error}", _parentid, ex.Message); AddModuleMessage("Error Loading Child Pages For Parent", MessageType.Error); } } @@ -216,20 +284,20 @@ { try { - themetype = (string)e.Value; - if (themetype != "") + _themetype = (string)e.Value; + if (_themetype != "-") { - panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype); + _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype); } else { - panelayouts = new Dictionary(); + _panelayouts = new Dictionary(); } StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", themetype, ex.Message); + await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error); } } @@ -239,78 +307,88 @@ Page page = null; try { - if (name != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype))) + if (_name != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype))) { page = new Page(); page.SiteId = PageState.Page.SiteId; - page.Name = name; - if (path == "") + page.Name = _name; + page.Title = _title; + if (_path == "") { - path = name; + _path = _name; } - if (path.Contains("/")) + + if (_path.Contains("/")) { - path = path.Substring(path.LastIndexOf("/") + 1); + _path = _path.Substring(_path.LastIndexOf("/") + 1); } - if (string.IsNullOrEmpty(parentid)) + + if (string.IsNullOrEmpty(_parentid)) { page.ParentId = null; - page.Path = Utilities.GetFriendlyUrl(path); + page.Path = Utilities.GetFriendlyUrl(_path); } else { - page.ParentId = Int32.Parse(parentid); - Page parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault(); - if (parent.Path == "") + page.ParentId = Int32.Parse(_parentid); + var parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault(); + if (parent.Path == string.Empty) { - page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(path); + page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path); } else { - page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(path); + page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path); } } + Page child; - switch (insert) + switch (_insert) { case "<<": page.Order = 0; break; case "<": - child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault(); + child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); page.Order = child.Order - 1; break; case ">": - child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault(); + child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); page.Order = child.Order + 1; break; case ">>": page.Order = int.MaxValue; break; } - page.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation)); - page.EditMode = (mode == "edit" ? true : false); - page.ThemeType = themetype; - page.LayoutType = (layouttype == null ? "" : layouttype); - page.Icon = (icon == null ? "" : icon); - page.Permissions = permissiongrid.GetPermissions(); - if (page.ThemeType == PageState.Site.DefaultThemeType) + page.IsNavigation = (_isnavigation == null ? true : Boolean.Parse(_isnavigation)); + page.Url = _url; + page.EditMode = (_mode == "edit" ? true : false); + page.ThemeType = (_themetype != "-") ? _themetype : string.Empty; + if (!string.IsNullOrEmpty(page.ThemeType) && page.ThemeType == PageState.Site.DefaultThemeType) { - page.ThemeType = ""; + page.ThemeType = string.Empty; } - if (page.LayoutType == PageState.Site.DefaultLayoutType) + page.LayoutType = (_layouttype != "-") ? _layouttype : string.Empty; + if (!string.IsNullOrEmpty(page.LayoutType) && page.LayoutType == PageState.Site.DefaultLayoutType) { - page.LayoutType = ""; + page.LayoutType = string.Empty; } - page.IsPersonalizable = (ispersonalizable == null ? false : Boolean.Parse(ispersonalizable)); + page.DefaultContainerType = (_containertype != "-") ? _containertype : string.Empty; + if (!string.IsNullOrEmpty(page.DefaultContainerType) && page.DefaultContainerType == PageState.Site.DefaultContainerType) + { + page.DefaultContainerType = string.Empty; + } + page.Icon = (_icon == null ? string.Empty : _icon); + page.Permissions = _permissionGrid.GetPermissions(); + page.IsPersonalizable = (_ispersonalizable == null ? false : Boolean.Parse(_ispersonalizable)); page.UserId = null; - await PageService.AddPageAsync(page); + page = await PageService.AddPageAsync(page); await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, page.ParentId); await logger.LogInformation("Page Added {Page}", page); - NavigationManager.NavigateTo(NavigateUrl(page.Path, Reload.Site)); + NavigationManager.NavigateTo(NavigateUrl(page.Path)); } else { diff --git a/Oqtane.Client/Modules/Admin/Pages/Edit.razor b/Oqtane.Client/Modules/Admin/Pages/Edit.razor index bc960d0b..b25f6b2e 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Edit.razor @@ -4,243 +4,317 @@ @inject IPageService PageService @inject IThemeService ThemeService - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - - @if (children != null && children.Count > 0 && (insert == "<" || insert == ">")) - { - - } -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
- - - -
+ + + @if (_themeList != null) + { + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + + @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) + { + + } +
+ + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+
+

+ + } +
+ + + + + +
+ +
+
+
Cancel -
-
- @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private Dictionary _themes; + private Dictionary _panelayouts; + private Dictionary _containers = new Dictionary(); + private List _themeList; + private List _pageList; + private int _pageId; + private string _name; + private string _title; + private string _path; + private string _currentparentid; + private string _parentid; + private string _insert = "="; + private List _children; + private int _childid = -1; + private string _isnavigation; + private string _url; + private string _ispersonalizable; + private string _mode; + private string _themetype = "-"; + private string _layouttype = "-"; + private string _containertype = "-"; + private string _icon; + private string _permissions; + private string _createdby; + private DateTime _createdon; + private string _modifiedby; + private DateTime _modifiedon; + private string _deletedby; + private DateTime? _deletedon; - Dictionary themes = new Dictionary(); - Dictionary panelayouts = new Dictionary(); +#pragma warning disable 649 + private PermissionGrid _permissionGrid; +#pragma warning restore 649 - List pages; - int PageId; - string name; - string path; - string currentparentid; - string parentid; - string insert = "="; - List children; - int childid = -1; - string isnavigation; - string ispersonalizable; - string mode; - string themetype; - string layouttype; - string icon; - string permissions; - string createdby; - DateTime createdon; - string modifiedby; - DateTime modifiedon; - string deletedby; - DateTime? deletedon; - - PermissionGrid permissiongrid; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() { try { - pages = PageState.Pages; - children = PageState.Pages.Where(item => item.ParentId == null).ToList(); + _themeList = await ThemeService.GetThemesAsync(); + _pageList = PageState.Pages; + _children = PageState.Pages.Where(item => item.ParentId == null).ToList(); - themes = ThemeService.GetThemeTypes(PageState.Themes); + _themes = ThemeService.GetThemeTypes(_themeList); + _containers = ThemeService.GetContainerTypes(_themeList); - PageId = Int32.Parse(PageState.QueryString["id"]); - Page page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault(); + _pageId = Int32.Parse(PageState.QueryString["id"]); + var page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId); if (page != null) { - name = page.Name; - path = page.Path; - if (path.Contains("/")) + _name = page.Name; + _title = page.Title; + _path = page.Path; + + if (_path.Contains("/")) { - path = path.Substring(path.LastIndexOf("/") + 1); + _path = _path.Substring(_path.LastIndexOf("/") + 1); } + if (page.ParentId == null) { - parentid = ""; + _parentid = string.Empty; } else { - parentid = page.ParentId.ToString(); + _parentid = page.ParentId.ToString(); } - currentparentid = parentid; - isnavigation = page.IsNavigation.ToString(); - ispersonalizable = page.IsPersonalizable.ToString(); - mode = (page.EditMode) ? "edit" : "view"; - themetype = page.ThemeType; - panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype); - layouttype = page.LayoutType; - icon = page.Icon; - permissions = page.Permissions; - createdby = page.CreatedBy; - createdon = page.CreatedOn; - modifiedby = page.ModifiedBy; - modifiedon = page.ModifiedOn; - deletedby = page.DeletedBy; - deletedon = page.DeletedOn; + + _currentparentid = _parentid; + _isnavigation = page.IsNavigation.ToString(); + _url = page.Url; + _ispersonalizable = page.IsPersonalizable.ToString(); + _mode = (page.EditMode) ? "edit" : "view"; + _themetype = page.ThemeType; + if (_themetype == PageState.Site.DefaultThemeType) + { + _themetype = "-"; + } + _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype); + _layouttype = page.LayoutType; + if (_layouttype == PageState.Site.DefaultLayoutType) + { + _layouttype = "-"; + } + _containertype = page.DefaultContainerType; + if (string.IsNullOrEmpty(_containertype)) + { + _containertype = "-"; + } + _icon = page.Icon; + _permissions = page.Permissions; + _createdby = page.CreatedBy; + _createdon = page.CreatedOn; + _modifiedby = page.ModifiedBy; + _modifiedon = page.ModifiedOn; + _deletedby = page.DeletedBy; + _deletedon = page.DeletedOn; } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Page {PageId} {Error}", PageId, ex.Message); + await logger.LogError(ex, "Error Loading Page {PageId} {Error}", _pageId, ex.Message); AddModuleMessage("Error Loading Page", MessageType.Error); } } @@ -249,28 +323,41 @@ { try { - parentid = (string)e.Value; - if (parentid == "-1") + _parentid = (string)e.Value; + _children = new List(); + if (_parentid == "-1") { - children = PageState.Pages.Where(item => item.ParentId == null).ToList(); + foreach(Page p in PageState.Pages.Where(item => item.ParentId == null)) + { + if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) + { + _children.Add(p); + } + } } else { - children = PageState.Pages.Where(item => item.ParentId == int.Parse(parentid)).ToList(); + foreach (Page p in PageState.Pages.Where(item => item.ParentId == int.Parse(_parentid))) + { + if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) + { + _children.Add(p); + } + } } - if (parentid == currentparentid) + if (_parentid == _currentparentid) { - insert = "="; + _insert = "="; } else { - insert = ">>"; + _insert = ">>"; } StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Child Pages For Parent {PageId} {Error}", parentid, ex.Message); + await logger.LogError(ex, "Error Loading Child Pages For Parent {PageId} {Error}", _parentid, ex.Message); AddModuleMessage("Error Loading Child Pages For Parent", MessageType.Error); } } @@ -279,20 +366,20 @@ { try { - themetype = (string)e.Value; - if (themetype != "") + _themetype = (string)e.Value; + if (_themetype != "-") { - panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes, themetype); + _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype); } else { - panelayouts = new Dictionary(); + _panelayouts = new Dictionary(); } StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", themetype, ex.Message); + await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error); } } @@ -302,104 +389,111 @@ Page page = null; try { - if (name != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype))) + if (_name != string.Empty) { - page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault(); - string currentpath = page.Path; + page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId); + string currentPath = page.Path; - page.Name = name; - if (path == "" && name.ToLower() != "home") + page.Name = _name; + page.Title = _title; + if (_path == "" && _name.ToLower() != "home") + if (_path == string.Empty && _name.ToLower() != "home") + { + _path = _name; + } + if (_path.Contains("/")) { - path = name; + _path = _path.Substring(_path.LastIndexOf("/") + 1); } - if (path.Contains("/")) - { - path = path.Substring(path.LastIndexOf("/") + 1); - } - if (string.IsNullOrEmpty(parentid)) + if (string.IsNullOrEmpty(_parentid) || _parentid == "-1") { page.ParentId = null; - page.Path = Utilities.GetFriendlyUrl(path); + page.Path = Utilities.GetFriendlyUrl(_path); } else { - page.ParentId = Int32.Parse(parentid); - Page parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault(); - if (parent.Path == "") + page.ParentId = Int32.Parse(_parentid); + Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == page.ParentId); + if (parent.Path == string.Empty) { - page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(path); + page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path); } else { - page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(path); + page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path); } } - if (insert != "=") + if (_insert != "=") { Page child; - switch (insert) + switch (_insert) { case "<<": page.Order = 0; break; case "<": - child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault(); - page.Order = child.Order - 1; + child = PageState.Pages.FirstOrDefault(item => item.PageId == _childid); + if (child != null) page.Order = child.Order - 1; break; case ">": - child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault(); - page.Order = child.Order + 1; + child = PageState.Pages.FirstOrDefault(item => item.PageId == _childid); + if (child != null) page.Order = child.Order + 1; break; case ">>": page.Order = int.MaxValue; break; } } - page.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation)); - page.EditMode = (mode == "edit" ? true : false); - page.ThemeType = themetype; - page.LayoutType = (layouttype == null ? "" : layouttype); - page.Icon = (icon == null ? "" : icon); - page.Permissions = permissiongrid.GetPermissions(); - - if (page.ThemeType == PageState.Site.DefaultThemeType) + page.IsNavigation = (_isnavigation == null || Boolean.Parse(_isnavigation)); + page.Url = _url; + page.EditMode = (_mode == "edit"); + page.ThemeType = (_themetype != "-") ? _themetype : string.Empty; + if (!string.IsNullOrEmpty(page.ThemeType) && page.ThemeType == PageState.Site.DefaultThemeType) { - page.ThemeType = ""; + page.ThemeType = string.Empty; } - if (page.LayoutType == PageState.Site.DefaultLayoutType) + page.LayoutType = (_layouttype != "-") ? _layouttype : string.Empty; + if (!string.IsNullOrEmpty(page.LayoutType) && page.LayoutType == PageState.Site.DefaultLayoutType) { - page.LayoutType = ""; + page.LayoutType = string.Empty; } - page.IsPersonalizable = (ispersonalizable == null ? false : Boolean.Parse(ispersonalizable)); + page.DefaultContainerType = (_containertype != "-") ? _containertype : string.Empty; + if (!string.IsNullOrEmpty(page.DefaultContainerType) && page.DefaultContainerType == PageState.Site.DefaultContainerType) + { + page.DefaultContainerType = string.Empty; + } + page.Icon = _icon ?? string.Empty; + page.Permissions = _permissionGrid.GetPermissions(); + page.IsPersonalizable = (_ispersonalizable != null && Boolean.Parse(_ispersonalizable)); page.UserId = null; - await PageService.UpdatePageAsync(page); + page = await PageService.UpdatePageAsync(page); await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, page.ParentId); - if (currentparentid == "") + if (_currentparentid == string.Empty) { await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, null); } else { - await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, int.Parse(currentparentid)); + await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, int.Parse(_currentparentid)); } // update child paths - if (parentid != currentparentid) + if (_parentid != _currentparentid) { - foreach (Page p in PageState.Pages.Where(item => item.Path.StartsWith(currentpath))) + foreach (Page p in PageState.Pages.Where(item => item.Path.StartsWith(currentPath))) { - p.Path = p.Path.Replace(currentpath, page.Path); + p.Path = p.Path.Replace(currentPath, page.Path); await PageService.UpdatePageAsync(p); } } await logger.LogInformation("Page Saved {Page}", page); - NavigationManager.NavigateTo(NavigateUrl(page.Path, Reload.Site)); + NavigationManager.NavigateTo(NavigateUrl(page.Path)); } else { - AddModuleMessage("You Must Provide Page Name And Theme", MessageType.Warning); + AddModuleMessage("You Must Provide Page Name", MessageType.Warning); } } catch (Exception ex) diff --git a/Oqtane.Client/Modules/Admin/Pages/Index.razor b/Oqtane.Client/Modules/Admin/Pages/Index.razor index bb6e030e..b53f3811 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Index.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Index.razor @@ -22,20 +22,21 @@ } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; - private async Task DeletePage(Page Page) + private async Task DeletePage(Page page) { try { - Page.IsDeleted = true; - await PageService.UpdatePageAsync(Page); - await logger.LogInformation("Page Deleted {Page}", Page); - NavigationManager.NavigateTo(NavigateUrl("admin/pages", Reload.Site)); + page.IsDeleted = true; + + await PageService.UpdatePageAsync(page); + await logger.LogInformation("Page Deleted {Page}", page); + NavigationManager.NavigateTo(NavigateUrl("admin/pages")); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Page {Page} {Error}", Page, ex.Message); + await logger.LogError(ex, "Error Deleting Page {Page} {Error}", page, ex.Message); AddModuleMessage("Error Deleting Page", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor index a1eaff65..96a65b18 100644 --- a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor @@ -6,66 +6,66 @@ @@ -25,27 +25,27 @@ else } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private List _profiles; - List Profiles; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() { - Profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId); + _profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId); } - private async Task DeleteProfile(int ProfileId) + private async Task DeleteProfile(int profileId) { try { - await ProfileService.DeleteProfileAsync(ProfileId); - await logger.LogInformation("Profile Deleted {ProfileId}", ProfileId); + await ProfileService.DeleteProfileAsync(profileId); + await logger.LogInformation("Profile Deleted {ProfileId}", profileId); AddModuleMessage("Profile Deleted", MessageType.Success); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", ProfileId, ex.Message); + await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", profileId, ex.Message); AddModuleMessage("Error Deleting Profile", MessageType.Error); } } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor b/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor index ec7ef28b..d3955307 100644 --- a/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor +++ b/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor @@ -5,76 +5,74 @@ @inject IModuleService ModuleService @inject IPageService PageService - - - @if (pages.Count == 0) + + + @if (_pages == null) { -
+

No Deleted Pages

} else { - +
+
+ - - + + - - } - - @if (pageModules.Count == 0) + + @if (_modules == null) { -
+

No Deleted Modules

} else { - +
+
+ - - + + - - } - + @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private List _pages; + private List _modules; - List pages { get; set; } - List pageModules { get; set; } + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() { try { - pages = new List(); - pageModules = new List(); - await LoadEntities(); + await Load(); } catch (Exception ex) { @@ -83,92 +81,89 @@ } } - protected override void OnParametersSet() + private async Task Load() { - pages = PageState.Pages.Where(item => item.IsDeleted).ToList(); + _pages = await PageService.GetPagesAsync(PageState.Site.SiteId); + _pages = _pages.Where(item => item.IsDeleted).ToList(); + + _modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId); + _modules = _modules.Where(item => item.IsDeleted).ToList(); } - private async Task LoadEntities() - { - pageModules.Clear(); - foreach (var module in PageState.Modules.Where(item => item.IsDeleted)) - { - var pageModule = await PageModuleService.GetPageModuleAsync(module.PageModuleId); - pageModules.Add(pageModule); - } - } - - private async Task RestorePage(Page Page) + private async Task RestorePage(Page page) { try { - Page.IsDeleted = false; - await PageService.UpdatePageAsync(Page); - await logger.LogInformation("Page Restored {Page}", Page); - NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); + page.IsDeleted = false; + await PageService.UpdatePageAsync(page); + await logger.LogInformation("Page Restored {Page}", page); + await Load(); + StateHasChanged(); + NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", Page, ex.Message); + await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", page, ex.Message); AddModuleMessage("Error Restoring Deleted Page", MessageType.Error); } } - private async Task DeletePage(int PageId) + private async Task DeletePage(Page page) { try { - var deletedPageModules = PageState.Modules.Where(item => item.PageId == PageId); - await PageService.DeletePageAsync(PageId); - foreach (var module in deletedPageModules) - { - await ModuleService.DeleteModuleAsync(module.ModuleId); - } - await logger.LogInformation("Page Permanently Deleted {PageId}", PageId); - NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); + await PageService.DeletePageAsync(page.PageId); + await logger.LogInformation("Page Permanently Deleted {Page}", page); + await Load(); + StateHasChanged(); + NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Permanently Deleting Page {PageId} {Error}", PageId, ex.Message); + await logger.LogError(ex, "Error Permanently Deleting Page {Page} {Error}", page, ex.Message); AddModuleMessage(ex.Message, MessageType.Error); } } - private async Task RestorePageModule(PageModule PageModule) + private async Task RestoreModule(Module module) { try { - PageModule.IsDeleted = false; - await PageModuleService.UpdatePageModuleAsync(PageModule); - await LoadEntities(); - await logger.LogInformation("Page Module Restored {PageModule}", PageModule); - NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); + var pagemodule = await PageModuleService.GetPageModuleAsync(module.PageModuleId); + pagemodule.IsDeleted = false; + await PageModuleService.UpdatePageModuleAsync(pagemodule); + await logger.LogInformation("Module Restored {Module}", module); + await Load(); + StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Restoring Deleted Page Module {PageModule} {Error}", PageModule, ex.Message); - AddModuleMessage("Error Restoring Deleted Page Module", MessageType.Error); + await logger.LogError(ex, "Error Restoring Deleted Module {Module} {Error}", module, ex.Message); + AddModuleMessage("Error Restoring Deleted Module", MessageType.Error); } } - private async Task DeletePageModule(int PageModuleId, int ModuleId) + private async Task DeleteModule(Module module) { try { - await PageModuleService.DeletePageModuleAsync(PageModuleId); - if (PageState.Modules.Count(item => item.ModuleId == ModuleId) == 1) + await PageModuleService.DeletePageModuleAsync(module.PageModuleId); + // check if there are any remaining module instances in the site + _modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId); + + if (!_modules.Exists(item => item.ModuleId == module.ModuleId)) { - await ModuleService.DeleteModuleAsync(ModuleId); + await ModuleService.DeleteModuleAsync(module.ModuleId); } - PageState.Modules.RemoveAt(PageState.Modules.FindIndex(item => item.ModuleId == ModuleId)); - await LoadEntities(); - await logger.LogInformation("Page Module Permanently Deleted {PageModuleId}", PageModuleId); - NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); + + await logger.LogInformation("Module Permanently Deleted {Module}", module); + await Load(); + StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Permanently Deleting Page Module {PageModuleId} {Error}", PageModuleId, ex.Message); - AddModuleMessage("Error Permanently Deleting Page Module", MessageType.Error); + await logger.LogError(ex, "Error Permanently Deleting Module {Module} {Error}", module, ex.Message); + AddModuleMessage("Error Permanently Deleting Module", MessageType.Error); } } } diff --git a/Oqtane.Client/Modules/Admin/Register/Index.razor b/Oqtane.Client/Modules/Admin/Register/Index.razor index 40b59b89..2ea64944 100644 --- a/Oqtane.Client/Modules/Admin/Register/Index.razor +++ b/Oqtane.Client/Modules/Admin/Register/Index.razor @@ -3,71 +3,87 @@ @inject NavigationManager NavigationManager @inject IUserService UserService -@if (Message != "") +@if (PageState.Site.AllowRegistration) { - + + + ... + + + + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+
+} +else +{ + } -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - -
- @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } } + private string _username = string.Empty; + private string _password = string.Empty; + private string _confirm = string.Empty; + private string _email = string.Empty; + private string _displayName = string.Empty; - string Message = "Please Note That Registration Requires A Valid Email Address In Order To Verify Your Identity"; - string Username = ""; - string Password = ""; - string Confirm = ""; - string Email = ""; - string DisplayName = ""; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous; private async Task Register() { try { - Message = ""; - if (Username != "" && Password != "" && Confirm != "" && Email != "") + bool _isEmailValid = Utilities.IsValidEmail(_email); + + if (_username != "" && _password != "" && _confirm != "" && _isEmailValid) { - if (Password == Confirm) + if (_password == _confirm) { - User user = new User(); - user.SiteId = PageState.Site.SiteId; - user.Username = Username; - user.DisplayName = (DisplayName == "" ? Username : DisplayName); - user.Email = Email; - user.Password = Password; + var user = new User + { + SiteId = PageState.Site.SiteId, + Username = _username, + DisplayName = (_displayName == string.Empty ? _username : _displayName), + Email = _email, + Password = _password + }; user = await UserService.AddUserAsync(user); if (user != null) { - await logger.LogInformation("User Created {Username} {Email}", Username, Email); + await logger.LogInformation("User Created {Username} {Email}", _username, _email); AddModuleMessage("User Account Created. Please Check Your Email For Verification Instructions.", MessageType.Info); } else { - await logger.LogError("Error Adding User {Username} {Email}", Username, Email); + await logger.LogError("Error Adding User {Username} {Email}", _username, _email); AddModuleMessage("Error Adding User. Please Ensure Password Meets Complexity Requirements And Username Is Not Already In Use.", MessageType.Error); } } @@ -83,13 +99,13 @@ } catch (Exception ex) { - await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", Username, Email, ex.Message); + await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", _username, _email, ex.Message); AddModuleMessage("Error Adding User", MessageType.Error); } } private void Cancel() { - NavigationManager.NavigateTo(NavigateUrl("")); + NavigationManager.NavigateTo(NavigateUrl(string.Empty)); } -} +} \ No newline at end of file diff --git a/Oqtane.Client/Modules/Admin/Reset/Index.razor b/Oqtane.Client/Modules/Admin/Reset/Index.razor index e7ed6bbe..b6e4eb66 100644 --- a/Oqtane.Client/Modules/Admin/Reset/Index.razor +++ b/Oqtane.Client/Modules/Admin/Reset/Index.razor @@ -6,36 +6,36 @@
- +
- +
- - + +
@code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } } + private string _username = string.Empty; + private string _password = string.Empty; + private string _confirm = string.Empty; - string Username = ""; - string Password = ""; - string Confirm = ""; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous; protected override void OnInitialized() { if (PageState.QueryString.ContainsKey("name") && PageState.QueryString.ContainsKey("token")) { - Username = PageState.QueryString["name"]; + _username = PageState.QueryString["name"]; } else { - NavigationManager.NavigateTo(NavigateUrl("")); + NavigationManager.NavigateTo(NavigateUrl(string.Empty)); } } @@ -43,24 +43,26 @@ { try { - if (Username != "" && Password != "" && Confirm != "") + if (_username != string.Empty && _password != string.Empty && _confirm != string.Empty) { - if (Password == Confirm) + if (_password == _confirm) { - User user = new User(); - user.SiteId = PageState.Site.SiteId; - user.Username = Username; - user.Password = Password; + var user = new User + { + SiteId = PageState.Site.SiteId, + Username = _username, + Password = _password + }; user = await UserService.ResetPasswordAsync(user, PageState.QueryString["token"]); if (user != null) { - await logger.LogInformation("User Password Reset {Username}", Username); + await logger.LogInformation("User Password Reset {Username}", _username); NavigationManager.NavigateTo(NavigateUrl("login")); } else { - await logger.LogError("Error Resetting User Password {Username}", Username); + await logger.LogError("Error Resetting User Password {Username}", _username); AddModuleMessage("Error Resetting User Password. Please Ensure Password Meets Complexity Requirements.", MessageType.Error); } } @@ -76,13 +78,13 @@ } catch (Exception ex) { - await logger.LogError(ex, "Error Resetting User Password {Username} {Error}", Username, ex.Message); + await logger.LogError(ex, "Error Resetting User Password {Username} {Error}", _username, ex.Message); AddModuleMessage("Error Resetting User Password", MessageType.Error); } } private void Cancel() { - NavigationManager.NavigateTo(NavigateUrl("")); + NavigationManager.NavigateTo(NavigateUrl(string.Empty)); } } diff --git a/Oqtane.Client/Modules/Admin/Roles/Add.razor b/Oqtane.Client/Modules/Admin/Roles/Add.razor index c2bff1da..34e93e2d 100644 --- a/Oqtane.Client/Modules/Admin/Roles/Add.razor +++ b/Oqtane.Client/Modules/Admin/Roles/Add.razor @@ -6,37 +6,26 @@
- + - +
- + - +
- + -
- + - +
- + - +
- + - +
- + - +
- + - @@ -73,10 +73,10 @@
- + - @@ -87,19 +87,20 @@ Cancel @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - public override string Actions { get { return "Add,Edit"; } } + private int _profileid = -1; + private string _name = string.Empty; + private string _title = string.Empty; + private string _description = string.Empty; + private string _category = string.Empty; + private string _vieworder = "0"; + private string _maxlength = "0"; + private string _defaultvalue = string.Empty; + private string _isrequired = "False"; + private string _isprivate = "False"; - int profileid = -1; - string name = ""; - string title = ""; - string description = ""; - string category = ""; - string vieworder = "0"; - string maxlength = "0"; - string defaultvalue = ""; - string isrequired = "False"; - string isprivate = "False"; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + + public override string Actions => "Add,Edit"; protected override async Task OnInitializedAsync() { @@ -107,25 +108,25 @@ { if (PageState.QueryString.ContainsKey("id")) { - profileid = Int32.Parse(PageState.QueryString["id"]); - Profile profile = await ProfileService.GetProfileAsync(profileid); + _profileid = Int32.Parse(PageState.QueryString["id"]); + var profile = await ProfileService.GetProfileAsync(_profileid); if (profile != null) { - name = profile.Name; - title = profile.Title; - description = profile.Description; - category = profile.Category; - vieworder = profile.ViewOrder.ToString(); - maxlength = profile.MaxLength.ToString(); - defaultvalue = profile.DefaultValue; - isrequired = profile.IsRequired.ToString(); - isprivate = profile.IsPrivate.ToString(); + _name = profile.Name; + _title = profile.Title; + _description = profile.Description; + _category = profile.Category; + _vieworder = profile.ViewOrder.ToString(); + _maxlength = profile.MaxLength.ToString(); + _defaultvalue = profile.DefaultValue; + _isrequired = profile.IsRequired.ToString(); + _isprivate = profile.IsPrivate.ToString(); } } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", profileid, ex.Message); + await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", _profileid, ex.Message); AddModuleMessage("Error Loading Profile", MessageType.Error); } } @@ -135,30 +136,38 @@ try { Profile profile; - if (profileid != -1) + if (_profileid != -1) { - profile = await ProfileService.GetProfileAsync(profileid); + profile = await ProfileService.GetProfileAsync(_profileid); } else { profile = new Profile(); } - profile.Name = name; - profile.Title = title; - profile.Description = description; - profile.Category = category; - profile.ViewOrder = int.Parse(vieworder); - profile.MaxLength = int.Parse(maxlength); - profile.DefaultValue = defaultvalue; - profile.IsRequired = (isrequired == null ? false : Boolean.Parse(isrequired)); - profile.IsPrivate = (isprivate == null ? false : Boolean.Parse(isprivate)); - profile = await ProfileService.UpdateProfileAsync(profile); + + profile.Name = _name; + profile.Title = _title; + profile.Description = _description; + profile.Category = _category; + profile.ViewOrder = int.Parse(_vieworder); + profile.MaxLength = int.Parse(_maxlength); + profile.DefaultValue = _defaultvalue; + profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired)); + profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate)); + if (_profileid != -1) + { + profile = await ProfileService.UpdateProfileAsync(profile); + }else + { + profile = await ProfileService.AddProfileAsync(profile); + } + await logger.LogInformation("Profile Saved {Profile}", profile); NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", profileid, ex.Message); + await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message); AddModuleMessage("Error Saving Profile", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/Profiles/Index.razor b/Oqtane.Client/Modules/Admin/Profiles/Index.razor index b362895a..e3cefdaa 100644 --- a/Oqtane.Client/Modules/Admin/Profiles/Index.razor +++ b/Oqtane.Client/Modules/Admin/Profiles/Index.razor @@ -2,7 +2,7 @@ @inherits ModuleBase @inject IProfileService ProfileService -@if (Profiles == null) +@if (_profiles == null) {

Loading...

} @@ -10,7 +10,7 @@ else { - +
      Name Deleted By Deleted On   @context.Name @context.DeletedBy @context.DeletedOn    Page Module Deleted By Deleted On   @PageState.Pages.Find(item => item.PageId == context.PageId).Name @context.Title @context.DeletedBy @context.DeletedOn
- - - - + + + + + + + +

+} + +@code { + private int roleid; + private string name = string.Empty; + private List users; + private int userid = -1; + private string effectivedate = string.Empty; + private string expirydate = string.Empty; + private List userroles; + + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + + protected override async Task OnInitializedAsync() + { + try + { + roleid = Int32.Parse(PageState.QueryString["id"]); + Role role = await RoleService.GetRoleAsync(roleid); + name = role.Name; + users = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId); + users = users.Where(item => item.Role.Name == Constants.RegisteredRole).ToList(); + await GetUserRoles(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Loading Users {Error}", ex.Message); + AddModuleMessage("Error Loading Users", MessageType.Error); + } + } + + private async Task GetUserRoles() + { + try + { + userroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId); + userroles = userroles.Where(item => item.RoleId == roleid).ToList(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Loading User Roles {RoleId} {Error}", roleid, ex.Message); + AddModuleMessage("Error Loading User Roles", MessageType.Error); + } + } + + private async Task SaveUserRole() + { + try + { + if (userid != -1) + { + var userrole = userroles.Where(item => item.UserId == userid && item.RoleId == roleid).FirstOrDefault(); + if (userrole != null) + { + if (string.IsNullOrEmpty(effectivedate)) + { + userrole.EffectiveDate = null; + } + else + { + userrole.EffectiveDate = DateTime.Parse(effectivedate); + } + + if (string.IsNullOrEmpty(expirydate)) + { + userrole.ExpiryDate = null; + } + else + { + userrole.ExpiryDate = DateTime.Parse(expirydate); + } + await UserRoleService.UpdateUserRoleAsync(userrole); + } + else + { + userrole = new UserRole(); + userrole.UserId = userid; + userrole.RoleId = roleid; + + if (string.IsNullOrEmpty(effectivedate)) + { + userrole.EffectiveDate = null; + } + else + { + userrole.EffectiveDate = DateTime.Parse(effectivedate); + } + + if (string.IsNullOrEmpty(expirydate)) + { + userrole.ExpiryDate = null; + } + else + { + userrole.ExpiryDate = DateTime.Parse(expirydate); + } + + await UserRoleService.AddUserRoleAsync(userrole); + } + + await GetUserRoles(); + await logger.LogInformation("User Assigned To Role {UserRole}", userrole); + AddModuleMessage("User Assigned To Role", MessageType.Success); + } + else + { + AddModuleMessage("You Must Select A User", MessageType.Warning); + } + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Saving User Roles {RoleId} {Error}", roleid, ex.Message); + AddModuleMessage("Error Saving User Roles", MessageType.Error); + } + } + + private async Task DeleteUserRole(int UserRoleId) + { + try + { + await UserRoleService.DeleteUserRoleAsync(UserRoleId); + await GetUserRoles(); + await logger.LogInformation("User Removed From Role {UserRoleId}", UserRoleId); + AddModuleMessage("User Removed From Role", MessageType.Success); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Removing User From Role {UserRoleId} {Error}", UserRoleId, ex.Message); + AddModuleMessage("Error Removing User From Role", MessageType.Error); + } + } +} diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor new file mode 100644 index 00000000..3f3425f6 --- /dev/null +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -0,0 +1,451 @@ +@namespace Oqtane.Modules.Admin.Site +@inherits ModuleBase +@inject NavigationManager NavigationManager +@inject ISiteService SiteService +@inject ITenantService TenantService +@inject IAliasService AliasService +@inject IThemeService ThemeService +@inject ISettingService SettingService + +@if (_themes != null) +{ +
- + - +
- + -
- + - -
- - - @@ -46,22 +35,21 @@ Cancel -@code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } +@code { + private string _name = string.Empty; + private string _description = string.Empty; + private string _isautoassigned = "False"; - string name = ""; - string description = ""; - string isautoassigned = "False"; - string issystem = "False"; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; private async Task SaveRole() { - Role role = new Role(); + var role = new Role(); role.SiteId = PageState.Page.SiteId; - role.Name = name; - role.Description = description; - role.IsAutoAssigned = (isautoassigned == null ? false : Boolean.Parse(isautoassigned)); - role.IsSystem = (issystem == null ? false : Boolean.Parse(issystem)); + role.Name = _name; + role.Description = _description; + role.IsAutoAssigned = (_isautoassigned == null ? false : Boolean.Parse(_isautoassigned)); + role.IsSystem = false; try { diff --git a/Oqtane.Client/Modules/Admin/Roles/Edit.razor b/Oqtane.Client/Modules/Admin/Roles/Edit.razor index 2557bd44..4b0dd0e0 100644 --- a/Oqtane.Client/Modules/Admin/Roles/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Roles/Edit.razor @@ -6,37 +6,26 @@ - - - - - - + + + } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private List _roles; - List Roles; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnParametersSetAsync() { - Roles = await RoleService.GetRolesAsync(PageState.Site.SiteId); + _roles = await RoleService.GetRolesAsync(PageState.Site.SiteId); } - private async Task DeleteRole(Role Role) + private async Task DeleteRole(Role role) { try { - await RoleService.DeleteRoleAsync(Role.RoleId); - await logger.LogInformation("Role Deleted {Role}", Role); + await RoleService.DeleteRoleAsync(role.RoleId); + await logger.LogInformation("Role Deleted {Role}", role); StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Role {Role} {Error}", Role, ex.Message); + await logger.LogError(ex, "Error Deleting Role {Role} {Error}", role, ex.Message); AddModuleMessage("Error Deleting Role", MessageType.Error); } } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/Roles/Users.razor b/Oqtane.Client/Modules/Admin/Roles/Users.razor new file mode 100644 index 00000000..c292d3d5 --- /dev/null +++ b/Oqtane.Client/Modules/Admin/Roles/Users.razor @@ -0,0 +1,201 @@ +@namespace Oqtane.Modules.Admin.Roles +@inherits ModuleBase +@inject IRoleService RoleService +@inject IUserRoleService UserRoleService + +@if (userroles == null) +{ +

Loading...

+} +else +{ +
- + - +
- + -
- + - -
- - - @@ -47,42 +36,40 @@ Cancel @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } + private int _roleid; + private string _name = string.Empty; + private string _description = string.Empty; + private string _isautoassigned = "False"; - int roleid; - string name = ""; - string description = ""; - string isautoassigned = "False"; - string issystem = "False"; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() { try { - roleid = Int32.Parse(PageState.QueryString["id"]); - Role role = await RoleService.GetRoleAsync(roleid); + _roleid = Int32.Parse(PageState.QueryString["id"]); + var role = await RoleService.GetRoleAsync(_roleid); if (role != null) { - name = role.Name; - description = role.Description; - isautoassigned = role.IsAutoAssigned.ToString(); - issystem = role.IsSystem.ToString(); + _name = role.Name; + _description = role.Description; + _isautoassigned = role.IsAutoAssigned.ToString(); } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", roleid, ex.Message); + await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", _roleid, ex.Message); AddModuleMessage("Error Loading Role", MessageType.Error); } } private async Task SaveRole() { - Role role = await RoleService.GetRoleAsync(roleid); - role.Name = name; - role.Description = description; - role.IsAutoAssigned = (isautoassigned == null ? false : Boolean.Parse(isautoassigned)); - role.IsSystem = (issystem == null ? false : Boolean.Parse(issystem)); + var role = await RoleService.GetRoleAsync(_roleid); + role.Name = _name; + role.Description = _description; + role.IsAutoAssigned = (_isautoassigned != null && Boolean.Parse(_isautoassigned)); + role.IsSystem = false; try { diff --git a/Oqtane.Client/Modules/Admin/Roles/Index.razor b/Oqtane.Client/Modules/Admin/Roles/Index.razor index 79124760..881a9348 100644 --- a/Oqtane.Client/Modules/Admin/Roles/Index.razor +++ b/Oqtane.Client/Modules/Admin/Roles/Index.razor @@ -2,7 +2,7 @@ @inherits ModuleBase @inject IRoleService RoleService -@if (Roles == null) +@if (_roles == null) {

Loading...

} @@ -10,42 +10,44 @@ else { - +
+
      Name @context.Name
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + Cancel + +
+

+ +

+
Users @context.User.DisplayName + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+
+
+ + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+
+ +
+ + Cancel +
+
+ +} + +@code { + private Dictionary _themes; + private Dictionary _panelayouts; + private Dictionary _containers; + private List _themeList; + private string _name = string.Empty; + private List _tenantList; + private string _tenant = string.Empty; + private List _aliasList; + private string _urls = string.Empty; + private int _logofileid = -1; + private FileManager _logofilemanager; + private int _faviconfileid = -1; + private FileManager _faviconfilemanager; + private string _themetype; + private string _layouttype; + private string _containertype; + private string _allowregistration; + private string _smtphost = string.Empty; + private string _smtpport = string.Empty; + private string _smtpssl = string.Empty; + private string _smtpusername = string.Empty; + private string _smtppassword = string.Empty; + private string _pwaisenabled; + private int _pwaappiconfileid = -1; + private FileManager _pwaappiconfilemanager; + private int _pwasplashiconfileid = -1; + private FileManager _pwasplashiconfilemanager; + private string _createdby; + private DateTime _createdon; + private string _modifiedby; + private DateTime _modifiedon; + private string _deletedby; + private DateTime? _deletedon; + private string _isdeleted; + + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + + protected override async Task OnInitializedAsync() + { + try + { + _themeList = await ThemeService.GetThemesAsync(); + _aliasList = await AliasService.GetAliasesAsync(); + Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId); + if (site != null) + { + _name = site.Name; + _tenantList = await TenantService.GetTenantsAsync(); + _tenant = _tenantList.Find(item => item.TenantId == site.TenantId).Name; + foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) + { + _urls += alias.Name + "\n"; + } + if (site.LogoFileId != null) + { + _logofileid = site.LogoFileId.Value; + } + + if (site.FaviconFileId != null) + { + _faviconfileid = site.FaviconFileId.Value; + } + + _themetype = site.DefaultThemeType; + _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype); + _layouttype = site.DefaultLayoutType; + _containertype = site.DefaultContainerType; + _allowregistration = site.AllowRegistration.ToString(); + + var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); + _smtphost = SettingService.GetSetting(settings, "SMTPHost", string.Empty); + _smtpport = SettingService.GetSetting(settings, "SMTPPort", string.Empty); + _smtpssl = SettingService.GetSetting(settings, "SMTPSSL", string.Empty); + _smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty); + _smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty); + + _pwaisenabled = site.PwaIsEnabled.ToString(); + + if (site.PwaAppIconFileId != null) + { + _pwaappiconfileid = site.PwaAppIconFileId.Value; + } + + if (site.PwaSplashIconFileId != null) + { + _pwasplashiconfileid = site.PwaSplashIconFileId.Value; + } + + _pwaisenabled = site.PwaIsEnabled.ToString(); + if (site.PwaAppIconFileId != null) + { + _pwaappiconfileid = site.PwaAppIconFileId.Value; + } + if (site.PwaSplashIconFileId != null) + { + _pwasplashiconfileid = site.PwaSplashIconFileId.Value; + } + + _createdby = site.CreatedBy; + _createdon = site.CreatedOn; + _modifiedby = site.ModifiedBy; + _modifiedon = site.ModifiedOn; + _deletedby = site.DeletedBy; + _deletedon = site.DeletedOn; + _isdeleted = site.IsDeleted.ToString(); + } + + _themes = ThemeService.GetThemeTypes(_themeList); + _containers = ThemeService.GetContainerTypes(_themeList); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message); + AddModuleMessage(ex.Message, MessageType.Error); + } + } + + private async void ThemeChanged(ChangeEventArgs e) + { + try + { + _themetype = (string)e.Value; + if (_themetype != string.Empty) + { + _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype); + } + else + { + _panelayouts = new Dictionary(); + } + StateHasChanged(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); + AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error); + } + } + + private async Task SaveSite() + { + try + { + if (_name != string.Empty && _urls != string.Empty && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype)) + { + var unique = true; + foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + { + if (_aliasList.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId)) + { + unique = false; + } + } + + if (unique) + { + var site = await SiteService.GetSiteAsync(PageState.Site.SiteId); + if (site != null) + { + site.Name = _name; + site.LogoFileId = null; + var logofileid = _logofilemanager.GetFileId(); + if (logofileid != -1) + { + site.LogoFileId = logofileid; + } + + site.DefaultThemeType = _themetype; + site.DefaultLayoutType = (_layouttype == null ? string.Empty : _layouttype); + site.DefaultContainerType = _containertype; + site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration)); + site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); + + site.PwaIsEnabled = (_pwaisenabled == null ? true : Boolean.Parse(_pwaisenabled)); + + var pwaappiconfileid = _pwaappiconfilemanager.GetFileId(); + if (pwaappiconfileid != -1) + { + site.PwaAppIconFileId = pwaappiconfileid; + } + + var pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId(); + if (pwasplashiconfileid != -1) + { + site.PwaSplashIconFileId = pwasplashiconfileid; + } + + site = await SiteService.UpdateSiteAsync(site); + + _urls = _urls.Replace("\n", ","); + var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) + { + if (!names.Contains(alias.Name)) + { + await AliasService.DeleteAliasAsync(alias.AliasId); + } + } + + foreach (string name in names) + { + if (!_aliasList.Exists(item => item.Name == name)) + { + Alias alias = new Alias(); + alias.Name = name; + alias.TenantId = site.TenantId; + alias.SiteId = site.SiteId; + await AliasService.AddAliasAsync(alias); + } + } + + var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); + SettingService.SetSetting(settings, "SMTPHost", _smtphost); + SettingService.SetSetting(settings, "SMTPPort", _smtpport); + SettingService.SetSetting(settings, "SMTPSSL", _smtpssl); + SettingService.SetSetting(settings, "SMTPUsername", _smtpusername); + SettingService.SetSetting(settings, "SMTPPassword", _smtppassword); + await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId); + + await logger.LogInformation("Site Saved {Site}", site); + + NavigationManager.NavigateTo(NavigateUrl()); + } + } + else + { + AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning); + } + } + else + { + AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning); + } + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message); + AddModuleMessage("Error Saving Site", MessageType.Error); + } + } +} diff --git a/Oqtane.Client/Modules/Admin/Sites/Add.razor b/Oqtane.Client/Modules/Admin/Sites/Add.razor index 5c1532cb..40ac6f39 100644 --- a/Oqtane.Client/Modules/Admin/Sites/Add.razor +++ b/Oqtane.Client/Modules/Admin/Sites/Add.razor @@ -5,9 +5,11 @@ @inject IAliasService AliasService @inject ISiteService SiteService @inject IThemeService ThemeService +@inject ISiteTemplateService SiteTemplateService @inject IUserService UserService +@inject IInstallationService InstallationService -@if (tenants == null) +@if (_tenants == null) {

Loading...

} @@ -16,50 +18,28 @@ else + +
- + - +
- + - +
- + - +
+ +

+ @if (!string.IsNullOrEmpty(_results)) + { + @((MarkupString)_results) + } +} + +@code { + private List _tenants; + private string _tenantid = "-1"; + private string _sql = string.Empty; + private string _results = string.Empty; + + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; + + protected override async Task OnInitializedAsync() + { + _tenants = await TenantService.GetTenantsAsync(); + } + + private async Task Execute() + { + if (_tenantid != "-1" && !string.IsNullOrEmpty(_sql)) + { + var sqlquery = new SqlQuery { TenantId = int.Parse(_tenantid), Query = _sql }; + sqlquery = await SqlService.ExecuteQueryAsync(sqlquery); + _results = DisplayResults(sqlquery.Results); + } + else + { + AddModuleMessage("You Must Select A Tenant And Provide A SQL Query", MessageType.Warning); + } + } + + private string DisplayResults(List> results) + { + var table = string.Empty; + foreach (Dictionary item in results) + { + if (table == string.Empty) + { + table = "
"; + table += ""; + + foreach (KeyValuePair kvp in item) + { + table += ""; + } + + table += ""; + } + + table += ""; + + foreach (KeyValuePair kvp in item) + { + table += ""; + } + + table += ""; + } + + if (table != string.Empty) + { + table += "
" + kvp.Key + "
" + kvp.Value + "
"; + } + else + { + table = "No Results Returned"; + } + + return table; + } +} diff --git a/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor b/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor new file mode 100644 index 00000000..ca7c7f2c --- /dev/null +++ b/Oqtane.Client/Modules/Admin/SystemInfo/Index.razor @@ -0,0 +1,81 @@ +@namespace Oqtane.Modules.Admin.SystemInfo +@inherits ModuleBase +@inject ISystemService SystemService + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+Access Framework API + +@code { + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; + + private string _version = string.Empty; + private string _runtime = string.Empty; + private string _clrversion = string.Empty; + private string _osversion = string.Empty; + private string _serverpath = string.Empty; + private string _servertime = string.Empty; + + protected override async Task OnInitializedAsync() + { + _version = Constants.Version; + _runtime = PageState.Runtime.ToString(); + + Dictionary systeminfo = await SystemService.GetSystemInfoAsync(); + if (systeminfo != null) + { + _clrversion = systeminfo["clrversion"]; + _osversion = systeminfo["osversion"]; + _serverpath = systeminfo["serverpath"]; + _servertime = systeminfo["servertime"]; + } + } +} diff --git a/Oqtane.Client/Modules/Admin/Tenants/Add.razor b/Oqtane.Client/Modules/Admin/Tenants/Add.razor deleted file mode 100644 index e12a27a3..00000000 --- a/Oqtane.Client/Modules/Admin/Tenants/Add.razor +++ /dev/null @@ -1,82 +0,0 @@ -@namespace Oqtane.Modules.Admin.Tenants -@inherits ModuleBase -@inject NavigationManager NavigationManager -@inject ITenantService TenantService -@inject IInstallationService InstallationService - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- -Cancel - -@code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } - - string name = ""; - string connectionstring = ""; - string schema = ""; - - protected override async Task OnInitializedAsync() - { - try - { - List tenants = await TenantService.GetTenantsAsync(); - connectionstring = tenants.FirstOrDefault().DBConnectionString; - schema = tenants.FirstOrDefault().DBSchema; - } - catch (Exception ex) - { - await logger.LogError(ex, "Error Loading Tenants {Error}", ex.Message); - AddModuleMessage("Error Loading Tenants", MessageType.Error); - } - } - - private async Task SaveTenant() - { - ShowProgressIndicator(); - - connectionstring = connectionstring.Replace("\\\\", "\\"); - GenericResponse response = await InstallationService.Install(connectionstring); - if (response.Success) - { - Tenant tenant = new Tenant(); - tenant.Name = name; - tenant.DBConnectionString = connectionstring; - tenant.DBSchema = schema; - tenant.IsInitialized = false; - await TenantService.AddTenantAsync(tenant); - await logger.LogInformation("Tenant Created {Tenant}", tenant); - - NavigationManager.NavigateTo(NavigateUrl()); - } - else - { - await logger.LogError("Error Creating Tenant {Error}", response.Message); - AddModuleMessage(response.Message, MessageType.Error); - } - } -} diff --git a/Oqtane.Client/Modules/Admin/Tenants/Edit.razor b/Oqtane.Client/Modules/Admin/Tenants/Edit.razor index ca0b8c9c..94ee91d6 100644 --- a/Oqtane.Client/Modules/Admin/Tenants/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Tenants/Edit.razor @@ -6,51 +6,50 @@ - - - - +
- + - + @if (name == Constants.MasterTenant) + { + + } + else + { + + }
- + - -
- - - +
Cancel @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private int tenantid; + private string name = string.Empty; + private string connectionstring = string.Empty; + private string schema = string.Empty; - int tenantid; - string name = ""; - string connectionstring = ""; - string schema = ""; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { try { tenantid = Int32.Parse(PageState.QueryString["id"]); - Tenant tenant = await TenantService.GetTenantAsync(tenantid); + var tenant = await TenantService.GetTenantAsync(tenantid); if (tenant != null) { name = tenant.Name; connectionstring = tenant.DBConnectionString; - schema = tenant.DBSchema; } } catch (Exception ex) @@ -65,12 +64,12 @@ try { connectionstring = connectionstring.Replace("\\\\", "\\"); - Tenant tenant = await TenantService.GetTenantAsync(tenantid); + var tenant = await TenantService.GetTenantAsync(tenantid); if (tenant != null) { tenant.Name = name; tenant.DBConnectionString = connectionstring; - tenant.DBSchema = schema; + await TenantService.UpdateTenantAsync(tenant); await logger.LogInformation("Tenant Saved {TenantId}", tenantid); diff --git a/Oqtane.Client/Modules/Admin/Tenants/Index.razor b/Oqtane.Client/Modules/Admin/Tenants/Index.razor index 5c22fcbf..ead272dc 100644 --- a/Oqtane.Client/Modules/Admin/Tenants/Index.razor +++ b/Oqtane.Client/Modules/Admin/Tenants/Index.razor @@ -1,6 +1,7 @@ @namespace Oqtane.Modules.Admin.Tenants @inherits ModuleBase @inject ITenantService TenantService +@inject IAliasService AliasService @if (tenants == null) { @@ -8,8 +9,6 @@ } else { - -
  @@ -18,7 +17,7 @@ else
- + @context.Name
@@ -26,9 +25,9 @@ else } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private List tenants; - List tenants; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnParametersSetAsync() { @@ -39,9 +38,25 @@ else { try { - await TenantService.DeleteTenantAsync(Tenant.TenantId); - await logger.LogInformation("Tenant Deleted {Tenant}", Tenant); - StateHasChanged(); + string message = string.Empty; + var aliases = await AliasService.GetAliasesAsync(); + foreach (var alias in aliases) + { + if (alias.TenantId == Tenant.TenantId) + { + message += ", " + alias.Name; + } + } + if (string.IsNullOrEmpty(message)) + { + await TenantService.DeleteTenantAsync(Tenant.TenantId); + await logger.LogInformation("Tenant Deleted {Tenant}", Tenant); + StateHasChanged(); + } + else + { + AddModuleMessage("Tenant Cannot Be Deleted Until The Following Sites Are Deleted: " + message.Substring(2), MessageType.Warning); + } } catch (Exception ex) { diff --git a/Oqtane.Client/Modules/Admin/Themes/Add.razor b/Oqtane.Client/Modules/Admin/Themes/Add.razor index bd243c9e..da47d8a9 100644 --- a/Oqtane.Client/Modules/Admin/Themes/Add.razor +++ b/Oqtane.Client/Modules/Admin/Themes/Add.razor @@ -5,117 +5,100 @@ @inject IThemeService ThemeService @inject IPackageService PackageService - - - - - -
- - - -
- - -@if (packages != null) +@if (_packages != null) { -
-

Available Themes

+ + @if (_packages.Count > 0) + { + + + +
+ Name + Version + +
+ + @context.Name + @context.Version + + + + +
+
+ } + + + + + + +
+ + + +
+
+
- -
- Name - Version - -
- - @context.Name - @context.Version - - - - -
-} - -@if (uploaded) -{ - -} + Cancel +} @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private List _packages; - bool uploaded = false; - List packages; - FileUpload fileupload; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { - List themes = await ThemeService.GetThemesAsync(); - packages = await PackageService.GetPackagesAsync("theme"); - foreach(Package package in packages.ToArray()) + try { - if (themes.Exists(item => Utilities.GetTypeName(item.ThemeName) == package.PackageId)) - { - packages.Remove(package); - } - } - } + var themes = await ThemeService.GetThemesAsync(); + _packages = await PackageService.GetPackagesAsync("theme"); - private async Task UploadTheme() - { - string[] files = await fileupload.GetFiles(); - if (files.Length > 0) - { - if (files[0].Contains(".Theme.")) + foreach (Package package in _packages.ToArray()) { - try + if (themes.Exists(item => Utilities.GetTypeName(item.ThemeName) == package.PackageId)) { - string result = await FileService.UploadFilesAsync("Themes", files, ""); - if (result == "") - { - await logger.LogInformation("Theme Uploaded {Package}", files[0]); - AddModuleMessage("Theme Uploaded Successfully. Click Install To Complete Installation.", MessageType.Success); - uploaded = true; - StateHasChanged(); - } - else - { - await logger.LogInformation("Theme Upload Failed For {Package}", result.Replace(",",", ")); - AddModuleMessage("Upload Failed For " + result.Replace(",",", ") + ". This Could Be Due To A Network Error Or Because A File Type Is Restricted.", MessageType.Error); - } + _packages.Remove(package); } - catch (Exception ex) - { - await logger.LogError(ex, "Theme Upload Failed {Package} {Error}", files[0], ex.Message); - AddModuleMessage("Theme Upload Failed", MessageType.Error); - } - } - else - { - await logger.LogError("Invalid Theme Package {Package}", files[0]); - AddModuleMessage("Invalid Theme Package", MessageType.Error); } } - else + catch (Exception ex) { - AddModuleMessage("You Must Select A Theme To Upload", MessageType.Warning); + await logger.LogError(ex, "Error Loading Packages {Error}", ex.Message); + AddModuleMessage("Error Loading Packages", MessageType.Error); } } private async Task InstallThemes() { - await ThemeService.InstallThemesAsync(); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + try + { + await ThemeService.InstallThemesAsync(); + NavigationManager.NavigateTo(NavigateUrl()); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Installating Theme"); + } } private async Task DownloadTheme(string packageid, string version) { - await PackageService.DownloadPackageAsync(packageid, version, "Themes"); - AddModuleMessage("Theme Downloaded Successfully. Click Install To Complete Installation.", MessageType.Success); - uploaded = true; - StateHasChanged(); + try + { + await PackageService.DownloadPackageAsync(packageid, version, "Themes"); + await logger.LogInformation("Theme {ThemeName} {Version} Downloaded Successfully", packageid, version); + AddModuleMessage("Themes Downloaded Successfully. Click Install To Complete Installation.", MessageType.Success); + StateHasChanged(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Downloading Module {ThemeName} {Version}", packageid, version); + AddModuleMessage("Error Downloading Theme", MessageType.Error); + } + } } -} diff --git a/Oqtane.Client/Modules/Admin/Themes/Index.razor b/Oqtane.Client/Modules/Admin/Themes/Index.razor index 501dec1b..4a3113b6 100644 --- a/Oqtane.Client/Modules/Admin/Themes/Index.razor +++ b/Oqtane.Client/Modules/Admin/Themes/Index.razor @@ -39,10 +39,10 @@ else } @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private List themes; + private List packages; - List themes; - List packages; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { @@ -52,12 +52,13 @@ else private bool UpgradeAvailable(string themename, string version) { - bool upgradeavailable = false; - Package package = packages.Where(item => item.PackageId == Utilities.GetTypeName(themename)).FirstOrDefault(); + var upgradeavailable = false; + var package = packages.Where(item => item.PackageId == Utilities.GetTypeName(themename)).FirstOrDefault(); if (package != null) { upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(version)) > 0); } + return upgradeavailable; } @@ -66,13 +67,13 @@ else await PackageService.DownloadPackageAsync(themename, version, "Themes"); await logger.LogInformation("Theme Downloaded {ThemeName} {Version}", themename, version); await ThemeService.InstallThemesAsync(); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + NavigationManager.NavigateTo(NavigateUrl()); } private async Task DeleteTheme(Theme Theme) { await ThemeService.DeleteThemeAsync(Theme.ThemeName); await logger.LogInformation("Theme Deleted {Theme}", Theme); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + NavigationManager.NavigateTo(NavigateUrl()); } } \ No newline at end of file diff --git a/Oqtane.Client/Modules/Admin/Upgrade/Index.razor b/Oqtane.Client/Modules/Admin/Upgrade/Index.razor index 2ae44820..7ee95e30 100644 --- a/Oqtane.Client/Modules/Admin/Upgrade/Index.razor +++ b/Oqtane.Client/Modules/Admin/Upgrade/Index.razor @@ -5,105 +5,66 @@ @inject IPackageService PackageService @inject IInstallationService InstallationService - - - - - -
- - - -
-@if (uploaded) +@if (_package != null) { - -} -else -{ - -} - -@if (upgradeavailable) -{ -
-

Upgrade Available

- - + + + @if (_upgradeavailable) + { + + @("Framework") @_package.Version + } + else + { + + } + + + + + + + +
+ + + +
+ +
+
} @code { - public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } + private Package _package; + private bool _upgradeavailable = false; - bool uploaded = false; - bool upgradeavailable = false; - FileUpload fileupload; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; protected override async Task OnInitializedAsync() { List packages = await PackageService.GetPackagesAsync("framework"); - Package package = packages.FirstOrDefault(); - if (package != null) + _package = packages.FirstOrDefault(); + if (_package != null) { - upgradeavailable = (Version.Parse(package.Version).CompareTo(Version.Parse(Constants.Version)) > 0); - } - if (!upgradeavailable) - { - AddModuleMessage("Framework Is Up To Date", MessageType.Info); - } - } - - private async Task UploadFile() - { - string[] files = await fileupload.GetFiles(); - if (files.Length > 0) - { - if (files[0].Contains(".Framework.")) - { - try - { - string result = await FileService.UploadFilesAsync("Framework", files, ""); - if (result == "") - { - await logger.LogInformation("Framework Uploaded {Package}", files[0]); - AddModuleMessage("Framework Uploaded Successfully. Click Upgrade To Complete Installation.", MessageType.Success); - uploaded = true; - StateHasChanged(); - } - else - { - await logger.LogInformation("Framework Upload Failed For {Package}", result.Replace(",",", ")); - AddModuleMessage("Upload Failed For " + result.Replace(",",", ") + ". This Could Be Due To A Network Error Or Because A File Type Is Restricted.", MessageType.Error); - } - } - catch (Exception ex) - { - await logger.LogError(ex, "Framework Upload Failed {Package} {Error}", files[0], ex.Message); - AddModuleMessage("Framework Upload Failed. " + ex.Message, MessageType.Error); - } - } - else - { - await logger.LogError("Invalid Framework Package {Package}", files[0]); - AddModuleMessage("Invalid Framework Package", MessageType.Error); - } + _upgradeavailable = (Version.Parse(_package.Version).CompareTo(Version.Parse(Constants.Version)) > 0); } else { - AddModuleMessage("You Must Select A Framework Package To Upload", MessageType.Warning); + _package = new Package { Name = Constants.PackageId, Version = Constants.Version }; } } private async Task Upgrade() { await InstallationService.Upgrade(); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + NavigationManager.NavigateTo(NavigateUrl()); } private async Task Download(string packageid, string version) { await PackageService.DownloadPackageAsync(packageid, version, "Framework"); await InstallationService.Upgrade(); - NavigationManager.NavigateTo(NavigateUrl(Reload.Application)); + NavigationManager.NavigateTo(NavigateUrl()); } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor index a5c3656f..e6ae6b68 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor @@ -9,10 +9,10 @@
- + - @if (userroles != null) { @@ -26,18 +26,18 @@
- + - +
- + - + } + else + { + + } + + + @code { + private ElementReference _editorElement; + private ElementReference _toolBar; + private bool _filemanagervisible = false; + private FileManager _fileManager; + private string _content = string.Empty; + private string _original = string.Empty; + private string _message = string.Empty; + + [Parameter] + public string Content { get; set; } + + [Parameter] + public bool ReadOnly { get; set; } = false; + + [Parameter] + public string Placeholder { get; set; } = "Enter Your Content..."; + + // parameters only applicable to rich text editor [Parameter] public RenderFragment ToolbarContent { get; set; } [Parameter] - public bool ReadOnly { get; set; } - = false; + public string Theme { get; set; } = "snow"; [Parameter] - public string Placeholder { get; set; } - = "Compose an epic..."; + public string DebugLevel { get; set; } = "info"; - [Parameter] - public string Theme { get; set; } - = "snow"; + protected override void OnInitialized() + { + _content = Content; // raw HTML + } - [Parameter] - public string DebugLevel { get; set; } - = "info"; - - private ElementReference EditorElement; - private ElementReference ToolBar; - - protected override async Task - OnAfterRenderAsync(bool firstRender) + protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { - await RichTextEditorInterop.CreateEditor( - JSRuntime, - EditorElement, - ToolBar, + var interop = new RichTextEditorInterop(JsRuntime); + + await interop.CreateEditor( + _editorElement, + _toolBar, ReadOnly, Placeholder, Theme, DebugLevel); + + await interop.LoadEditorContent(_editorElement, Content); + + // preserve a copy of the rich text content ( Quill sanitizes content so we need to retrieve it from the editor ) + _original = await interop.GetHtml(_editorElement); } } - public async Task GetText() + public void CloseFileManager() { - return await RichTextEditorInterop.GetText( - JSRuntime, - EditorElement); + _filemanagervisible = false; + _message = string.Empty; + StateHasChanged(); } - public async Task GetHTML() + public async Task RefreshRichText() { - return await RichTextEditorInterop.GetHTML( - JSRuntime, - EditorElement); + var interop = new RichTextEditorInterop(JsRuntime); + await interop.LoadEditorContent(_editorElement, _content); + } + + public async Task RefreshRawHtml() + { + var interop = new RichTextEditorInterop(JsRuntime); + _content = await interop.GetHtml(_editorElement); + StateHasChanged(); + } + + public async Task GetHtml() + { + // get rich text content + var interop = new RichTextEditorInterop(JsRuntime); + string content = await interop.GetHtml(_editorElement); + + if (_original != content) + { + // rich text content has changed - return it + return content; + } + else + { + // return raw html content + return _content; + } + } + + public async Task InsertImage() + { + if (_filemanagervisible) + { + var fileid = _fileManager.GetFileId(); + if (fileid != -1) + { + var interop = new RichTextEditorInterop(JsRuntime); + await interop.InsertImage(_editorElement, ContentUrl(fileid)); + _filemanagervisible = false; + _message = string.Empty; + } + else + { + _message = "
You Must Select An Image To Insert
"; + } + } + else + { + _filemanagervisible = true; + _message = string.Empty; + } + StateHasChanged(); + } + + // other rich text editor methods which can be used by developers + public async Task GetText() + { + var interop = new RichTextEditorInterop(JsRuntime); + return await interop.GetText(_editorElement); } public async Task GetContent() { - return await RichTextEditorInterop.GetContent( - JSRuntime, - EditorElement); - } - - public async Task LoadContent(string Content) - { - await RichTextEditorInterop.LoadEditorContent( - JSRuntime, - EditorElement, Content); + var interop = new RichTextEditorInterop(JsRuntime); + return await interop.GetContent(_editorElement); } public async Task EnableEditor(bool mode) { - await RichTextEditorInterop.EnableEditor( - JSRuntime, - EditorElement, mode); + var interop = new RichTextEditorInterop(JsRuntime); + await interop.EnableEditor(_editorElement, mode); } - - public async Task InsertImage(string ImageURL) - { - await RichTextEditorInterop.InsertImage( - JSRuntime, - EditorElement, ImageURL); - } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs b/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs new file mode 100644 index 00000000..a5bd4ffa --- /dev/null +++ b/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs @@ -0,0 +1,124 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Threading.Tasks; + +namespace Oqtane.Modules.Controls +{ + public class RichTextEditorInterop + { + private readonly IJSRuntime _jsRuntime; + + public RichTextEditorInterop(IJSRuntime jsRuntime) + { + _jsRuntime = jsRuntime; + } + + public Task CreateEditor( + ElementReference quillElement, + ElementReference toolbar, + bool readOnly, + string placeholder, + string theme, + string debugLevel) + { + try + { + _jsRuntime.InvokeAsync( + "Oqtane.RichTextEditor.createQuill", + quillElement, toolbar, readOnly, + placeholder, theme, debugLevel); + return Task.CompletedTask; + } + catch + { + return Task.CompletedTask; + } + } + + public ValueTask GetText(ElementReference quillElement) + { + try + { + return _jsRuntime.InvokeAsync( + "Oqtane.RichTextEditor.getQuillText", + quillElement); + } + catch + { + return new ValueTask(Task.FromResult(string.Empty)); + } + } + + public ValueTask GetHtml(ElementReference quillElement) + { + try + { + return _jsRuntime.InvokeAsync( + "Oqtane.RichTextEditor.getQuillHTML", + quillElement); + } + catch + { + return new ValueTask(Task.FromResult(string.Empty)); + } + } + + public ValueTask GetContent(ElementReference quillElement) + { + try + { + return _jsRuntime.InvokeAsync( + "Oqtane.RichTextEditor.getQuillContent", + quillElement); + } + catch + { + return new ValueTask(Task.FromResult(string.Empty)); + } + } + + public Task LoadEditorContent(ElementReference quillElement, string content) + { + try + { + _jsRuntime.InvokeAsync( + "Oqtane.RichTextEditor.loadQuillContent", + quillElement, content); + return Task.CompletedTask; + } + catch + { + return Task.CompletedTask; + } + } + + public Task EnableEditor(ElementReference quillElement, bool mode) + { + try + { + _jsRuntime.InvokeAsync( + "Oqtane.RichTextEditor.enableQuillEditor", quillElement, mode); + return Task.CompletedTask; + } + catch + { + return Task.CompletedTask; + } + } + + public Task InsertImage(ElementReference quillElement, string imageUrl) + { + try + { + _jsRuntime.InvokeAsync( + "Oqtane.RichTextEditor.insertQuillImage", + quillElement, imageUrl); + return Task.CompletedTask; + } + catch + { + return Task.CompletedTask; + } + } + } +} diff --git a/Oqtane.Client/Modules/Controls/Section.razor b/Oqtane.Client/Modules/Controls/Section.razor new file mode 100644 index 00000000..4f33b42f --- /dev/null +++ b/Oqtane.Client/Modules/Controls/Section.razor @@ -0,0 +1,45 @@ +@namespace Oqtane.Modules.Controls +@inherits ModuleBase +@attribute [OqtaneIgnore] + + +
+
+
+
+ @ChildContent +
+ +@code { + private string _heading = string.Empty; + private string _expanded = string.Empty; + + [Parameter] + public RenderFragment ChildContent { get; set; } + + [Parameter] + public string Name { get; set; } // required - the name of the section + + [Parameter] + public string Heading { get; set; } // optional - will default to Name if not provided + + [Parameter] + public string Expanded { get; set; } // optional - will default to false if not provided + + protected override void OnInitialized() + { + _heading = (!string.IsNullOrEmpty(Heading)) ? Heading : Name; + _expanded = (!string.IsNullOrEmpty(Expanded)) ? Expanded : "false"; + } +} diff --git a/Oqtane.Client/Modules/Controls/TabControl.razor b/Oqtane.Client/Modules/Controls/TabControl.razor deleted file mode 100644 index e6cda943..00000000 --- a/Oqtane.Client/Modules/Controls/TabControl.razor +++ /dev/null @@ -1,43 +0,0 @@ -@namespace Oqtane.Modules.Controls -@inherits ModuleBase - - -
- @foreach (TabPanel tabPanel in TabPanels) - { - - } -
- @ChildContent -
- -@code { - // Next line is needed so we are able to add components inside - [Parameter] - public RenderFragment ChildContent { get; set; } - - public TabPanel ActiveTabPanel { get; set; } - List TabPanels = new List(); - - internal void AddTabPanel(TabPanel tabPanel) - { - TabPanels.Add(tabPanel); - if (TabPanels.Count == 1) - ActiveTabPanel = tabPanel; - StateHasChanged(); - } - - string GetButtonClass(TabPanel tabPanel) - { - return tabPanel == ActiveTabPanel ? "btn-primary" : "btn-secondary"; - } - - void ActivateTabPanel(TabPanel tabPanel) - { - ActiveTabPanel = tabPanel; - } -} diff --git a/Oqtane.Client/Modules/Controls/TabPanel.razor b/Oqtane.Client/Modules/Controls/TabPanel.razor index 475d6258..bd89ab59 100644 --- a/Oqtane.Client/Modules/Controls/TabPanel.razor +++ b/Oqtane.Client/Modules/Controls/TabPanel.razor @@ -1,27 +1,36 @@ @namespace Oqtane.Modules.Controls -@inherits ModuleBase +@inherits ModuleBase +@attribute [OqtaneIgnore] -@if (Parent.ActiveTabPanel == (TabPanel)(object)this) +@if (Name == Parent.ActiveTab) { - @ChildContent +
+ @ChildContent +
+} +else +{ +
+ @ChildContent +
} @code { [CascadingParameter] - private TabControl Parent { get; set; } + private TabStrip Parent { get; set; } [Parameter] public RenderFragment ChildContent { get; set; } [Parameter] - public string Text { get; set; } + public string Name { get; set; } // required - name of the TabPanel + + [Parameter] + public string Heading { get; set; } // optional - defaults to name if not specified protected override void OnInitialized() { - if (Parent == null) - throw new ArgumentNullException(nameof(Parent), "TabPanel must exist within a TabControl"); - base.OnInitialized(); - Parent.AddTabPanel((TabPanel)(object)this); + Parent.AddTabPanel((TabPanel)this); } } diff --git a/Oqtane.Client/Modules/Controls/TabStrip.razor b/Oqtane.Client/Modules/Controls/TabStrip.razor new file mode 100644 index 00000000..8d8d3838 --- /dev/null +++ b/Oqtane.Client/Modules/Controls/TabStrip.razor @@ -0,0 +1,66 @@ +@namespace Oqtane.Modules.Controls +@inherits ModuleBase +@attribute [OqtaneIgnore] + + +
+
+ +
+
+ @ChildContent +
+
+
+
+ +@code { + private List _tabPanels = new List(); + + [Parameter] + public RenderFragment ChildContent { get; set; } // contains the TabPanels + + [Parameter] + public string ActiveTab { get; set; } // optional - defaults to first TabPanel if not specified. Can also be set using a "tab=" querystring parameter. + + protected override void OnInitialized() + { + if (PageState.QueryString.ContainsKey("tab")) + { + ActiveTab = PageState.QueryString["tab"]; + } + } + + internal void AddTabPanel(TabPanel tabPanel) + { + _tabPanels.Add(tabPanel); + if (string.IsNullOrEmpty(ActiveTab)) + { + ActiveTab = tabPanel.Name; + } + StateHasChanged(); + } + + private string DisplayHeading(string Name, string Heading) + { + return (string.IsNullOrEmpty(Heading)) ? Name : Heading; + } +} diff --git a/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor b/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor index c8881f3f..3c056d87 100644 --- a/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor +++ b/Oqtane.Client/Modules/Controls/TriStateCheckBox.razor @@ -1,8 +1,12 @@ @namespace Oqtane.Modules.Controls - + @code { + private bool? _value = null; + private string _title; + private string _src = string.Empty; + [Parameter] public bool? Value { get; set; } @@ -12,51 +16,52 @@ [Parameter] public Action OnChange { get; set; } - bool? value = null; - string title; - string src = ""; - protected override void OnInitialized() { - value = Value; + _value = Value; SetImage(); } private void SetValue() { - switch (value) + if (!Disabled) { - case true: - value = false; - break; - case false: - value = null; - break; - case null: - value = true; - break; + switch (_value) + { + case true: + _value = false; + break; + case false: + _value = null; + break; + case null: + _value = true; + break; + } + + SetImage(); + OnChange(_value); } - SetImage(); - OnChange(value); } private void SetImage() { - switch (value) + switch (_value) { case true: - src = "images/checked.png"; - title = "Permission Granted"; + _src = "images/checked.png"; + _title = "Permission Granted"; break; case false: - src = "images/unchecked.png"; - title = "Permission Denied"; + _src = "images/unchecked.png"; + _title = "Permission Denied"; break; case null: - src = "images/null.png"; - title = ""; + _src = "images/null.png"; + _title = string.Empty; break; } + StateHasChanged(); } } diff --git a/Oqtane.Client/Modules/Counter/Index.razor b/Oqtane.Client/Modules/Counter/Index.razor deleted file mode 100644 index b511cfc0..00000000 --- a/Oqtane.Client/Modules/Counter/Index.razor +++ /dev/null @@ -1,16 +0,0 @@ -@namespace Oqtane.Modules.Counter -@inherits ModuleBase -Current count: @currentCount -
- -
-
- -@code { - int currentCount = 0; - - void IncrementCount() - { - currentCount++; - } -} diff --git a/Oqtane.Client/Modules/Counter/Module.cs b/Oqtane.Client/Modules/Counter/Module.cs deleted file mode 100644 index 5f509ae2..00000000 --- a/Oqtane.Client/Modules/Counter/Module.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; - -namespace Oqtane.Modules.Counter -{ - public class Module : IModule - { - public Dictionary Properties - { - get - { - Dictionary properties = new Dictionary - { - { "Name", "Counter" }, - { "Description", "Increments a counter" }, - { "Version", "1.0.0" } - }; - return properties; - } - } - } -} diff --git a/Oqtane.Client/Modules/HtmlText/Edit.razor b/Oqtane.Client/Modules/HtmlText/Edit.razor index 0fb17a96..292706e2 100644 --- a/Oqtane.Client/Modules/HtmlText/Edit.razor +++ b/Oqtane.Client/Modules/HtmlText/Edit.razor @@ -3,154 +3,94 @@ @using Oqtane.Modules.Controls @namespace Oqtane.Modules.HtmlText @inherits ModuleBase +@inject IHtmlTextService HtmlTextService @inject NavigationManager NavigationManager -@inject HttpClient http -@inject SiteState sitestate - - - -
- - - @if (!RichTextEditorMode) +@if (_content != null) +{ + + + Cancel + @if (!string.IsNullOrEmpty(_content)) + { +
+
+ + } +} + +@code { + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit; + + public override string Title => "Edit Html/Text"; + + public override List Resources => new List() + { + new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }, + // the following resources should be declared in the RichTextEditor component however the framework currently only supports resource management for modules and themes + new Resource { ResourceType = ResourceType.Stylesheet, Url = "css/quill/quill1.3.6.bubble.css" }, + new Resource { ResourceType = ResourceType.Stylesheet, Url = "css/quill/quill1.3.6.snow.css" }, + new Resource { ResourceType = ResourceType.Script, Url = "js/quill1.3.6.min.js" }, + new Resource { ResourceType = ResourceType.Script, Url = "js/quill-blot-formatter.min.js" }, + new Resource { ResourceType = ResourceType.Script, Url = "js/quill-interop.js" } + }; + + private RichTextEditor RichTextEditorHtml; + private string _content = null; + private string _createdby; + private DateTime _createdon; + private string _modifiedby; + private DateTime _modifiedon; + + protected override async Task OnInitializedAsync() + { + try + { + var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId); + if (htmltext != null) { -