allow page and module settings to be included in site templates, improve terms and privacy default content, add Settings for HtmlText module
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
@namespace Oqtane.Modules.HtmlText
|
||||
@inherits ModuleBase
|
||||
@inject IHtmlTextService HtmlTextService
|
||||
@inject ISettingService SettingService
|
||||
@inject IStringLocalizer<Index> Localizer
|
||||
|
||||
@if (PageState.EditMode)
|
||||
@ -36,6 +37,10 @@
|
||||
{
|
||||
content = htmltext.Content;
|
||||
content = Utilities.FormatContent(content, PageState.Alias, "render");
|
||||
if (bool.Parse(SettingService.GetSetting(ModuleState.Settings, "DynamicTokens", "false")))
|
||||
{
|
||||
content = ReplaceTokens(content);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace Oqtane.Modules.HtmlText
|
||||
Version = "1.0.1",
|
||||
ServerManagerType = "Oqtane.Modules.HtmlText.Manager.HtmlTextManager, Oqtane.Server",
|
||||
ReleaseVersions = "1.0.0,1.0.1",
|
||||
SettingsType = string.Empty,
|
||||
SettingsType = "Oqtane.Modules.HtmlText.Settings, Oqtane.Client",
|
||||
Resources = new List<Resource>()
|
||||
{
|
||||
new Resource { ResourceType = ResourceType.Stylesheet, Url = "~/Module.css" }
|
||||
|
55
Oqtane.Client/Modules/HtmlText/Settings.razor
Normal file
55
Oqtane.Client/Modules/HtmlText/Settings.razor
Normal file
@ -0,0 +1,55 @@
|
||||
@namespace Oqtane.Modules.HtmlText
|
||||
@inherits ModuleBase
|
||||
@inject ISettingService SettingService
|
||||
@implements Oqtane.Interfaces.ISettingsControl
|
||||
@inject IStringLocalizer<Settings> Localizer
|
||||
@inject IStringLocalizer<SharedResources> SharedLocalizer
|
||||
|
||||
<form @ref="form" class="@(validated ? "was-validated" : "needs-validation")" novalidate>
|
||||
<div class="container">
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="dynamictokens" ResourceKey="DynamicTokens" ResourceType="@resourceType" HelpText="Do you wish to allow tokens to be dynamically replaced? Please note that this will affect the performance of your site.">Dynamic Tokens? </Label>
|
||||
<div class="col-sm-9">
|
||||
<select id="dynamictokens" class="form-select" @bind="@_dynamictokens">
|
||||
<option value="true">@SharedLocalizer["Yes"]</option>
|
||||
<option value="false">@SharedLocalizer["No"]</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
private string resourceType = "Oqtane.Modules.HtmlText.Settings, Oqtane.Client"; // for localization
|
||||
|
||||
private ElementReference form;
|
||||
private bool validated = false;
|
||||
|
||||
private string _dynamictokens;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
try
|
||||
{
|
||||
_dynamictokens = SettingService.GetSetting(ModuleState.Settings, "DynamicTokens", "false");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddModuleMessage(ex.Message, MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = await SettingService.GetModuleSettingsAsync(ModuleState.ModuleId);
|
||||
settings = SettingService.SetSetting(settings, "DynamicTokens", _dynamictokens);
|
||||
await SettingService.UpdateModuleSettingsAsync(settings, ModuleState.ModuleId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddModuleMessage(ex.Message, MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using Microsoft.JSInterop;
|
||||
using System.Linq;
|
||||
using System.Dynamic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Oqtane.Modules
|
||||
{
|
||||
@ -35,7 +36,7 @@ namespace Oqtane.Modules
|
||||
protected PageState PageState { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
protected Module ModuleState { get; set; }
|
||||
protected Models.Module ModuleState { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderModeBoundary RenderModeBoundary { get; set; }
|
||||
@ -413,6 +414,79 @@ namespace Oqtane.Modules
|
||||
await interop.ScrollTo(0, 0, "smooth");
|
||||
}
|
||||
|
||||
public string ReplaceTokens(string content)
|
||||
{
|
||||
return ReplaceTokens(content, null);
|
||||
}
|
||||
|
||||
public string ReplaceTokens(string content, object obj)
|
||||
{
|
||||
var tokens = new List<string>();
|
||||
var pos = content.IndexOf("[");
|
||||
if (pos != -1)
|
||||
{
|
||||
if (content.IndexOf("]", pos) != -1)
|
||||
{
|
||||
var token = content.Substring(pos, content.IndexOf("]", pos) - pos + 1);
|
||||
if (token.Contains(":"))
|
||||
{
|
||||
tokens.Add(token.Substring(1, token.Length - 2));
|
||||
}
|
||||
}
|
||||
pos = content.IndexOf("[", pos + 1);
|
||||
}
|
||||
if (tokens.Count != 0)
|
||||
{
|
||||
foreach (string token in tokens)
|
||||
{
|
||||
var segments = token.Split(":");
|
||||
if (segments.Length >= 2 && segments.Length <= 3)
|
||||
{
|
||||
var objectName = string.Join(":", segments, 0, segments.Length - 1);
|
||||
var propertyName = segments[segments.Length - 1];
|
||||
var propertyValue = "";
|
||||
|
||||
switch (objectName)
|
||||
{
|
||||
case "ModuleState":
|
||||
propertyValue = ModuleState.GetType().GetProperty(propertyName)?.GetValue(ModuleState, null).ToString();
|
||||
break;
|
||||
case "PageState":
|
||||
propertyValue = PageState.GetType().GetProperty(propertyName)?.GetValue(PageState, null).ToString();
|
||||
break;
|
||||
case "PageState:Alias":
|
||||
propertyValue = PageState.Alias.GetType().GetProperty(propertyName)?.GetValue(PageState.Alias, null).ToString();
|
||||
break;
|
||||
case "PageState:Site":
|
||||
propertyValue = PageState.Site.GetType().GetProperty(propertyName)?.GetValue(PageState.Site, null).ToString();
|
||||
break;
|
||||
case "PageState:Page":
|
||||
propertyValue = PageState.Page.GetType().GetProperty(propertyName)?.GetValue(PageState.Page, null).ToString();
|
||||
break;
|
||||
case "PageState:User":
|
||||
propertyValue = PageState.User?.GetType().GetProperty(propertyName)?.GetValue(PageState.User, null).ToString();
|
||||
break;
|
||||
case "PageState:Route":
|
||||
propertyValue = PageState.Route.GetType().GetProperty(propertyName)?.GetValue(PageState.Route, null).ToString();
|
||||
break;
|
||||
default:
|
||||
if (obj != null && obj.GetType().Name == objectName)
|
||||
{
|
||||
propertyValue = obj.GetType().GetProperty(propertyName)?.GetValue(obj, null).ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (propertyValue != null)
|
||||
{
|
||||
content = content.Replace("[" + token + "]", propertyValue);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
// logging methods
|
||||
public async Task Log(Alias alias, LogLevel level, string function, Exception exception, string message, params object[] args)
|
||||
{
|
||||
|
Reference in New Issue
Block a user