Merge pull request #4452 from sbwalker/dev

remove ITextEditorProvider interface
This commit is contained in:
Shaun Walker 2024-07-22 13:31:39 -04:00 committed by GitHub
commit 4a35d7364b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 40 additions and 66 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Oqtane.Interfaces;
using Oqtane.Providers; using Oqtane.Providers;
using Oqtane.Services; using Oqtane.Services;
using Oqtane.Shared; using Oqtane.Shared;
@ -51,6 +52,10 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddScoped<IVisitorService, VisitorService>(); services.AddScoped<IVisitorService, VisitorService>();
services.AddScoped<ISyncService, SyncService>(); services.AddScoped<ISyncService, SyncService>();
// providers
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.QuillJSTextEditor>();
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.TextAreaTextEditor>();
return services; return services;
} }
} }

View File

@ -131,14 +131,14 @@
<Section Name="Functionality" Heading="Functionality" ResourceKey="Functionality"> <Section Name="Functionality" Heading="Functionality" ResourceKey="Functionality">
<div class="container"> <div class="container">
<div class="row mb-1 align-items-center"> <div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="textEditorProvider" HelpText="Select the text editor for the site" ResourceKey="TextEditorProvider">Text Editor: </Label> <Label Class="col-sm-3" For="textEditor" HelpText="Select the text editor for the site" ResourceKey="TextEditor">Text Editor: </Label>
<div class="col-sm-9"> <div class="col-sm-9">
<select id="textEditorProvider" class="form-select" @bind="@_textEditorProvider" required> <select id="textEditor" class="form-select" @bind="@_textEditor" required>
@if (_textEditorProviders != null) @if (_textEditors != null)
{ {
@foreach (var provider in _textEditorProviders) @foreach (var textEditor in _textEditors)
{ {
<option value="@provider.EditorType">@provider.Name</option> <option value="@textEditor.Value">@textEditor.Key</option>
} }
} }
</select> </select>
@ -428,8 +428,8 @@
private string _containertype = ""; private string _containertype = "";
private string _admincontainertype = ""; private string _admincontainertype = "";
private IEnumerable<ITextEditorProvider> _textEditorProviders; private Dictionary<string, string> _textEditors = new Dictionary<string, string>();
private string _textEditorProvider = ""; private string _textEditor = "";
private string _imageFiles = string.Empty; private string _imageFiles = string.Empty;
private string _uploadableFiles = string.Empty; private string _uploadableFiles = string.Empty;
@ -515,8 +515,12 @@
_admincontainertype = (!string.IsNullOrEmpty(site.AdminContainerType)) ? site.AdminContainerType : Constants.DefaultAdminContainer; _admincontainertype = (!string.IsNullOrEmpty(site.AdminContainerType)) ? site.AdminContainerType : Constants.DefaultAdminContainer;
// functionality // functionality
_textEditorProviders = ServiceProvider.GetServices<ITextEditorProvider>(); var textEditors = ServiceProvider.GetServices<ITextEditor>();
_textEditorProvider = SettingService.GetSetting(settings, "TextEditorProvider", Constants.DefaultTextEditorProvider); foreach (var textEditor in textEditors)
{
_textEditors.Add(textEditor.Name, Utilities.GetFullTypeName(textEditor.GetType().AssemblyQualifiedName));
}
_textEditor = SettingService.GetSetting(settings, "TextEditor", Constants.DefaultTextEditor);
_imageFiles = SettingService.GetSetting(settings, "ImageFiles", Constants.ImageFiles); _imageFiles = SettingService.GetSetting(settings, "ImageFiles", Constants.ImageFiles);
_imageFiles = (string.IsNullOrEmpty(_imageFiles)) ? Constants.ImageFiles : _imageFiles; _imageFiles = (string.IsNullOrEmpty(_imageFiles)) ? Constants.ImageFiles : _imageFiles;
_uploadableFiles = SettingService.GetSetting(settings, "UploadableFiles", Constants.UploadableFiles); _uploadableFiles = SettingService.GetSetting(settings, "UploadableFiles", Constants.UploadableFiles);
@ -724,7 +728,7 @@
settings = SettingService.SetSetting(settings, "NotificationRetention", _retention.ToString(), true); settings = SettingService.SetSetting(settings, "NotificationRetention", _retention.ToString(), true);
// functionality // functionality
settings = SettingService.SetSetting(settings, "TextEditorProvider", _textEditorProvider); settings = SettingService.SetSetting(settings, "TextEditor", _textEditor);
settings = SettingService.SetSetting(settings, "ImageFiles", (_imageFiles != Constants.ImageFiles) ? _imageFiles.Replace(" ", "") : "", false); settings = SettingService.SetSetting(settings, "ImageFiles", (_imageFiles != Constants.ImageFiles) ? _imageFiles.Replace(" ", "") : "", false);
settings = SettingService.SetSetting(settings, "UploadableFiles", (_uploadableFiles != Constants.UploadableFiles) ? _uploadableFiles.Replace(" ", "") : "", false); settings = SettingService.SetSetting(settings, "UploadableFiles", (_uploadableFiles != Constants.UploadableFiles) ? _uploadableFiles.Replace(" ", "") : "", false);

View File

@ -177,6 +177,8 @@
</div> </div>
@code { @code {
public string Name => "QuillJS";
private string resourceType = "Oqtane.Modules.Controls.QuillJSTextEditor, Oqtane.Client"; private string resourceType = "Oqtane.Modules.Controls.QuillJSTextEditor, Oqtane.Client";
private bool _settingsLoaded; private bool _settingsLoaded;

View File

@ -14,7 +14,7 @@
</div> </div>
@code { @code {
private string _textEditorProvider; private string _textEditorType;
private RenderFragment _textEditorComponent; private RenderFragment _textEditorComponent;
private ITextEditor _textEditor; private ITextEditor _textEditor;
@ -35,7 +35,7 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
_textEditorProvider = await GetTextEditorType(); _textEditorType = await GetTextEditorType();
} }
protected override void OnParametersSet() protected override void OnParametersSet()
@ -63,9 +63,9 @@
private void CreateTextEditor(RenderTreeBuilder builder) private void CreateTextEditor(RenderTreeBuilder builder)
{ {
if(!string.IsNullOrEmpty(_textEditorProvider)) if(!string.IsNullOrEmpty(_textEditorType))
{ {
var editorType = Type.GetType(_textEditorProvider); var editorType = Type.GetType(_textEditorType);
if (editorType != null) if (editorType != null)
{ {
builder.OpenComponent(0, editorType); builder.OpenComponent(0, editorType);
@ -111,18 +111,18 @@
private async Task<string> GetTextEditorType() private async Task<string> GetTextEditorType()
{ {
const string EditorSettingName = "TextEditorProvider"; const string EditorSettingName = "TextEditor";
if(!string.IsNullOrEmpty(Provider)) if(!string.IsNullOrEmpty(Provider))
{ {
var provider = ServiceProvider.GetServices<ITextEditorProvider>().FirstOrDefault(i => i.Name.Equals(Provider, StringComparison.OrdinalIgnoreCase)); var provider = ServiceProvider.GetServices<ITextEditor>().FirstOrDefault(i => i.Name.Equals(Provider, StringComparison.OrdinalIgnoreCase));
if(provider != null) if(provider != null)
{ {
return provider.EditorType; return Utilities.GetFullTypeName(provider.GetType().AssemblyQualifiedName);
} }
} }
var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId); var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId);
return SettingService.GetSetting(settings, EditorSettingName, Constants.DefaultTextEditorProvider); return SettingService.GetSetting(settings, EditorSettingName, Constants.DefaultTextEditor);
} }
} }

View File

@ -7,6 +7,8 @@
</div> </div>
@code { @code {
public string Name => "TextArea";
private ElementReference _editor; private ElementReference _editor;
private string _content; private string _content;

View File

@ -1,11 +0,0 @@
using Oqtane.Interfaces;
namespace Oqtane.Providers
{
public class QuillJSTextEditorProvider : ITextEditorProvider
{
public string Name => "QuillJS";
public string EditorType => "Oqtane.Modules.Controls.QuillJSTextEditor, Oqtane.Client";
}
}

View File

@ -1,11 +0,0 @@
using Oqtane.Interfaces;
namespace Oqtane.Providers
{
public class TextAreaTextEditorProvider : ITextEditorProvider
{
public string Name => "TextArea";
public string EditorType => "Oqtane.Modules.Controls.TextAreaTextEditor, Oqtane.Client";
}
}

View File

@ -426,10 +426,10 @@
<data name="Runtime.Text" xml:space="preserve"> <data name="Runtime.Text" xml:space="preserve">
<value>Interactivity:</value> <value>Interactivity:</value>
</data> </data>
<data name="TextEditorProvider.HelpText" xml:space="preserve"> <data name="TextEditor.HelpText" xml:space="preserve">
<value>Select the text editor for the site</value> <value>Select the text editor for the site</value>
</data> </data>
<data name="TextEditorProvider.Text" xml:space="preserve"> <data name="TextEditor.Text" xml:space="preserve">
<value>Text Editor:</value> <value>Text Editor:</value>
</data> </data>
<data name="Functionality" xml:space="preserve"> <data name="Functionality" xml:space="preserve">

View File

@ -102,7 +102,10 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddScoped<ISearchResultsService, SearchResultsService>(); services.AddScoped<ISearchResultsService, SearchResultsService>();
services.AddScoped<ISearchService, SearchService>(); services.AddScoped<ISearchService, SearchService>();
services.AddScoped<ISearchProvider, DatabaseSearchProvider>(); services.AddScoped<ISearchProvider, DatabaseSearchProvider>();
// providers
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.QuillJSTextEditor>();
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.TextAreaTextEditor>();
return services; return services;
} }
@ -150,10 +153,6 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddTransient<IUpgradeManager, UpgradeManager>(); services.AddTransient<IUpgradeManager, UpgradeManager>();
services.AddTransient<IUserManager, UserManager>(); services.AddTransient<IUserManager, UserManager>();
// providers
services.AddTransient<ITextEditorProvider, QuillJSTextEditorProvider>();
services.AddTransient<ITextEditorProvider, TextAreaTextEditorProvider>();
// obsolete - replaced by ITenantManager // obsolete - replaced by ITenantManager
services.AddTransient<ITenantResolver, TenantResolver>(); services.AddTransient<ITenantResolver, TenantResolver>();

View File

@ -7,6 +7,8 @@ namespace Oqtane.Interfaces
/// </summary> /// </summary>
public interface ITextEditor public interface ITextEditor
{ {
string Name { get; }
/// <summary> /// <summary>
/// initializes the editor with the initialize content. /// initializes the editor with the initialize content.
/// </summary> /// </summary>

View File

@ -1,18 +0,0 @@
namespace Oqtane.Interfaces
{
/// <summary>
/// Rich text editor provider interface.
/// </summary>
public interface ITextEditorProvider
{
/// <summary>
/// The text editor provider name.
/// </summary>
string Name { get; }
/// <summary>
/// The text editor type full name.
/// </summary>
string EditorType { get; }
}
}

View File

@ -81,7 +81,7 @@ namespace Oqtane.Shared
public const string DefaultSearchProviderName = "DatabaseSearchProvider"; public const string DefaultSearchProviderName = "DatabaseSearchProvider";
public static readonly string[] InternalPagePaths = { "login", "register", "reset", "404" }; public static readonly string[] InternalPagePaths = { "login", "register", "reset", "404" };
public const string DefaultTextEditorProvider = "Oqtane.Modules.Controls.QuillJSTextEditor, Oqtane.Client"; public const string DefaultTextEditor = "Oqtane.Modules.Controls.QuillJSTextEditor, Oqtane.Client";
// Obsolete constants // Obsolete constants