From 261ed05fa39f7451e5cb839560df156c09a54e93 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Wed, 23 Aug 2023 16:43:14 -0400 Subject: [PATCH] Allow InputList component to be localizable and support multiple instances on a page. Implement icon localization in Page Add/Edit using IconResources.resx --- Oqtane.Client/IconResources.cs | 14 ++ Oqtane.Client/Modules/Admin/Pages/Add.razor | 4 +- Oqtane.Client/Modules/Admin/Pages/Edit.razor | 4 +- .../Modules/Controls/InputList.razor | 23 +++- Oqtane.Client/Resources/IconResources.resx | 123 ++++++++++++++++++ 5 files changed, 160 insertions(+), 8 deletions(-) create mode 100644 Oqtane.Client/IconResources.cs create mode 100644 Oqtane.Client/Resources/IconResources.resx diff --git a/Oqtane.Client/IconResources.cs b/Oqtane.Client/IconResources.cs new file mode 100644 index 00000000..a7c086ee --- /dev/null +++ b/Oqtane.Client/IconResources.cs @@ -0,0 +1,14 @@ +namespace Oqtane +{ + /// + /// Dummy class used to collect shared resource strings for this application + /// + /// + /// This class is mostly used with IStringLocalizer and IHtmlLocalizer interfaces. + /// The class must reside at the project root. + /// + public class IconResources + { + + } +} diff --git a/Oqtane.Client/Modules/Admin/Pages/Add.razor b/Oqtane.Client/Modules/Admin/Pages/Add.razor index 221b1696..78bdd021 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Add.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Add.razor @@ -113,7 +113,7 @@
- +
@@ -232,6 +232,7 @@ private bool _refresh = false; protected Page _parent = null; protected Dictionary _icons; + private string _iconresources = ""; protected override async Task OnInitializedAsync() { @@ -247,6 +248,7 @@ } } _icons = await SystemService.GetIconsAsync(); + _iconresources = typeof(IconResources).FullName; // if admin or user has edit access to parent page if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin) || (_parent != null && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, _parent.PermissionList))) diff --git a/Oqtane.Client/Modules/Admin/Pages/Edit.razor b/Oqtane.Client/Modules/Admin/Pages/Edit.razor index 7a395148..4af2a227 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Edit.razor @@ -125,7 +125,7 @@
- +
@@ -317,6 +317,7 @@ protected Page _page = null; protected Page _parent = null; protected Dictionary _icons; + private string _iconresources = ""; protected override async Task OnInitializedAsync() { @@ -326,6 +327,7 @@ _pageId = Int32.Parse(PageState.QueryString["id"]); _page = await PageService.GetPageAsync(_pageId); _icons = await SystemService.GetIconsAsync(); + _iconresources = Utilities.GetFullTypeName(typeof(IconResources).AssemblyQualifiedName); if (_page != null && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, _page.PermissionList)) { diff --git a/Oqtane.Client/Modules/Controls/InputList.razor b/Oqtane.Client/Modules/Controls/InputList.razor index 678bc4ac..c8a14924 100644 --- a/Oqtane.Client/Modules/Controls/InputList.razor +++ b/Oqtane.Client/Modules/Controls/InputList.razor @@ -1,24 +1,35 @@ @namespace Oqtane.Modules.Controls @using System.Linq.Expressions; -@inherits ModuleControlBase - - - @foreach(var iv in InputValues) +@inherits LocalizableComponent + + + + @foreach(var kvp in DataList) { - + } @code { + private string _id; + [Parameter] public string Value { get; set; } + [EditorRequired] [Parameter] - public Dictionary InputValues { get; set; } + public Dictionary DataList { get; set; } + [EditorRequired] [Parameter] public EventCallback ValueChanged { get; set; } + protected override void OnInitialized() + { + // create unique id for component + _id = "DataList_" + Guid.NewGuid().ToString("N"); + } + protected void OnChange(ChangeEventArgs e) { if (string.IsNullOrWhiteSpace(e.Value.ToString())) { return; } diff --git a/Oqtane.Client/Resources/IconResources.resx b/Oqtane.Client/Resources/IconResources.resx new file mode 100644 index 00000000..6dec88ae --- /dev/null +++ b/Oqtane.Client/Resources/IconResources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Home + + \ No newline at end of file