add copy page functionality to control panel
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
<Label Class="col-sm-3" For="move" HelpText="Select the location where you would like the page to be moved in relation to other pages" ResourceKey="Move">Move: </Label>
|
||||
<div class="col-sm-9">
|
||||
<select id="move" class="form-select" @bind="@_insert" required>
|
||||
@if (_parentid == _currentparentid)
|
||||
@if (_parentid == _currentparentid && !_copy)
|
||||
{
|
||||
<option value="="><@Localizer["ThisLocation.Keep"]></option>
|
||||
}
|
||||
@@ -241,36 +241,40 @@
|
||||
<option value="False">@SharedLocalizer["No"]</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<button type="button" class="btn btn-success" @onclick="SavePage">@SharedLocalizer["Save"]</button>
|
||||
<button type="button" class="btn btn-secondary" @onclick="Cancel">@SharedLocalizer["Cancel"]</button>
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel Name="PageModules" Heading="Modules" ResourceKey="PageModules">
|
||||
<Pager Items="_pageModules">
|
||||
<Header>
|
||||
@if (!_copy)
|
||||
{
|
||||
<TabPanel Name="PageModules" Heading="Modules" ResourceKey="PageModules">
|
||||
<Pager Items="_pageModules">
|
||||
<Header>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th>@Localizer["ModuleTitle"]</th>
|
||||
<th>@Localizer["ModuleDefinition"]</th>
|
||||
</Header>
|
||||
<Row>
|
||||
<td><ActionLink Action="Settings" Text="Edit" Path="@_actualpath" ModuleId="@context.ModuleId" Security="SecurityAccessLevel.Edit" PermissionList="@context.PermissionList" ResourceKey="ModuleSettings" /></td>
|
||||
<td><ActionDialog Header="Delete Module" Message="Are You Sure You Wish To Delete This Module?" Action="Delete" Security="SecurityAccessLevel.Edit" PermissionList="@context.PermissionList" Class="btn btn-danger" OnClick="@(async () => await DeleteModule(context))" ResourceKey="DeleteModule" /></td>
|
||||
<td>@context.Title</td>
|
||||
<td>@context.ModuleDefinition?.Name</td>
|
||||
</Row>
|
||||
</Pager>
|
||||
</TabPanel>
|
||||
@if (_themeSettingsType != null)
|
||||
{
|
||||
<TabPanel Name="ThemeSettings" Heading="Theme Settings" ResourceKey="ThemeSettings">
|
||||
@_themeSettingsComponent
|
||||
<br />
|
||||
<button type="button" class="btn btn-success" @onclick="SavePage">@SharedLocalizer["Save"]</button>
|
||||
<button type="button" class="btn btn-secondary" @onclick="Cancel">@SharedLocalizer["Cancel"]</button>
|
||||
</Header>
|
||||
<Row>
|
||||
<td><ActionLink Action="Settings" Text="Edit" Path="@_actualpath" ModuleId="@context.ModuleId" Security="SecurityAccessLevel.Edit" PermissionList="@context.PermissionList" ResourceKey="ModuleSettings" /></td>
|
||||
<td><ActionDialog Header="Delete Module" Message="Are You Sure You Wish To Delete This Module?" Action="Delete" Security="SecurityAccessLevel.Edit" PermissionList="@context.PermissionList" Class="btn btn-danger" OnClick="@(async () => await DeleteModule(context))" ResourceKey="DeleteModule" /></td>
|
||||
<td>@context.Title</td>
|
||||
<td>@context.ModuleDefinition?.Name</td>
|
||||
</Row>
|
||||
</Pager>
|
||||
</TabPanel>
|
||||
@if (_themeSettingsType != null)
|
||||
{
|
||||
<TabPanel Name="ThemeSettings" Heading="Theme Settings" ResourceKey="ThemeSettings">
|
||||
@_themeSettingsComponent
|
||||
<br />
|
||||
<button type="button" class="btn btn-success" @onclick="SavePage">@SharedLocalizer["Save"]</button>
|
||||
<button type="button" class="btn btn-secondary" @onclick="Cancel">@SharedLocalizer["Cancel"]</button>
|
||||
</TabPanel>
|
||||
}
|
||||
|
||||
}
|
||||
</TabStrip>
|
||||
}
|
||||
@@ -349,6 +353,7 @@
|
||||
private List<ThemeControl> _containers = new List<ThemeControl>();
|
||||
private List<Page> _pages;
|
||||
private int _pageId;
|
||||
private bool _copy = false;
|
||||
private string _name;
|
||||
private string _currentparentid;
|
||||
private string _parentid = "-1";
|
||||
@@ -394,6 +399,10 @@
|
||||
{
|
||||
_pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
|
||||
_pageId = Int32.Parse(PageState.QueryString["id"]);
|
||||
if (PageState.QueryString.ContainsKey("copy"))
|
||||
{
|
||||
_copy = bool.Parse(PageState.QueryString["copy"]);
|
||||
}
|
||||
_page = await PageService.GetPageAsync(_pageId);
|
||||
_icons = await SystemService.GetIconsAsync();
|
||||
_iconresources = Utilities.GetFullTypeName(typeof(IconResources).AssemblyQualifiedName);
|
||||
@@ -413,7 +422,7 @@
|
||||
_children = new List<Page>();
|
||||
foreach (Page p in _pages.Where(item => (_parentid == "-1" && item.ParentId == null) || (item.ParentId == int.Parse(_parentid, CultureInfo.InvariantCulture))))
|
||||
{
|
||||
if (p.PageId != _pageId && UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.PermissionList))
|
||||
if ((p.PageId != _pageId || _copy) && UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.PermissionList))
|
||||
{
|
||||
_children.Add(p);
|
||||
}
|
||||
@@ -440,6 +449,12 @@
|
||||
_expirydate = Utilities.UtcAsLocalDate(_page.ExpiryDate);
|
||||
_ispersonalizable = _page.IsPersonalizable.ToString();
|
||||
|
||||
if (_copy)
|
||||
{
|
||||
_insert = ">";
|
||||
_childid = _page.PageId;
|
||||
}
|
||||
|
||||
// appearance
|
||||
_title = _page.Title;
|
||||
_themetype = _page.ThemeType;
|
||||
@@ -470,6 +485,19 @@
|
||||
// permissions
|
||||
_permissions = _page.PermissionList;
|
||||
_updatemodulepermissions = "True";
|
||||
if (_copy)
|
||||
{
|
||||
_permissions = _page.PermissionList.Select(item => new Permission
|
||||
{
|
||||
SiteId = item.SiteId,
|
||||
EntityName = item.EntityName,
|
||||
EntityId = -1,
|
||||
PermissionName = item.PermissionName,
|
||||
RoleName = item.RoleName,
|
||||
UserId = item.UserId,
|
||||
IsAuthorized = item.IsAuthorized,
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
// page modules
|
||||
var modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
|
||||
@@ -484,6 +512,13 @@
|
||||
_deletedon = _page.DeletedOn;
|
||||
|
||||
ThemeSettings();
|
||||
|
||||
if (_copy)
|
||||
{
|
||||
_name = "";
|
||||
_path = "";
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
else
|
||||
@@ -554,7 +589,7 @@
|
||||
builder.OpenComponent(0, _themeSettingsType);
|
||||
builder.AddAttribute(1, "RenderModeBoundary", RenderModeBoundary);
|
||||
builder.AddComponentReferenceCapture(2, inst => { _themeSettings = Convert.ChangeType(inst, _themeSettingsType); });
|
||||
|
||||
|
||||
builder.CloseComponent();
|
||||
};
|
||||
}
|
||||
@@ -581,6 +616,13 @@
|
||||
{
|
||||
string currentPath = _page.Path;
|
||||
|
||||
if (_copy)
|
||||
{
|
||||
_page = new Page();
|
||||
_page.SiteId = PageState.Site.SiteId;
|
||||
currentPath = "";
|
||||
}
|
||||
|
||||
_page.Name = _name;
|
||||
|
||||
if (_parentid == "-1")
|
||||
@@ -696,8 +738,19 @@
|
||||
_page.UpdateModulePermissions = bool.Parse(_updatemodulepermissions);
|
||||
}
|
||||
|
||||
// update page
|
||||
_page = await PageService.UpdatePageAsync(_page);
|
||||
if (_copy)
|
||||
{
|
||||
// create page
|
||||
_page = await PageService.AddPageAsync(_page);
|
||||
await PageService.CopyPageAsync(_pageId, _page.PageId, bool.Parse(_updatemodulepermissions));
|
||||
await logger.LogInformation("Page Added {Page}", _page);
|
||||
}
|
||||
else
|
||||
{
|
||||
// update page
|
||||
_page = await PageService.UpdatePageAsync(_page);
|
||||
await logger.LogInformation("Page Saved {Page}", _page);
|
||||
}
|
||||
|
||||
// update page order
|
||||
await PageService.UpdatePageOrderAsync(_page.SiteId, _page.PageId, _page.ParentId);
|
||||
@@ -710,7 +763,6 @@
|
||||
await PageService.UpdatePageOrderAsync(_page.SiteId, _page.PageId, int.Parse(_currentparentid));
|
||||
}
|
||||
|
||||
await logger.LogInformation("Page Saved {Page}", _page);
|
||||
if (!string.IsNullOrEmpty(PageState.ReturnUrl))
|
||||
{
|
||||
NavigationManager.NavigateTo(PageState.ReturnUrl, true); // redirect to page being edited and reload
|
||||
|
||||
@@ -201,4 +201,7 @@
|
||||
<data name="Synchronize" xml:space="preserve">
|
||||
<value>Synchronize Site</value>
|
||||
</data>
|
||||
<data name="Copy" xml:space="preserve">
|
||||
<value>Copy Page</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -71,6 +71,15 @@ namespace Oqtane.Services
|
||||
/// <param name="pageId"></param>
|
||||
/// <returns></returns>
|
||||
Task DeletePageAsync(int pageId);
|
||||
|
||||
/// <summary>
|
||||
/// Copies the modules from one page to another
|
||||
/// </summary>
|
||||
/// <param name="fromPageId"></param>
|
||||
/// <param name="toPageId"></param>
|
||||
/// <param name="usePagePermissions"></param>
|
||||
/// <returns></returns>
|
||||
Task CopyPageAsync(int fromPageId, int toPageId, bool usePagePermissions);
|
||||
}
|
||||
|
||||
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
|
||||
@@ -129,5 +138,10 @@ namespace Oqtane.Services
|
||||
{
|
||||
await DeleteAsync($"{Apiurl}/{pageId}");
|
||||
}
|
||||
|
||||
public async Task CopyPageAsync(int fromPageId, int toPageId, bool usePagePermissions)
|
||||
{
|
||||
await PostAsync($"{Apiurl}/{fromPageId}/{toPageId}/{usePagePermissions}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,18 +59,29 @@
|
||||
<button type="button" class="btn btn-danger col ms-1" @onclick="ConfirmDelete">@SharedLocalizer["Delete"]</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row d-flex">
|
||||
<div class="col">
|
||||
@if (UserSecurity.ContainsRole(PageState.Page.PermissionList, PermissionNames.View, RoleNames.Everyone))
|
||||
{
|
||||
<button type="button" class="btn btn-secondary col-12" @onclick=@(async () => Publish("unpublish"))>@Localizer["Page.Unpublish"]</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-secondary col-12" @onclick=@(async () => Publish("publish"))>@Localizer["Page.Publish"]</button>
|
||||
}
|
||||
@if (PageState.Page.UserId == null)
|
||||
{
|
||||
<div class="row d-flex mb-2">
|
||||
<div class="col">
|
||||
<button type="button" class="btn btn-secondary col-12" data-bs-dismiss="offcanvas" @onclick=@(async () => Navigate("Copy"))>@Localizer["Copy"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (!PageState.Page.Path.StartsWith("admin/"))
|
||||
{
|
||||
<div class="row d-flex">
|
||||
<div class="col">
|
||||
@if (UserSecurity.ContainsRole(PageState.Page.PermissionList, PermissionNames.View, RoleNames.Everyone))
|
||||
{
|
||||
<button type="button" class="btn btn-secondary col-12" @onclick=@(async () => Publish("unpublish"))>@Localizer["Page.Unpublish"]</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-secondary col-12" @onclick=@(async () => Publish("publish"))>@Localizer["Page.Publish"]</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<hr class="app-rule" />
|
||||
|
||||
@if (_deleteConfirmation)
|
||||
@@ -496,7 +507,12 @@
|
||||
case "Edit":
|
||||
// get page management moduleid
|
||||
moduleId = int.Parse(PageState.Site.Settings[Constants.PageManagementModule]);
|
||||
NavigationManager.NavigateTo(Utilities.EditUrl(PageState.Alias.Path, "admin/pages", moduleId, location, $"id={PageState.Page.PageId}&returnurl={WebUtility.UrlEncode(PageState.Route.PathAndQuery)}"));
|
||||
NavigationManager.NavigateTo(Utilities.EditUrl(PageState.Alias.Path, "admin/pages", moduleId, "Edit", $"id={PageState.Page.PageId}&returnurl={WebUtility.UrlEncode(PageState.Route.PathAndQuery)}"));
|
||||
break;
|
||||
case "Copy":
|
||||
// get page management moduleid
|
||||
moduleId = int.Parse(PageState.Site.Settings[Constants.PageManagementModule]);
|
||||
NavigationManager.NavigateTo(Utilities.EditUrl(PageState.Alias.Path, "admin/pages", moduleId, "Edit", $"id={PageState.Page.PageId}©=true&returnurl={WebUtility.UrlEncode(PageState.Route.PathAndQuery)}"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
using System.Linq;
|
||||
using Oqtane.Security;
|
||||
using System.Net;
|
||||
using System.Security;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Oqtane.Security;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
@@ -498,6 +497,79 @@ namespace Oqtane.Controllers
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// POST api/<controller>/5/6
|
||||
[HttpPost("{fromPageId}/{toPageId}/{usePagePermissions}")]
|
||||
[Authorize(Roles = RoleNames.Registered)]
|
||||
public void Post(int fromPageId, int toPageId, bool usePagePermissions)
|
||||
{
|
||||
var fromPage = _pages.GetPage(fromPageId);
|
||||
if (fromPage != null && fromPage.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.View, fromPage.PermissionList))
|
||||
{
|
||||
var toPage = _pages.GetPage(toPageId);
|
||||
if (toPage != null && toPage.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.View, toPage.PermissionList))
|
||||
{
|
||||
// copy modules
|
||||
List<PageModule> pageModules = _pageModules.GetPageModules(fromPage.SiteId).ToList();
|
||||
foreach (PageModule pm in pageModules.Where(item => item.PageId == fromPage.PageId && !item.Module.AllPages && !item.IsDeleted))
|
||||
{
|
||||
Module module = new Module();
|
||||
module.SiteId = fromPage.SiteId;
|
||||
module.PageId = toPageId;
|
||||
module.ModuleDefinitionName = pm.Module.ModuleDefinitionName;
|
||||
module.AllPages = false;
|
||||
if (usePagePermissions)
|
||||
{
|
||||
module.PermissionList = toPage.PermissionList;
|
||||
}
|
||||
else
|
||||
{
|
||||
module.PermissionList = pm.Module.PermissionList;
|
||||
}
|
||||
module.PermissionList = module.PermissionList.Select(item => new Permission
|
||||
{
|
||||
SiteId = item.SiteId,
|
||||
EntityName = EntityNames.Module,
|
||||
EntityId = -1,
|
||||
PermissionName = item.PermissionName,
|
||||
RoleName = item.RoleName,
|
||||
UserId = item.UserId,
|
||||
IsAuthorized = item.IsAuthorized,
|
||||
}).ToList();
|
||||
module = _modules.AddModule(module);
|
||||
|
||||
string content = _modules.ExportModule(pm.ModuleId);
|
||||
if (content != "")
|
||||
{
|
||||
_modules.ImportModule(module.ModuleId, content);
|
||||
}
|
||||
|
||||
PageModule pageModule = new PageModule();
|
||||
pageModule.PageId = toPageId;
|
||||
pageModule.ModuleId = module.ModuleId;
|
||||
pageModule.Title = pm.Title;
|
||||
pageModule.Pane = pm.Pane;
|
||||
pageModule.Order = pm.Order;
|
||||
pageModule.ContainerType = pm.ContainerType;
|
||||
pageModule.EffectiveDate = pm.EffectiveDate;
|
||||
pageModule.ExpiryDate = pm.ExpiryDate;
|
||||
pageModule.Header = pm.Header;
|
||||
pageModule.Footer = pm.Footer;
|
||||
|
||||
_pageModules.AddPageModule(pageModule);
|
||||
}
|
||||
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.Site, fromPage.SiteId, SyncEventActions.Refresh);
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
// synchronization only supports sites in the same tenant (database)
|
||||
// module title is used as a key to identify module instances on a page
|
||||
// modules must implement ISynchronizable interface
|
||||
// modules must implement ISynchronizable interface for content synchronization
|
||||
// change detection does not support deleted items as key values will usually be different due to localization
|
||||
|
||||
// define settings that should not be synchronized (should be extensible in the future)
|
||||
|
||||
Reference in New Issue
Block a user