Merge pull request #251 from sbwalker/master

module load error handler, router optimizaton, relative paths, fixed add existing module control panel issue
This commit is contained in:
Shaun Walker
2020-03-04 13:23:24 -05:00
committed by GitHub
10 changed files with 242 additions and 199 deletions

View File

@ -0,0 +1,18 @@
@namespace Oqtane.Modules.Admin.Error
@inherits ModuleBase
@inject IModuleService ModuleService
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return 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);
}
}

View File

@ -5,9 +5,25 @@
@inject IModuleService ModuleService @inject IModuleService ModuleService
@inject IPageService PageService @inject IPageService PageService
<TabControl> <div class="container-fluid">
<TabPanel Text="Pages"> <div class="form-group">
@if (pages.Count == 0)
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#Pages" role="tab">
Pages
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#Modules" role="tab">
Modules
</a>
</li>
</ul>
<div class="tab-content">
<div id="Pages" class="tab-pane fade show active" role="tabpanel">
@if (pages == null)
{ {
<br /> <br />
<p>No Deleted Pages</p> <p>No Deleted Pages</p>
@ -16,65 +32,65 @@
{ {
<Pager Items="@pages"> <Pager Items="@pages">
<Header> <Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Name</th> <th>Name</th>
<th>Deleted By</th> <th>Deleted By</th>
<th>Deleted On</th> <th>Deleted On</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</Header> </Header>
<Row> <Row>
<td><button @onclick="@(() => RestorePage(context))" class="btn btn-info" title="Restore">Restore</button></td>
<td><ActionDialog Header="Delete Page" Message="@("Are You Sure You Wish To Permanently Delete The " + context.Name + " Page?")" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeletePage(context))" /></td>
<td>@context.Name</td> <td>@context.Name</td>
<td>@context.DeletedBy</td> <td>@context.DeletedBy</td>
<td>@context.DeletedOn</td> <td>@context.DeletedOn</td>
<td><button @onclick="@(() => RestorePage(context))" class="btn btn-info" title="Restore">Restore</button></td>
<td><button @onclick="@(() => DeletePage(context.PageId))" class="btn btn-danger">Delete</button></td>
</Row> </Row>
</Pager> </Pager>
} }
</TabPanel> </div>
<TabPanel Text="Modules"> <div id="Modules" class="tab-pane fade" role="tabpanel">
@if (pageModules.Count == 0) @if (modules == null)
{ {
<br /> <br />
<p>No Deleted Modules</p> <p>No Deleted Modules</p>
} }
else else
{ {
<Pager Items="@pageModules"> <Pager Items="@modules">
<Header> <Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Page</th> <th>Page</th>
<th>Module</th> <th>Module</th>
<th>Deleted By</th> <th>Deleted By</th>
<th>Deleted On</th> <th>Deleted On</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</Header> </Header>
<Row> <Row>
<td><button @onclick="@(() => RestoreModule(context))" class="btn btn-info" title="Restore">Restore</button></td>
<td><ActionDialog Header="Delete Module" Message="@("Are You Sure You Wish To Permanently Delete The " + context.Title + " Module?")" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteModule(context))" /></td>
<td>@PageState.Pages.Find(item => item.PageId == context.PageId).Name</td> <td>@PageState.Pages.Find(item => item.PageId == context.PageId).Name</td>
<td>@context.Title</td> <td>@context.Title</td>
<td>@context.DeletedBy</td> <td>@context.DeletedBy</td>
<td>@context.DeletedOn</td> <td>@context.DeletedOn</td>
<td><button @onclick="@(() => RestorePageModule(context))" class="btn btn-info" title="Restore">Restore</button></td>
<td><button @onclick="@(() => DeletePageModule(context.PageModuleId, context.ModuleId))" class="btn btn-danger">Delete</button></td>
</Row> </Row>
</Pager> </Pager>
} }
</TabPanel> </div>
</TabControl> </div>
</div>
</div>
@code { @code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
List<Page> pages { get; set; } List<Page> pages;
List<PageModule> pageModules { get; set; } List<Module> modules;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
try try
{ {
pages = new List<Page>(); await Load();
pageModules = new List<PageModule>();
await LoadEntities();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -83,19 +99,13 @@
} }
} }
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();
private async Task LoadEntities() modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
{ modules = modules.Where(item => item.IsDeleted).ToList();
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)
@ -105,6 +115,8 @@
Page.IsDeleted = false; Page.IsDeleted = false;
await PageService.UpdatePageAsync(Page); await PageService.UpdatePageAsync(Page);
await logger.LogInformation("Page Restored {Page}", Page); await logger.LogInformation("Page Restored {Page}", Page);
await Load();
StateHasChanged();
NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
} }
catch (Exception ex) catch (Exception ex)
@ -114,61 +126,60 @@
} }
} }
private async Task DeletePage(int PageId) private async Task DeletePage(Page Page)
{ {
try try
{ {
var deletedPageModules = PageState.Modules.Where(item => item.PageId == PageId); await PageService.DeletePageAsync(Page.PageId);
await PageService.DeletePageAsync(PageId); await logger.LogInformation("Page Permanently Deleted {Page}", Page);
foreach (var module in deletedPageModules) await Load();
{ StateHasChanged();
await ModuleService.DeleteModuleAsync(module.ModuleId);
}
await logger.LogInformation("Page Permanently Deleted {PageId}", PageId);
NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
} }
catch (Exception ex) 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); AddModuleMessage(ex.Message, MessageType.Error);
} }
} }
private async Task RestorePageModule(PageModule PageModule) private async Task RestoreModule(Module Module)
{ {
try try
{ {
PageModule.IsDeleted = false; PageModule pagemodule = await PageModuleService.GetPageModuleAsync(Module.PageModuleId);
await PageModuleService.UpdatePageModuleAsync(PageModule); pagemodule.IsDeleted = false;
await LoadEntities(); await PageModuleService.UpdatePageModuleAsync(pagemodule);
await logger.LogInformation("Page Module Restored {PageModule}", PageModule); await logger.LogInformation("Module Restored {Module}", Module);
NavigationManager.NavigateTo(NavigateUrl(Reload.Site)); await Load();
StateHasChanged();
} }
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError(ex, "Error Restoring Deleted Page Module {PageModule} {Error}", PageModule, ex.Message); await logger.LogError(ex, "Error Restoring Deleted Module {Module} {Error}", Module, ex.Message);
AddModuleMessage("Error Restoring Deleted Page Module", MessageType.Error); AddModuleMessage("Error Restoring Deleted Module", MessageType.Error);
} }
} }
private async Task DeletePageModule(int PageModuleId, int ModuleId) private async Task DeleteModule(Module Module)
{ {
try try
{ {
await PageModuleService.DeletePageModuleAsync(PageModuleId); await PageModuleService.DeletePageModuleAsync(Module.PageModuleId);
if (PageState.Modules.Count(item => item.ModuleId == ModuleId) == 1) // 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 logger.LogInformation("Module Permanently Deleted {Module}", Module);
await LoadEntities(); await Load();
await logger.LogInformation("Page Module Permanently Deleted {PageModuleId}", PageModuleId); StateHasChanged();
NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
} }
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError(ex, "Error Permanently Deleting Page Module {PageModuleId} {Error}", PageModuleId, ex.Message); await logger.LogError(ex, "Error Permanently Deleting Module {Module} {Error}", Module, ex.Message);
AddModuleMessage("Error Permanently Deleting Page Module", MessageType.Error); AddModuleMessage("Error Permanently Deleting Module", MessageType.Error);
} }
} }
} }

View File

@ -133,6 +133,8 @@ else
content = await this.RichTextEditorHtml.GetHTML(); content = await this.RichTextEditorHtml.GetHTML();
} }
content = content.Replace(((PageState.Alias.Path == "") ? "/~" : PageState.Alias.Path) + Constants.ContentUrl, Constants.ContentUrl);
try try
{ {
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, NavigationManager); HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, NavigationManager);

View File

@ -13,7 +13,7 @@
<br /><br /> <br /><br />
@code { @code {
string content; string content = "";
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
@ -24,6 +24,7 @@
if (htmltext != null) if (htmltext != null)
{ {
content = htmltext.Content; content = htmltext.Content;
content = content.Replace(Constants.ContentUrl, ((PageState.Alias.Path == "") ? "/~" : PageState.Alias.Path) + Constants.ContentUrl);
} }
} }
catch (Exception ex) catch (Exception ex)

View File

@ -104,13 +104,9 @@ namespace Oqtane.Modules
public string ContentUrl(int fileid) public string ContentUrl(int fileid)
{ {
string apiurl = PageState.Uri.Scheme + "://" + PageState.Alias.Name + "/"; string url = (PageState.Alias.Path == "") ? "/~" : PageState.Alias.Path;
if (PageState.Alias.Path == "") url += Constants.ContentUrl + fileid.ToString();
{ return url;
apiurl += "~/";
}
apiurl += "api/File/Download/" + fileid.ToString();
return apiurl;
} }
// user feedback methods // user feedback methods

View File

@ -355,7 +355,17 @@
Dictionary<string, int> paneindex = new Dictionary<string, int>(); Dictionary<string, int> paneindex = new Dictionary<string, int>();
foreach (Module module in modules) foreach (Module module in modules)
{ {
string typename = module.ModuleDefinition.ControlTypeTemplate; if (module.PageId == pageid || module.ModuleId == moduleid)
{
string typename = "";
if (module.ModuleDefinition != null)
{
typename = module.ModuleDefinition.ControlTypeTemplate;
}
else
{
typename = Constants.ErrorModule;
}
if (module.ModuleId == moduleid && control != "") if (module.ModuleId == moduleid && control != "")
{ {
// check if the module defines custom routes // check if the module defines custom routes
@ -396,9 +406,6 @@
module.ModuleType = typename.Replace(Constants.ActionToken, Constants.DefaultAction); module.ModuleType = typename.Replace(Constants.ActionToken, Constants.DefaultAction);
} }
if (module.PageId == pageid)
{
// ensure module's pane exists in current page and if not, assign it to the Admin pane // ensure module's pane exists in current page and if not, assign it to the Admin pane
if (panes == null || !panes.ToLower().Contains(module.Pane.ToLower())) if (panes == null || !panes.ToLower().Contains(module.Pane.ToLower()))
{ {
@ -415,21 +422,18 @@
paneindex.Add(module.Pane, 0); paneindex.Add(module.Pane, 0);
} }
module.PaneModuleIndex = paneindex[module.Pane]; module.PaneModuleIndex = paneindex[module.Pane];
}
if (string.IsNullOrEmpty(module.ContainerType)) if (string.IsNullOrEmpty(module.ContainerType))
{ {
module.ContainerType = defaultcontainertype; module.ContainerType = defaultcontainertype;
} }
} }
}
foreach (Module module in modules) foreach (Module module in modules.Where(item => item.PageId == pageid))
{
if (module.PageId == pageid)
{ {
module.PaneModuleCount = paneindex[module.Pane] + 1; module.PaneModuleCount = paneindex[module.Pane] + 1;
} }
}
return modules; return modules;
} }

View File

@ -202,7 +202,7 @@
List<ModuleDefinition> ModuleDefinitions; List<ModuleDefinition> ModuleDefinitions;
List<ModuleDefinition> moduledefinitions; List<ModuleDefinition> moduledefinitions;
List<Page> pages = new List<Page>(); List<Page> pages = new List<Page>();
string pageid = ""; string pageid = "-";
string moduleid = "-"; string moduleid = "-";
List<Module> modules = new List<Module>(); List<Module> modules = new List<Module>();
Dictionary<string, string> containers = new Dictionary<string, string>(); Dictionary<string, string> containers = new Dictionary<string, string>();
@ -285,7 +285,7 @@
{ {
pageid = (string)e.Value; pageid = (string)e.Value;
modules?.Clear(); modules?.Clear();
if (pageid != "") if (pageid != "-")
{ {
foreach (Module module in PageState.Modules.Where(item => item.PageId == int.Parse(pageid) && !item.IsDeleted)) foreach (Module module in PageState.Modules.Where(item => item.PageId == int.Parse(pageid) && !item.IsDeleted))
{ {
@ -301,7 +301,9 @@
private async Task AddModule() private async Task AddModule()
{ {
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions) && !string.IsNullOrWhiteSpace(moduledefinitionname) && moduledefinitionname != "-") if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{
if ((moduletype == "new" && moduledefinitionname != "-") || (moduletype != "new" && moduleid != "-"))
{ {
if (moduletype == "new") if (moduletype == "new")
{ {
@ -315,7 +317,7 @@
} }
PageModule pagemodule = new PageModule(); PageModule pagemodule = new PageModule();
pagemodule.PageId = string.IsNullOrEmpty(pageid) ? PageState.Page.PageId : int.Parse(pageid); pagemodule.PageId = (pageid != "-") ? PageState.Page.PageId : int.Parse(pageid);
pagemodule.ModuleId = int.Parse(moduleid); pagemodule.ModuleId = int.Parse(moduleid);
pagemodule.Title = title; pagemodule.Title = title;
if (pagemodule.Title == "") if (pagemodule.Title == "")
@ -347,10 +349,20 @@
pane = ""; pane = "";
title = ""; title = "";
containertype = ""; containertype = "";
pageid = "-";
moduleid = "-"; moduleid = "-";
NavigationManager.NavigateTo(NavigateUrl(Reload.Page)); NavigationManager.NavigateTo(NavigateUrl(Reload.Page));
} }
else
{
message = "<br /><div class=\"alert alert-warning\" role=\"alert\">You Must Select A Module</div>";
}
}
else
{
message = "<br /><div class=\"alert alert-error\" role=\"alert\">Not Authorized</div>";
}
} }
private async Task ToggleEditMode(bool EditMode) private async Task ToggleEditMode(bool EditMode)

View File

@ -31,7 +31,7 @@
{ {
actions = new List<ActionViewModel>(); actions = new List<ActionViewModel>();
actions.Add(new ActionViewModel { Action = "settings", Name = "Manage Settings" }); actions.Add(new ActionViewModel { Action = "settings", Name = "Manage Settings" });
if (ModuleState.ModuleDefinition.ServerAssemblyName != "") if (ModuleState.ModuleDefinition != null && ModuleState.ModuleDefinition.ServerAssemblyName != "")
{ {
actions.Add(new ActionViewModel { Action = "import", Name = "Import Content" }); actions.Add(new ActionViewModel { Action = "import", Name = "Import Content" });
actions.Add(new ActionViewModel { Action = "export", Name = "Export Content" }); actions.Add(new ActionViewModel { Action = "export", Name = "Export Content" });

View File

@ -55,13 +55,9 @@ namespace Oqtane.Themes
public string ContentUrl(int fileid) public string ContentUrl(int fileid)
{ {
string apiurl = PageState.Uri.Scheme + "://" + PageState.Alias.Name + "/"; string url = (PageState.Alias.Path == "") ? "/~" : PageState.Alias.Path;
if (PageState.Alias.Path == "") url += Constants.ContentUrl + fileid.ToString();
{ return url;
apiurl += "~/";
}
apiurl += "api/File/Download/" + fileid.ToString();
return apiurl;
} }
} }
} }

View File

@ -23,8 +23,11 @@
public const string AdminDashboardModule = "Oqtane.Modules.Admin.Dashboard, Oqtane.Client"; public const string AdminDashboardModule = "Oqtane.Modules.Admin.Dashboard, Oqtane.Client";
public const string PageManagementModule = "Oqtane.Modules.Admin.Pages, Oqtane.Client"; public const string PageManagementModule = "Oqtane.Modules.Admin.Pages, Oqtane.Client";
public const string ErrorModule = "Oqtane.Modules.Admin.Error.{Action}, Oqtane.Client";
public const string ModuleMessageComponent = "Oqtane.Modules.Controls.ModuleMessage, Oqtane.Client"; public const string ModuleMessageComponent = "Oqtane.Modules.Controls.ModuleMessage, Oqtane.Client";
public const string ContentUrl = "/api/file/download/";
public const string HostUser = "host"; public const string HostUser = "host";
public const string AllUsersRole = "All Users"; public const string AllUsersRole = "All Users";