Merge pull request #3178 from sbwalker/dev
move icon loading reflection logic to server
This commit is contained in:
commit
f5ce48a7c2
|
@ -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"];
|
||||
}
|
||||
|
|
|
@ -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"];
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
private string _encryption = "false";
|
||||
private string _trustservercertificate = "false";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_togglePassword = SharedLocalizer["ShowPassword"];
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@inject NavigationManager NavigationManager
|
||||
@inject IPageService PageService
|
||||
@inject IThemeService ThemeService
|
||||
@inject ISystemService SystemService
|
||||
@inject IStringLocalizer<Add> Localizer
|
||||
@inject IStringLocalizer<SharedResources> SharedLocalizer
|
||||
|
||||
|
@ -112,7 +113,7 @@
|
|||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="icon" HelpText="Optionally provide an icon class name for this page which will be displayed in the site navigation" ResourceKey="Icon">Icon: </Label>
|
||||
<div class="col-sm-8">
|
||||
<InputList Value="@_icon" ValueChanged="IconChanged" InputValues="@IconList" />
|
||||
<InputList Value="@_icon" ValueChanged="IconChanged" InputValues="@_icons" />
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<i class="@_icon"></i>
|
||||
|
@ -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<string, string> IconList = new();
|
||||
protected Dictionary<string, string> _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)))
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
@inject IPageService PageService
|
||||
@inject IPageModuleService PageModuleService
|
||||
@inject IThemeService ThemeService
|
||||
@inject ISystemService SystemService
|
||||
@inject IStringLocalizer<Edit> Localizer
|
||||
@inject IStringLocalizer<SharedResources> SharedLocalizer
|
||||
|
||||
|
@ -124,7 +125,7 @@
|
|||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="icon" HelpText="Optionally provide an icon class name for this page which will be displayed in the site navigation" ResourceKey="Icon">Icon: </Label>
|
||||
<div class="col-sm-8">
|
||||
<InputList Value="@_icon" ValueChanged="IconChanged" InputValues="@IconList" />
|
||||
<InputList Value="@_icon" ValueChanged="IconChanged" InputValues="@_icons" />
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<i class="@_icon"></i>
|
||||
|
@ -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<string, string> IconList = new();
|
||||
protected Dictionary<string, string> _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;
|
||||
|
|
|
@ -9,13 +9,13 @@ namespace Oqtane.Services
|
|||
public interface ISystemService
|
||||
{
|
||||
/// <summary>
|
||||
/// returns a key-value directory with the current system configuration information
|
||||
/// returns a key-value dictionary with the current system configuration information
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<string, object>> GetSystemInfoAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 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"
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<string, object>> GetSystemInfoAsync(string type);
|
||||
|
@ -32,5 +32,11 @@ namespace Oqtane.Services
|
|||
/// <param name="settings"></param>
|
||||
/// <returns></returns>
|
||||
Task UpdateSystemInfoAsync(Dictionary<string, object> settings);
|
||||
|
||||
/// <summary>
|
||||
/// returns a key-value dictionary with default system icons
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<string, string>> GetIconsAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,5 +33,10 @@ namespace Oqtane.Services
|
|||
{
|
||||
await PostJsonAsync(Apiurl, settings);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, string>> GetIconsAsync()
|
||||
{
|
||||
return await GetJsonAsync<Dictionary<string, string>>($"{Apiurl}/icons");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,6 @@ namespace Oqtane.Controllers
|
|||
return systeminfo;
|
||||
}
|
||||
|
||||
|
||||
// GET: api/<controller>
|
||||
[HttpGet("{key}/{value}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
|
@ -94,6 +93,36 @@ namespace Oqtane.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
// GET: api/<controller>/icons
|
||||
[HttpGet("icons")]
|
||||
public Dictionary<string, string> Get()
|
||||
{
|
||||
var icons = new Dictionary<string, string>();
|
||||
|
||||
// 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())
|
||||
|
|
Loading…
Reference in New Issue
Block a user