-
- @ToolbarContent
-
-
-
+
+
+
+
+ @if (_filemanagervisible)
+ {
+
+ @((MarkupString)_message)
+
+ }
+
+
+
+ @if (_filemanagervisible)
+ {
+ @((MarkupString)" ")
+
+ }
+
+
+
+
+ @if (ToolbarContent != null)
+ {
+ @ToolbarContent
+ }
+ else
+ {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ @if (ReadOnly)
+ {
+
+ }
+ else
+ {
+
+ }
+
+
@@ -32,10 +85,12 @@
private ElementReference _toolBar;
private bool _filemanagervisible = false;
private FileManager _fileManager;
+ private string _original = string.Empty;
+ private string _content = string.Empty;
private string _message = string.Empty;
[Parameter]
- public RenderFragment ToolbarContent { get; set; }
+ public string Content { get; set; }
[Parameter]
public bool ReadOnly { get; set; } = false;
@@ -43,12 +98,27 @@
[Parameter]
public string Placeholder { get; set; } = "Enter Your Content...";
+ // parameters only applicable to rich text editor
+ [Parameter]
+ public RenderFragment ToolbarContent { get; set; }
+
[Parameter]
public string Theme { get; set; } = "snow";
[Parameter]
public string DebugLevel { get; set; } = "info";
+ protected override void OnInitialized()
+ {
+ _original = Content;
+
+ _content = _original;
+ if (string.IsNullOrEmpty(_content))
+ {
+ _content = Placeholder;
+ }
+ }
+
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
@@ -61,6 +131,10 @@
Placeholder,
Theme,
DebugLevel);
+
+ await RichTextEditorInterop.LoadEditorContent(
+ JsRuntime,
+ _editorElement, _original);
}
}
@@ -73,9 +147,18 @@
public async Task
GetHtml()
{
- return await RichTextEditorInterop.GetHtml(
- JsRuntime,
- _editorElement);
+ if (_original != _content)
+ {
+ // raw html content changed
+ return _content;
+ }
+ else
+ {
+ // return rich text content
+ return await RichTextEditorInterop.GetHtml(
+ JsRuntime,
+ _editorElement);
+ }
}
public async Task GetContent()
@@ -85,13 +168,6 @@
_editorElement);
}
- public async Task LoadContent(string content)
- {
- await RichTextEditorInterop.LoadEditorContent(
- JsRuntime,
- _editorElement, content);
- }
-
public async Task EnableEditor(bool mode)
{
await RichTextEditorInterop.EnableEditor(
@@ -122,7 +198,6 @@
_filemanagervisible = true;
_message = string.Empty;
}
-
StateHasChanged();
}
@@ -130,8 +205,21 @@
{
_filemanagervisible = false;
_message = string.Empty;
-
StateHasChanged();
}
+ public async Task RefreshRichText()
+ {
+ await RichTextEditorInterop.LoadEditorContent(
+ JsRuntime,
+ _editorElement, _content);
+ }
+
+ public async Task RefreshRawHtml()
+ {
+ _content = await RichTextEditorInterop.GetHtml(
+ JsRuntime,
+ _editorElement);
+ StateHasChanged();
+ }
}
diff --git a/Oqtane.Client/UI/RichTextEditorInterop.cs b/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs
similarity index 98%
rename from Oqtane.Client/UI/RichTextEditorInterop.cs
rename to Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs
index 54536005..1f590f8a 100644
--- a/Oqtane.Client/UI/RichTextEditorInterop.cs
+++ b/Oqtane.Client/Modules/Controls/RichTextEditorInterop.cs
@@ -2,7 +2,7 @@
using Microsoft.JSInterop;
using System.Threading.Tasks;
-namespace Oqtane.UI
+namespace Oqtane.Modules.Controls
{
public static class RichTextEditorInterop
{
diff --git a/Oqtane.Client/Modules/HtmlText/Edit.razor b/Oqtane.Client/Modules/HtmlText/Edit.razor
index ab0f1feb..9df38687 100644
--- a/Oqtane.Client/Modules/HtmlText/Edit.razor
+++ b/Oqtane.Client/Modules/HtmlText/Edit.razor
@@ -7,111 +7,48 @@
@inject HttpClient http
@inject SiteState sitestate
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @if (!RichTextEditorMode)
- {
-
- }
- else
- {
-
- }
-
- Cancel
-
-
-
-
+@if (_content != null)
+{
+
+
+ Cancel
+ @if (!string.IsNullOrEmpty(_content))
+ {
+
+
+ }
+}
@code {
- private string _visibleText = "d-none";
- private string _visibleRich;
- private bool _richTextEditorMode;
private RichTextEditor RichTextEditorHtml;
- private string content;
- private string createdby;
- private DateTime createdon;
- private string modifiedby;
- private DateTime modifiedon;
+ private string _content = null;
+ private string _createdby;
+ private DateTime _createdon;
+ private string _modifiedby;
+ private DateTime _modifiedon;
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
public override string Title => "Edit Html/Text";
- public bool RichTextEditorMode
- {
- get => _richTextEditorMode;
- set
- {
- _richTextEditorMode = value;
-
- if (_richTextEditorMode)
- {
- _visibleText = "d-none";
- _visibleRich = string.Empty;
- }
- else
- {
- _visibleText = string.Empty;
- _visibleRich = "d-none";
- }
- }
- }
-
- protected override async Task OnAfterRenderAsync(bool firstRender)
+ protected override async Task OnInitializedAsync()
{
try
{
- if (firstRender)
+ var htmltextservice = new HtmlTextService(http, sitestate);
+ var htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
+ if (htmltext != null)
{
- if (content == null)
- {
- RichTextEditorMode = true;
- await LoadText();
- }
+ _content = htmltext.Content;
+ _content = _content.Replace(Constants.ContentUrl, "/" + PageState.Alias.AliasId.ToString() + Constants.ContentUrl);
+ _createdby = htmltext.CreatedBy;
+ _createdon = htmltext.CreatedOn;
+ _modifiedby = htmltext.ModifiedBy;
+ _modifiedon = htmltext.ModifiedOn;
+ }
+ else
+ {
+ _content = string.Empty;
}
}
catch (Exception ex)
@@ -121,48 +58,10 @@
}
}
- private async Task LoadText()
- {
- var htmltextservice = new HtmlTextService(http, sitestate);
- var htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
- if (htmltext != null)
- {
- content = htmltext.Content;
- createdby = htmltext.CreatedBy;
- createdon = htmltext.CreatedOn;
- modifiedby = htmltext.ModifiedBy;
- modifiedon = htmltext.ModifiedOn;
-
- if (RichTextEditorMode)
- {
- await RichTextEditorHtml.LoadContent(content);
- StateHasChanged();
- }
- }
- }
-
- private async Task RichTextEditor()
- {
- RichTextEditorMode = true;
- await RichTextEditorHtml.LoadContent(content);
- StateHasChanged();
- }
-
- private async Task RawHtmlEditor()
- {
- content = await this.RichTextEditorHtml.GetHtml();
- RichTextEditorMode = false;
- StateHasChanged();
- }
-
private async Task SaveContent()
{
- if (RichTextEditorMode)
- {
- content = await RichTextEditorHtml.GetHtml();
- }
-
- content = content.Replace(((PageState.Alias.Path == string.Empty) ? "/~" : PageState.Alias.Path) + Constants.ContentUrl, Constants.ContentUrl);
+ string content = await RichTextEditorHtml.GetHtml();
+ content = content.Replace("/" + PageState.Alias.AliasId.ToString() + Constants.ContentUrl, Constants.ContentUrl);
try
{
@@ -180,7 +79,7 @@
htmltext.Content = content;
await htmltextservice.AddHtmlTextAsync(htmltext);
}
-
+
await logger.LogInformation("Html/Text Content Saved {HtmlText}", htmltext);
NavigationManager.NavigateTo(NavigateUrl());
}
@@ -190,5 +89,4 @@
AddModuleMessage("Error Saving Content", MessageType.Error);
}
}
-
}
diff --git a/Oqtane.Client/Modules/HtmlText/Index.razor b/Oqtane.Client/Modules/HtmlText/Index.razor
index e04ffbf2..c76afa02 100644
--- a/Oqtane.Client/Modules/HtmlText/Index.razor
+++ b/Oqtane.Client/Modules/HtmlText/Index.razor
@@ -30,7 +30,7 @@
if (htmltext != null)
{
content = htmltext.Content;
- content = content.Replace(Constants.ContentUrl, ((PageState.Alias.Path == "") ? "/~" : PageState.Alias.Path) + Constants.ContentUrl);
+ content = content.Replace(Constants.ContentUrl, "/" + PageState.Alias.AliasId.ToString() + Constants.ContentUrl);
}
}
catch (Exception ex)