Menu component refactoring

Login component refactoring
This commit is contained in:
Pavel Vesely
2020-04-26 20:24:00 +02:00
parent 7097caad69
commit 8dd2677b8f
6 changed files with 175 additions and 164 deletions

View File

@ -0,0 +1,45 @@
using System.Collections.Generic;
using System.Linq;
using Oqtane.Models;
using Oqtane.Security;
using Oqtane.Shared;
namespace Oqtane.Themes.Controls
{
public class MenuBase : ThemeControlBase
{
private List<Page> _menuPages;
protected IEnumerable<Page> MenuPages => _menuPages ?? (_menuPages = GetMenuPages().ToList());
protected string GetTarget(Page page)
{
return page.Url.StartsWith("http") ? "_new" : string.Empty;
}
protected string GetUrl(Page page)
{
return string.IsNullOrEmpty(page.Url) ? NavigateUrl(page.Path) : page.Url;
}
private IEnumerable<Page> GetMenuPages()
{
var securityLevel = int.MaxValue;
foreach (Page p in PageState.Pages.Where(item => item.IsNavigation && !item.IsDeleted))
{
if (p.Level <= securityLevel && UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions))
{
securityLevel = int.MaxValue;
yield return p;
}
else
{
if (securityLevel == int.MaxValue)
{
securityLevel = p.Level;
}
}
}
}
}
}