diff --git a/Oqtane.Client/Installer/Controls/MySQLConfig.razor b/Oqtane.Client/Installer/Controls/MySQLConfig.razor index 98e64a21..1d41a9d9 100644 --- a/Oqtane.Client/Installer/Controls/MySQLConfig.razor +++ b/Oqtane.Client/Installer/Controls/MySQLConfig.razor @@ -45,7 +45,7 @@ private string _passwordType = "password"; private string _togglePassword = string.Empty; - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { _togglePassword = SharedLocalizer["ShowPassword"]; } diff --git a/Oqtane.Client/Installer/Controls/PostgreSQLConfig.razor b/Oqtane.Client/Installer/Controls/PostgreSQLConfig.razor index a06581e6..f9413fbb 100644 --- a/Oqtane.Client/Installer/Controls/PostgreSQLConfig.razor +++ b/Oqtane.Client/Installer/Controls/PostgreSQLConfig.razor @@ -59,7 +59,7 @@ private string _passwordType = "password"; private string _togglePassword = string.Empty; - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { _togglePassword = SharedLocalizer["ShowPassword"]; } diff --git a/Oqtane.Client/Installer/Controls/SqlServerConfig.razor b/Oqtane.Client/Installer/Controls/SqlServerConfig.razor index 5eed9649..0f96c9ff 100644 --- a/Oqtane.Client/Installer/Controls/SqlServerConfig.razor +++ b/Oqtane.Client/Installer/Controls/SqlServerConfig.razor @@ -75,7 +75,7 @@ private string _encryption = "false"; private string _trustservercertificate = "false"; - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { _togglePassword = SharedLocalizer["ShowPassword"]; } diff --git a/Oqtane.Client/Modules/Admin/Pages/Add.razor b/Oqtane.Client/Modules/Admin/Pages/Add.razor index e934ed9d..221b1696 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Add.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Add.razor @@ -3,6 +3,7 @@ @inject NavigationManager NavigationManager @inject IPageService PageService @inject IThemeService ThemeService +@inject ISystemService SystemService @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer @@ -112,7 +113,7 @@
- +
@@ -218,7 +219,7 @@ private string _url; private string _ispersonalizable = "False"; private string _title; - private string _icon { get; set; } = string.Empty; + private string _icon = string.Empty; private string _themetype = string.Empty; private string _containertype = string.Empty; private string _headcontent; @@ -230,7 +231,7 @@ private RenderFragment ThemeSettingsComponent { get; set; } private bool _refresh = false; protected Page _parent = null; - protected Dictionary IconList = new(); + protected Dictionary _icons; protected override async Task OnInitializedAsync() { @@ -245,20 +246,7 @@ _parentid = _parent.PageId.ToString(); } } - - Type iconsType = typeof(Icons); - System.Reflection.FieldInfo[] fields = iconsType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.GetField); - - foreach (System.Reflection.FieldInfo field in fields) - { - if (field.FieldType == typeof(string)) - { - string fieldName = field.Name; - string fieldValue = (string)field.GetValue(null); - - IconList.Add(fieldName, fieldValue); - } - } + _icons = await SystemService.GetIconsAsync(); // 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 bf5f6c0f..7a395148 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Edit.razor @@ -5,6 +5,7 @@ @inject IPageService PageService @inject IPageModuleService PageModuleService @inject IThemeService ThemeService +@inject ISystemService SystemService @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer @@ -124,7 +125,7 @@
- +
@@ -295,7 +296,7 @@ private string _url; private string _ispersonalizable; private string _title; - private string _icon { get; set; } + private string _icon; private string _themetype; private string _containertype = "-"; private Type _themeSettingsType; @@ -315,7 +316,8 @@ private bool _refresh = false; protected Page _page = null; protected Page _parent = null; - protected Dictionary IconList = new(); + protected Dictionary _icons; + protected override async Task OnInitializedAsync() { try @@ -323,6 +325,7 @@ _children = PageState.Pages.Where(item => item.ParentId == null).ToList(); _pageId = Int32.Parse(PageState.QueryString["id"]); _page = await PageService.GetPageAsync(_pageId); + _icons = await SystemService.GetIconsAsync(); if (_page != null && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, _page.PermissionList)) { @@ -355,20 +358,6 @@ _icon = _page.Icon; _ispersonalizable = _page.IsPersonalizable.ToString(); - Type iconsType = typeof(Icons); - System.Reflection.FieldInfo[] fields = iconsType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.GetField); - - foreach (System.Reflection.FieldInfo field in fields) - { - if (field.FieldType == typeof(string)) - { - string fieldName = field.Name; - string fieldValue = (string)field.GetValue(null); - - IconList.Add(fieldName, fieldValue); - } - } - // appearance _title = _page.Title; _themetype = _page.ThemeType; diff --git a/Oqtane.Client/Services/Interfaces/ISystemService.cs b/Oqtane.Client/Services/Interfaces/ISystemService.cs index 4ecc757c..3f4e194d 100644 --- a/Oqtane.Client/Services/Interfaces/ISystemService.cs +++ b/Oqtane.Client/Services/Interfaces/ISystemService.cs @@ -9,13 +9,13 @@ namespace Oqtane.Services public interface ISystemService { /// - /// returns a key-value directory with the current system configuration information + /// returns a key-value dictionary with the current system configuration information /// /// Task> GetSystemInfoAsync(); /// - /// returns a key-value directory with the current system information - "environment" or "configuration" + /// returns a key-value dictionary with the current system information - "environment" or "configuration" /// /// Task> GetSystemInfoAsync(string type); @@ -32,5 +32,11 @@ namespace Oqtane.Services /// /// Task UpdateSystemInfoAsync(Dictionary settings); + + /// + /// returns a key-value dictionary with default system icons + /// + /// + Task> GetIconsAsync(); } } diff --git a/Oqtane.Client/Services/SystemService.cs b/Oqtane.Client/Services/SystemService.cs index 1d632dc5..d6ab8268 100644 --- a/Oqtane.Client/Services/SystemService.cs +++ b/Oqtane.Client/Services/SystemService.cs @@ -33,5 +33,10 @@ namespace Oqtane.Services { await PostJsonAsync(Apiurl, settings); } + + public async Task> GetIconsAsync() + { + return await GetJsonAsync>($"{Apiurl}/icons"); + } } } diff --git a/Oqtane.Server/Controllers/SystemController.cs b/Oqtane.Server/Controllers/SystemController.cs index ca95428a..184b650f 100644 --- a/Oqtane.Server/Controllers/SystemController.cs +++ b/Oqtane.Server/Controllers/SystemController.cs @@ -74,7 +74,6 @@ namespace Oqtane.Controllers return systeminfo; } - // GET: api/ [HttpGet("{key}/{value}")] [Authorize(Roles = RoleNames.Host)] @@ -94,6 +93,36 @@ namespace Oqtane.Controllers } } + // GET: api//icons + [HttpGet("icons")] + public Dictionary Get() + { + var icons = new Dictionary(); + + // use reflection to get list of icons from Icons class + Type iconsType = typeof(Icons); + System.Reflection.FieldInfo[] fields = iconsType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.GetField); + foreach (System.Reflection.FieldInfo field in fields) + { + if (field.FieldType == typeof(string)) + { + // add spacing between words based on capitalization + var name = ""; + for (int index = 0; index < field.Name.Length; index++) + { + name += ((index > 0 && field.Name[index] == Char.ToUpper(field.Name[index])) ? " " : "") + field.Name[index]; + } + + string fieldName = name; + string fieldValue = (string)field.GetValue(null); + + icons.Add(fieldName, fieldValue); + } + } + + return icons; + } + private void UpdateSetting(string key, object value) { switch (key.ToLower())