Reputation: 2006
I'm trying to make an dynamic menu for Dashboards, I have an register of Dashboards, this will just have an Description and Link. After register this, it has to appear in menu.
My new menu page will contain an frame to open this link inside the new page.
Has an easy way to alter the menu in serenity to has this behavior?
Upvotes: 2
Views: 590
Reputation: 2006
I have make this altering the NavigationModel.cs
After search alot, don't found any example doing that.
I have create a DynamicNavigation
like this:
public class DynamicDashboards : INavigationItemSource
{
public List<NavigationItemAttribute> GetItems()
{
var items = new List<NavigationItemAttribute>
{
new NavigationMenuAttribute(1000, "Dashboards", "icon-speedometer")
};
using (var connection = SqlConnections.NewByKey("Default"))
{
var dashboards = connection.List<DashboardsRow>();
foreach (var dashboard in dashboards)
items.Add(new NavigationLinkAttribute(1000,
path: "Dashboards/" + dashboard.Descricao.Replace("/", "//"),
url: "~/Dashboards/DefaultDashboard?link=" + dashboard.Link,
permission: CadastrosPermissionKeys.General,
icon: "icon-speedometer"));
}
return items;
}
}
Them on NavigationModel.cs
, i'm calling this class for insert it on Items
var dy = new DynamicDashboards();
var dashboardMenu = NavigationHelper.ConvertToNavigationItems(NavigationHelper.ByCategory(dy.GetItems()), x => x != null && x.StartsWith("~/") ? VirtualPathUtility.ToAbsolute(x) : x);
Items[0] = dashboardMenu[0]
In my case i have an default menu inside Dashboard, so i just adding this again on position [0], you can manipulate this like you want.
Upvotes: 1