From 8b2e55a96978cc0994da2ada6256f0b8f71430a3 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Mon, 22 Jul 2024 13:31:24 -0400 Subject: [PATCH] remove ITextEditorProvider interface --- .../OqtaneServiceCollectionExtensions.cs | 5 ++++ Oqtane.Client/Modules/Admin/Site/Index.razor | 24 +++++++++++-------- .../Modules/Controls/QuillJSTextEditor.razor | 2 ++ .../Modules/Controls/RichTextEditor.razor | 16 ++++++------- .../Modules/Controls/TextAreaTextEditor.razor | 2 ++ .../Providers/QuillJSTextEditorProvider.cs | 11 --------- .../Providers/TextAreaTextEditorProvider.cs | 11 --------- .../Resources/Modules/Admin/Site/Index.resx | 4 ++-- .../OqtaneServiceCollectionExtensions.cs | 9 ++++--- Oqtane.Shared/Interfaces/ITextEditor.cs | 2 ++ .../Interfaces/ITextEditorProvider.cs | 18 -------------- Oqtane.Shared/Shared/Constants.cs | 2 +- 12 files changed, 40 insertions(+), 66 deletions(-) delete mode 100644 Oqtane.Client/Providers/QuillJSTextEditorProvider.cs delete mode 100644 Oqtane.Client/Providers/TextAreaTextEditorProvider.cs delete mode 100644 Oqtane.Shared/Interfaces/ITextEditorProvider.cs diff --git a/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs index 7dcb25759..8facf91fd 100644 --- a/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Components.Authorization; +using Oqtane.Interfaces; using Oqtane.Providers; using Oqtane.Services; using Oqtane.Shared; @@ -51,6 +52,10 @@ public static IServiceCollection AddOqtaneClientScopedServices(this IServiceColl services.AddScoped(); services.AddScoped(); + // providers + services.AddScoped(); + services.AddScoped(); + return services; } } diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index d51aa4a1c..b708149ce 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -131,14 +131,14 @@
- +
- + @if (_textEditors != null) { - @foreach (var provider in _textEditorProviders) + @foreach (var textEditor in _textEditors) { - + } } @@ -428,8 +428,8 @@ private string _containertype = ""; private string _admincontainertype = ""; - private IEnumerable _textEditorProviders; - private string _textEditorProvider = ""; + private Dictionary _textEditors = new Dictionary(); + private string _textEditor = ""; private string _imageFiles = string.Empty; private string _uploadableFiles = string.Empty; @@ -515,8 +515,12 @@ _admincontainertype = (!string.IsNullOrEmpty(site.AdminContainerType)) ? site.AdminContainerType : Constants.DefaultAdminContainer; // functionality - _textEditorProviders = ServiceProvider.GetServices(); - _textEditorProvider = SettingService.GetSetting(settings, "TextEditorProvider", Constants.DefaultTextEditorProvider); + var textEditors = ServiceProvider.GetServices(); + 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 = (string.IsNullOrEmpty(_imageFiles)) ? Constants.ImageFiles : _imageFiles; _uploadableFiles = SettingService.GetSetting(settings, "UploadableFiles", Constants.UploadableFiles); @@ -724,7 +728,7 @@ settings = SettingService.SetSetting(settings, "NotificationRetention", _retention.ToString(), true); // 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, "UploadableFiles", (_uploadableFiles != Constants.UploadableFiles) ? _uploadableFiles.Replace(" ", "") : "", false); diff --git a/Oqtane.Client/Modules/Controls/QuillJSTextEditor.razor b/Oqtane.Client/Modules/Controls/QuillJSTextEditor.razor index 05a40d9e6..db89b1811 100644 --- a/Oqtane.Client/Modules/Controls/QuillJSTextEditor.razor +++ b/Oqtane.Client/Modules/Controls/QuillJSTextEditor.razor @@ -177,6 +177,8 @@
@code { + public string Name => "QuillJS"; + private string resourceType = "Oqtane.Modules.Controls.QuillJSTextEditor, Oqtane.Client"; private bool _settingsLoaded; diff --git a/Oqtane.Client/Modules/Controls/RichTextEditor.razor b/Oqtane.Client/Modules/Controls/RichTextEditor.razor index 4a3699520..630b1ed74 100644 --- a/Oqtane.Client/Modules/Controls/RichTextEditor.razor +++ b/Oqtane.Client/Modules/Controls/RichTextEditor.razor @@ -14,7 +14,7 @@
@code { - private string _textEditorProvider; + private string _textEditorType; private RenderFragment _textEditorComponent; private ITextEditor _textEditor; @@ -35,7 +35,7 @@ protected override async Task OnInitializedAsync() { - _textEditorProvider = await GetTextEditorType(); + _textEditorType = await GetTextEditorType(); } protected override void OnParametersSet() @@ -63,9 +63,9 @@ 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) { builder.OpenComponent(0, editorType); @@ -111,18 +111,18 @@ private async Task GetTextEditorType() { - const string EditorSettingName = "TextEditorProvider"; + const string EditorSettingName = "TextEditor"; if(!string.IsNullOrEmpty(Provider)) { - var provider = ServiceProvider.GetServices().FirstOrDefault(i => i.Name.Equals(Provider, StringComparison.OrdinalIgnoreCase)); + var provider = ServiceProvider.GetServices().FirstOrDefault(i => i.Name.Equals(Provider, StringComparison.OrdinalIgnoreCase)); if(provider != null) { - return provider.EditorType; + return Utilities.GetFullTypeName(provider.GetType().AssemblyQualifiedName); } } var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId); - return SettingService.GetSetting(settings, EditorSettingName, Constants.DefaultTextEditorProvider); + return SettingService.GetSetting(settings, EditorSettingName, Constants.DefaultTextEditor); } } diff --git a/Oqtane.Client/Modules/Controls/TextAreaTextEditor.razor b/Oqtane.Client/Modules/Controls/TextAreaTextEditor.razor index d2e0185c8..f8bb95655 100644 --- a/Oqtane.Client/Modules/Controls/TextAreaTextEditor.razor +++ b/Oqtane.Client/Modules/Controls/TextAreaTextEditor.razor @@ -7,6 +7,8 @@
@code { + public string Name => "TextArea"; + private ElementReference _editor; private string _content; diff --git a/Oqtane.Client/Providers/QuillJSTextEditorProvider.cs b/Oqtane.Client/Providers/QuillJSTextEditorProvider.cs deleted file mode 100644 index 311743f87..000000000 --- a/Oqtane.Client/Providers/QuillJSTextEditorProvider.cs +++ /dev/null @@ -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"; - } -} diff --git a/Oqtane.Client/Providers/TextAreaTextEditorProvider.cs b/Oqtane.Client/Providers/TextAreaTextEditorProvider.cs deleted file mode 100644 index 3fde42311..000000000 --- a/Oqtane.Client/Providers/TextAreaTextEditorProvider.cs +++ /dev/null @@ -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"; - } -} diff --git a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx index 392a68a65..b232fe619 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx @@ -426,10 +426,10 @@ Interactivity: - + Select the text editor for the site - + Text Editor: diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index 883d50333..d9b31fd9d 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -102,7 +102,10 @@ internal static IServiceCollection AddOqtaneServerScopedServices(this IServiceCo services.AddScoped(); services.AddScoped(); services.AddScoped(); - + + // providers + services.AddScoped(); + services.AddScoped(); return services; } @@ -150,10 +153,6 @@ internal static IServiceCollection AddOqtaneTransientServices(this IServiceColle services.AddTransient(); services.AddTransient(); - // providers - services.AddTransient(); - services.AddTransient(); - // obsolete - replaced by ITenantManager services.AddTransient(); diff --git a/Oqtane.Shared/Interfaces/ITextEditor.cs b/Oqtane.Shared/Interfaces/ITextEditor.cs index 67f4efabb..f67441e51 100644 --- a/Oqtane.Shared/Interfaces/ITextEditor.cs +++ b/Oqtane.Shared/Interfaces/ITextEditor.cs @@ -7,6 +7,8 @@ namespace Oqtane.Interfaces /// public interface ITextEditor { + string Name { get; } + /// /// initializes the editor with the initialize content. /// diff --git a/Oqtane.Shared/Interfaces/ITextEditorProvider.cs b/Oqtane.Shared/Interfaces/ITextEditorProvider.cs deleted file mode 100644 index a00c68176..000000000 --- a/Oqtane.Shared/Interfaces/ITextEditorProvider.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Oqtane.Interfaces -{ - /// - /// Rich text editor provider interface. - /// - public interface ITextEditorProvider - { - /// - /// The text editor provider name. - /// - string Name { get; } - - /// - /// The text editor type full name. - /// - string EditorType { get; } - } -} diff --git a/Oqtane.Shared/Shared/Constants.cs b/Oqtane.Shared/Shared/Constants.cs index bcd3dc360..4fef964fd 100644 --- a/Oqtane.Shared/Shared/Constants.cs +++ b/Oqtane.Shared/Shared/Constants.cs @@ -81,7 +81,7 @@ public class Constants public const string DefaultSearchProviderName = "DatabaseSearchProvider"; 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