Module ordering improvements

This commit is contained in:
Shaun Walker
2019-09-10 09:56:42 -04:00
parent f60898dbc7
commit 2a691dbceb
12 changed files with 229 additions and 152 deletions

View File

@ -1,5 +1,6 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules
@using Oqtane.Client.Modules.Controls
@using Oqtane.Client.Modules.HtmlText.Services
@using Oqtane.Shared.Modules.HtmlText.Models
@using System.Net.Http;
@ -9,54 +10,79 @@
@inject HttpClient http
@inject SiteState sitestate
<form>
<table class="form-group">
<tr>
<td>
<label for="Name" class="control-label">Content: </label>
</td>
<td>
<textarea class="form-control" @bind="@content" rows="5" style="width:400px;" />
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="@SaveContent">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
</form>
<ModuleMessage Message="@message" />
<table class="form-group">
<tr>
<td>
<label for="Name" class="control-label">Content: </label>
</td>
<td>
<textarea class="form-control" @bind="@content" rows="5" style="width:400px;" />
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="@SaveContent">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br /><br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } }
public override string Title { get { return "Edit Html/Text"; } }
string message = "";
string content;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override async Task OnInitializedAsync()
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
try
{
content = htmltext.Content;
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
content = htmltext.Content;
createdby = htmltext.CreatedBy;
createdon = htmltext.CreatedOn;
modifiedby = htmltext.ModifiedBy;
modifiedon = htmltext.ModifiedOn;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task SaveContent()
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
try
{
htmltext.Content = content;
await htmltextservice.UpdateHtmlTextAsync(htmltext);
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
htmltext.Content = content;
await htmltextservice.UpdateHtmlTextAsync(htmltext);
}
else
{
htmltext = new HtmlTextInfo();
htmltext.ModuleId = ModuleState.ModuleId;
htmltext.Content = content;
await htmltextservice.AddHtmlTextAsync(htmltext);
}
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(NavigateUrl());
}
else
catch (Exception ex)
{
htmltext = new HtmlTextInfo();
htmltext.ModuleId = ModuleState.ModuleId;
htmltext.Content = content;
await htmltextservice.AddHtmlTextAsync(htmltext);
message = ex.Message;
}
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(NavigateUrl());
}
}

View File

@ -9,20 +9,30 @@
@inject HttpClient http
@inject SiteState sitestate
<ModuleMessage Message="@message" />
@((MarkupString)content)
<br /><ActionLink Action="Edit" /><br /><br />
@code {
string message = "";
string content;
protected override async Task OnParametersSetAsync()
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
try
{
content = htmltext.Content;
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
content = htmltext.Content;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
}

View File

@ -10,6 +10,7 @@ namespace Oqtane.Services
Task<PageModule> GetPageModuleAsync(int PageModuleId);
Task<PageModule> AddPageModuleAsync(PageModule PageModule);
Task<PageModule> UpdatePageModuleAsync(PageModule PageModule);
Task UpdatePageModuleOrderAsync(int PageId, string Pane);
Task DeletePageModuleAsync(int PageModuleId);
}
}

View File

@ -46,6 +46,11 @@ namespace Oqtane.Services
return await http.PutJsonAsync<PageModule>(apiurl + "/" + PageModule.PageModuleId.ToString(), PageModule);
}
public async Task UpdatePageModuleOrderAsync(int PageId, string Pane)
{
await http.PutJsonAsync(apiurl + "/?pageid=" + PageId.ToString() + "&pane=" + Pane, null);
}
public async Task DeletePageModuleAsync(int PageModuleId)
{
await http.DeleteAsync(apiurl + "/" + PageModuleId.ToString());

View File

@ -13,45 +13,34 @@
[Parameter]
public Module Module { get; set; }
Module ModuleState;
string container;
RenderFragment DynamicComponent { get; set; }
Module ModuleState;
protected override void OnParametersSet()
{
ModuleState = Module; // passed in from Pane component
string container = ModuleState.ContainerType;
if (PageState.ModuleId != -1 && PageState.Control != "" && ModuleState.UseAdminContainer)
{
container = Constants.DefaultAdminContainer;
}
DynamicComponent = builder =>
{
if (ModuleState != null)
Type containerType = Type.GetType(container);
if (containerType != null)
{
Type containerType = Type.GetType(container);
if (containerType != null)
{
builder.OpenComponent(0, containerType);
builder.CloseComponent();
}
else
{
// container does not exist with type specified
builder.OpenComponent(0, Type.GetType(Constants.ModuleMessageControl));
builder.AddAttribute(1, "Message", "Error Loading Module Container " + container);
builder.CloseComponent();
}
builder.OpenComponent(0, containerType);
builder.CloseComponent();
}
else
{
// container does not exist with type specified
builder.OpenComponent(0, Type.GetType(Constants.ModuleMessageControl));
builder.AddAttribute(1, "Message", "Error Loading Module Container " + container);
builder.CloseComponent();
}
};
}
protected override Task OnParametersSetAsync()
{
if (PageState.Page.PageId == Module.PageId)
{
ModuleState = Module; // passed in from Pane component
container = ModuleState.ContainerType;
if (PageState.ModuleId != -1 && PageState.Control != "" && ModuleState.UseAdminContainer)
{
container = Constants.DefaultAdminContainer;
}
}
return Task.CompletedTask;
}
}

View File

@ -1,5 +1,6 @@
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Shared
@inject IUriHelper UriHelper
@inject IInstallationService InstallationService
@inject IUserService UserService
@ -167,8 +168,8 @@
user.Username = Email;
user.DisplayName = Email;
user.Email = Email;
user.Password = HostPassword;
user.IsHost = true;
user.Password = HostPassword;
user = await UserService.AddUserAsync(user);
UriHelper.NavigateTo("", true);

View File

@ -9,13 +9,13 @@
@inject IModuleService ModuleService
@inject IModuleDefinitionService ModuleDefinitionService
<div class="@paneadminborder">
@if (panetitle != "")
{
@((MarkupString)panetitle)
}
@DynamicComponent
</div>
<div class="@paneadminborder">
@if (panetitle != "")
{
@((MarkupString)panetitle)
}
@DynamicComponent
</div>
@code {
[CascadingParameter]
@ -129,6 +129,7 @@
{
builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer));
builder.AddAttribute(1, "Module", module);
builder.SetKey(module.PageModuleId);
builder.CloseComponent();
}
}

View File

@ -31,11 +31,19 @@
actions = new List<ActionViewModel>();
if (ModuleState.PaneModuleIndex > 0)
{
actions.Add(new ActionViewModel { Action = "up", Name = "Move Up" });
actions.Add(new ActionViewModel { Action = "<<", Name = "Move To Top" });
}
if (ModuleState.PaneModuleIndex > 0)
{
actions.Add(new ActionViewModel { Action = "<", Name = "Move Up" });
}
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
{
actions.Add(new ActionViewModel { Action = "down", Name = "Move Down" });
actions.Add(new ActionViewModel { Action = ">", Name = "Move Down" });
}
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
{
actions.Add(new ActionViewModel { Action = ">>", Name = "Move To Bottom" });
}
foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
@ -58,23 +66,40 @@
string url = NavigateUrl();
switch (action)
{
case "up":
pagemodule.Order += -1;
case "<<":
pagemodule.Order = 0;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case "down":
pagemodule.Order += 1;
case "<":
pagemodule.Order -= 3;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case ">":
pagemodule.Order += 3;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case ">>":
pagemodule.Order = ModuleState.PaneModuleCount * 2;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case "settings":
url = EditUrl(pagemodule.ModuleId, "Settings");
break;
case "delete":
await PageModuleService.DeletePageModuleAsync(pagemodule.PageModuleId);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
default: // move to pane
string pane = pagemodule.Pane;
pagemodule.Pane = action;
pagemodule.Order = int.MaxValue; // add to bottom of pane
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pane);
break;
}
PageState.Reload = Constants.ReloadPage;