Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ITextEditorProvider interface #4452

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components.Authorization;
using Oqtane.Interfaces;
using Oqtane.Providers;
using Oqtane.Services;
using Oqtane.Shared;
Expand Down Expand Up @@ -51,6 +52,10 @@ public static IServiceCollection AddOqtaneClientScopedServices(this IServiceColl
services.AddScoped<IVisitorService, VisitorService>();
services.AddScoped<ISyncService, SyncService>();

// providers
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.QuillJSTextEditor>();
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.TextAreaTextEditor>();

return services;
}
}
Expand Down
24 changes: 14 additions & 10 deletions Oqtane.Client/Modules/Admin/Site/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@
<Section Name="Functionality" Heading="Functionality" ResourceKey="Functionality">
<div class="container">
<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">
<select id="textEditorProvider" class="form-select" @bind="@_textEditorProvider" required>
@if (_textEditorProviders != null)
<select id="textEditor" class="form-select" @bind="@_textEditor" required>
@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>
Expand Down Expand Up @@ -428,8 +428,8 @@
private string _containertype = "";
private string _admincontainertype = "";

private IEnumerable<ITextEditorProvider> _textEditorProviders;
private string _textEditorProvider = "";
private Dictionary<string, string> _textEditors = new Dictionary<string, string>();
private string _textEditor = "";
private string _imageFiles = string.Empty;
private string _uploadableFiles = string.Empty;

Expand Down Expand Up @@ -515,8 +515,12 @@
_admincontainertype = (!string.IsNullOrEmpty(site.AdminContainerType)) ? site.AdminContainerType : Constants.DefaultAdminContainer;

// functionality
_textEditorProviders = ServiceProvider.GetServices<ITextEditorProvider>();
_textEditorProvider = SettingService.GetSetting(settings, "TextEditorProvider", Constants.DefaultTextEditorProvider);
var textEditors = ServiceProvider.GetServices<ITextEditor>();
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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions Oqtane.Client/Modules/Controls/QuillJSTextEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
</div>

@code {
public string Name => "QuillJS";

private string resourceType = "Oqtane.Modules.Controls.QuillJSTextEditor, Oqtane.Client";

private bool _settingsLoaded;
Expand Down
16 changes: 8 additions & 8 deletions Oqtane.Client/Modules/Controls/RichTextEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>

@code {
private string _textEditorProvider;
private string _textEditorType;
private RenderFragment _textEditorComponent;
private ITextEditor _textEditor;

Expand All @@ -35,7 +35,7 @@

protected override async Task OnInitializedAsync()
{
_textEditorProvider = await GetTextEditorType();
_textEditorType = await GetTextEditorType();
}

protected override void OnParametersSet()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -111,18 +111,18 @@

private async Task<string> GetTextEditorType()
{
const string EditorSettingName = "TextEditorProvider";
const string EditorSettingName = "TextEditor";

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)
{
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);
}
}
2 changes: 2 additions & 0 deletions Oqtane.Client/Modules/Controls/TextAreaTextEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</div>

@code {
public string Name => "TextArea";

private ElementReference _editor;
private string _content;

Expand Down
11 changes: 0 additions & 11 deletions Oqtane.Client/Providers/QuillJSTextEditorProvider.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Oqtane.Client/Providers/TextAreaTextEditorProvider.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Oqtane.Client/Resources/Modules/Admin/Site/Index.resx
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,10 @@
<data name="Runtime.Text" xml:space="preserve">
<value>Interactivity:</value>
</data>
<data name="TextEditorProvider.HelpText" xml:space="preserve">
<data name="TextEditor.HelpText" xml:space="preserve">
<value>Select the text editor for the site</value>
</data>
<data name="TextEditorProvider.Text" xml:space="preserve">
<data name="TextEditor.Text" xml:space="preserve">
<value>Text Editor:</value>
</data>
<data name="Functionality" xml:space="preserve">
Expand Down
9 changes: 4 additions & 5 deletions Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ internal static IServiceCollection AddOqtaneServerScopedServices(this IServiceCo
services.AddScoped<ISearchResultsService, SearchResultsService>();
services.AddScoped<ISearchService, SearchService>();
services.AddScoped<ISearchProvider, DatabaseSearchProvider>();


// providers
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.QuillJSTextEditor>();
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.TextAreaTextEditor>();

return services;
}
Expand Down Expand Up @@ -150,10 +153,6 @@ internal static IServiceCollection AddOqtaneTransientServices(this IServiceColle
services.AddTransient<IUpgradeManager, UpgradeManager>();
services.AddTransient<IUserManager, UserManager>();

// providers
services.AddTransient<ITextEditorProvider, QuillJSTextEditorProvider>();
services.AddTransient<ITextEditorProvider, TextAreaTextEditorProvider>();

// obsolete - replaced by ITenantManager
services.AddTransient<ITenantResolver, TenantResolver>();

Expand Down
2 changes: 2 additions & 0 deletions Oqtane.Shared/Interfaces/ITextEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Oqtane.Interfaces
/// </summary>
public interface ITextEditor
{
string Name { get; }

/// <summary>
/// initializes the editor with the initialize content.
/// </summary>
Expand Down
18 changes: 0 additions & 18 deletions Oqtane.Shared/Interfaces/ITextEditorProvider.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Oqtane.Shared/Shared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down