103 lines
3.8 KiB
Plaintext
103 lines
3.8 KiB
Plaintext
@using Oqtane.Modules.HtmlText.Services
|
|
@using Oqtane.Modules.HtmlText.Models
|
|
@using Oqtane.Modules.Controls
|
|
@namespace Oqtane.Modules.HtmlText
|
|
@inherits ModuleBase
|
|
@inject IHtmlTextService HtmlTextService
|
|
@inject ISettingService SettingService
|
|
@inject NavigationManager NavigationManager
|
|
@inject IStringLocalizer<Edit> Localizer
|
|
|
|
@if (_content != null)
|
|
{
|
|
<RichTextEditor Content="@_content" AllowFileManagement="@_allowfilemanagement" @ref="@RichTextEditorHtml"></RichTextEditor>
|
|
<button type="button" class="btn btn-success" @onclick="SaveContent">@Localizer["Save"]</button>
|
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink>
|
|
@if (!string.IsNullOrEmpty(_content))
|
|
{
|
|
<br />
|
|
<br />
|
|
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon"></AuditInfo>
|
|
}
|
|
}
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
|
|
|
public override string Title => "Edit Html/Text";
|
|
|
|
public override List<Resource> Resources => new List<Resource>()
|
|
{
|
|
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" },
|
|
new Resource { ResourceType = ResourceType.Stylesheet, Url = "css/quill/quill1.3.6.bubble.css" },
|
|
new Resource { ResourceType = ResourceType.Stylesheet, Url = "css/quill/quill1.3.6.snow.css" }
|
|
};
|
|
|
|
private RichTextEditor RichTextEditorHtml;
|
|
private bool _allowfilemanagement;
|
|
private string _content = null;
|
|
private string _createdby;
|
|
private DateTime _createdon;
|
|
private string _modifiedby;
|
|
private DateTime _modifiedon;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
_allowfilemanagement = bool.Parse(SettingService.GetSetting(ModuleState.Settings, "AllowFileManagement", "true"));
|
|
|
|
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
|
|
if (htmltext != null)
|
|
{
|
|
_content = htmltext.Content;
|
|
_content = _content.Replace(Constants.ContentUrl, "/" + PageState.Alias.Path + Constants.ContentUrl);
|
|
_createdby = htmltext.CreatedBy;
|
|
_createdon = htmltext.CreatedOn;
|
|
_modifiedby = htmltext.ModifiedBy;
|
|
_modifiedon = htmltext.ModifiedOn;
|
|
}
|
|
else
|
|
{
|
|
_content = string.Empty;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "An Error Occurred Loading Html/Text Content. " + ex.Message);
|
|
AddModuleMessage(ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task SaveContent()
|
|
{
|
|
string content = await RichTextEditorHtml.GetHtml();
|
|
content = content.Replace("/" + PageState.Alias.Path + Constants.ContentUrl, Constants.ContentUrl);
|
|
|
|
try
|
|
{
|
|
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
|
|
if (htmltext != null)
|
|
{
|
|
htmltext.Content = content;
|
|
await HtmlTextService.UpdateHtmlTextAsync(htmltext);
|
|
}
|
|
else
|
|
{
|
|
htmltext = new HtmlText();
|
|
htmltext.ModuleId = ModuleState.ModuleId;
|
|
htmltext.Content = content;
|
|
await HtmlTextService.AddHtmlTextAsync(htmltext);
|
|
}
|
|
|
|
await logger.LogInformation("Html/Text Content Saved {HtmlText}", htmltext);
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Saving Content {Error}", ex.Message);
|
|
AddModuleMessage(Localizer["Error Saving Content"], MessageType.Error);
|
|
}
|
|
}
|
|
}
|