Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor #4198 - copy existing module #4204

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,14 @@
<value>Not Authorized</value>
</data>
<data name="Message.Require.ModuleSelect" xml:space="preserve">
<value>You Must Select A Module.</value>
<value>You Must Select A Module</value>
</data>
<data name="Module.Manage" xml:space="preserve">
<value>Module Management:</value>
</data>
<data name="Module.Select" xml:space="preserve">
<value>Select Module</value>
</data>
<data name="CopyMode.Select" xml:space="preserve">
<value>Select Copy Mode</value>
</data>
<data name="CopyMode.Sync" xml:space="preserve">
<value>Sync</value>
</data>
<data name="CopyMode.Copy" xml:space="preserve">
<value>Copy</value>
</data>
<data name="Page.Manage" xml:space="preserve">
<value>Page Management:</value>
</data>
Expand Down Expand Up @@ -207,13 +198,7 @@
<data name="LocationTop" xml:space="preserve">
<value>Top</value>
</data>
<data name="Message.Require.ModuleAndCopyModeSelect" xml:space="preserve">
<value>You Must Select A Module And The Copy Mode.</value>
</data>
<data name="Message.Module.NotPortable" xml:space="preserve">
<value>The Module's Content Will Not Be Synchronized.</value>
</data>
<data name="Module.CopyExisting" xml:space="preserve">
<value>Copy Existing Module</value>
</data>
</data>
</root>
37 changes: 15 additions & 22 deletions Oqtane.Client/Themes/Controls/Theme/ControlPanelInteractive.razor
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@
<div class="row">
<div class="col text-center">
<label for="Module" class="control-label">@Localizer["Module.Manage"]</label>
<select class="form-select" @bind="@_moduleType">
<select class="form-select" @onchange="(e => ModuleTypeChanged(e))">
<option value="new">@Localizer["Module.AddNew"]</option>
@if (PageState.Page.UserId == null)
{
<option value="existing.add">@Localizer["Module.AddExisting"]</option>
<option value="existing.copy">@Localizer["Module.CopyExisting"]</option>
<option value="add">@Localizer["Module.AddExisting"]</option>
<option value="copy">@Localizer["Module.CopyExisting"]</option>
}
</select>
@if (_moduleType == "new")
Expand Down Expand Up @@ -143,21 +143,20 @@
}
else
{
<select class="form-select mt-1" @onchange="(e => PageChanged(e))">
<select class="form-select mt-1" value="@_pageId" @onchange="(e => PageChanged(e))">
<option value="-">&lt;@Localizer["Page.Select"]&gt;</option>
@foreach (Page p in _pages)
{
<option value="@p.PageId">@p.Name</option>
}
</select>
<select class="form-select mt-1" @bind="@_moduleId" @bind:after="() => ModuleIdChanged()">
<select class="form-select mt-1" @bind="@_moduleId">
<option value="-">&lt;@Localizer["Module.Select"]&gt;</option>
@foreach (Module module in _modules)
{
<option value="@module.ModuleId">@module.Title</option>
}
</select>
@((MarkupString)_copyModuleMessage)
}
</div>
</div>
Expand Down Expand Up @@ -270,7 +269,6 @@
protected int _location { get; private set; } = int.MaxValue;
protected string _visibility { get; private set; } = "view";
protected string _message { get; private set; } = "";
protected string _copyModuleMessage { get; private set; } = "";

private string settingCategory = "CP-category";
private string settingPane = "CP-pane";
Expand Down Expand Up @@ -341,33 +339,28 @@
StateHasChanged();
}

private void ModuleTypeChanged(ChangeEventArgs e)
{
_moduleType = (string)e.Value;
_pageId = "-";
_moduleId = "-";
}

private void PageChanged(ChangeEventArgs e)
{
_pageId = (string)e.Value;
if (_pageId != "-")
{
_modules = PageState.Modules
.Where(module => module.PageId == int.Parse(_pageId) &&
UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.PermissionList))
UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.PermissionList) &&
(_moduleType == "add" || module.ModuleDefinition.IsPortable))
.ToList();
}
_moduleId = "-";
StateHasChanged();
}

private void ModuleIdChanged()
{
_copyModuleMessage = string.Empty;
if(_moduleId != "-")
{
var module = _modules.FirstOrDefault(item => item.ModuleId == int.Parse(_moduleId));
if (module != null && !module.ModuleDefinition.IsPortable)
{
_copyModuleMessage = $"<div class=\"alert alert-warning mt-2 text-center\" role=\"alert\">{Localizer["Message.Module.NotPortable"]}</div>";
}
}
}

private async Task AddModule()
{
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.PermissionList))
Expand All @@ -387,7 +380,7 @@
module = await ModuleService.AddModuleAsync(module);
newModuleId = module.ModuleId;
}
else if (_moduleType == "exsiting.copy")
else if (_moduleType == "copy")
{
var module = await ModuleService.GetModuleAsync(int.Parse(_moduleId));
module.ModuleId = 0;
Expand Down
8 changes: 5 additions & 3 deletions Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Oqtane.Shared;
using Oqtane.Migrations.Framework;
using Oqtane.Documentation;
using System.Linq;

// ReSharper disable ConvertToUsingDeclaration

Expand All @@ -29,10 +30,11 @@ public HtmlTextManager(IHtmlTextRepository htmlText, IDBContextDependencies DBCo
public string ExportModule(Module module)
{
string content = "";
var htmlText = _htmlText.GetHtmlText(module.ModuleId);
if (htmlText != null)
var htmltexts = _htmlText.GetHtmlTexts(module.ModuleId);
if (htmltexts != null && htmltexts.Any())
{
content = WebUtility.HtmlEncode(htmlText.Content);
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
content = WebUtility.HtmlEncode(htmltext.Content);
}
return content;
}
Expand Down