move icon loading reflection logic to server

This commit is contained in:
sbwalker
2023-08-23 15:25:39 -04:00
parent 34ae731959
commit 82d128974c
8 changed files with 57 additions and 40 deletions

View File

@ -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)))