Move menu items under the new administration menu

pull/892/head
Halil ibrahim Kalkan 6 years ago
parent be76678c74
commit 03246e0791

@ -1,5 +1,5 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Volo.Abp.Ui.Navigation;
namespace Volo.Abp.UI.Navigation
{
@ -29,11 +29,11 @@ namespace Volo.Abp.UI.Navigation
/// <inheritdoc cref="IHasMenuItems.Items"/>
[NotNull]
public IList<ApplicationMenuItem> Items { get; } //TODO: Create a specialized collection (that can contain AddAfter for example)
public ApplicationMenuItemList Items { get; }
/// <summary>
/// Can be used to store a custom object related to this menu.
/// TODO: Conver to dictionary!
/// TODO: Convert to dictionary!
/// </summary>
[CanBeNull]
public object CustomData { get; set; }
@ -47,7 +47,7 @@ namespace Volo.Abp.UI.Navigation
Name = name;
DisplayName = displayName ?? Name;
Items = new List<ApplicationMenuItem>();
Items = new ApplicationMenuItemList();
}
/// <summary>
@ -60,5 +60,10 @@ namespace Volo.Abp.UI.Navigation
Items.Add(menuItem);
return this;
}
public override string ToString()
{
return $"[ApplicationMenu] Name = {Name}";
}
}
}

@ -1,5 +1,5 @@
using System.Linq;
using JetBrains.Annotations;
using System.Linq;
using Volo.Abp.Ui.Navigation;
namespace Volo.Abp.UI.Navigation
@ -7,13 +7,18 @@ namespace Volo.Abp.UI.Navigation
public static class ApplicationMenuExtensions
{
[NotNull]
public static ApplicationMenuItem GetAdministration(this ApplicationMenu applicationMenu)
public static ApplicationMenuItem GetAdministration(
[NotNull] this ApplicationMenu applicationMenu)
{
return applicationMenu.GetMenuItem(DefaultMenuNames.Application.Main.Administration);
return applicationMenu.GetMenuItem(
DefaultMenuNames.Application.Main.Administration
);
}
[NotNull]
public static ApplicationMenuItem GetMenuItem(this IHasMenuItems menuWithItems, string menuItemName)
public static ApplicationMenuItem GetMenuItem(
[NotNull] this IHasMenuItems menuWithItems,
string menuItemName)
{
var menuItem = menuWithItems.GetMenuItemOrNull(menuItemName);
if (menuItem == null)
@ -26,10 +31,29 @@ namespace Volo.Abp.UI.Navigation
[CanBeNull]
public static ApplicationMenuItem GetMenuItemOrNull(
this IHasMenuItems menuWithItems,
[NotNull] this IHasMenuItems menuWithItems,
string menuItemName)
{
Check.NotNull(menuWithItems, nameof(menuWithItems));
return menuWithItems.Items.FirstOrDefault(mi => mi.Name == menuItemName);
}
[NotNull]
public static IHasMenuItems SetSubItemOrder(
[NotNull] this IHasMenuItems menuWithItems,
string menuItemName,
int order)
{
Check.NotNull(menuWithItems, nameof(menuWithItems));
var menuItem = menuWithItems.GetMenuItemOrNull(menuItemName);
if (menuItem != null)
{
menuItem.Order = order;
}
return menuWithItems;
}
}
}

@ -1,5 +1,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Volo.Abp.Ui.Navigation;
namespace Volo.Abp.UI.Navigation
{
@ -68,7 +69,7 @@ namespace Volo.Abp.UI.Navigation
/// <inheritdoc cref="IHasMenuItems.Items"/>
[NotNull]
public IList<ApplicationMenuItem> Items { get; }
public ApplicationMenuItemList Items { get; }
/// <summary>
/// Can be used to store a custom object related to this menu item. Optional.
@ -109,7 +110,7 @@ namespace Volo.Abp.UI.Navigation
ElementId = elementId ?? GetDefaultElementId();
CssClass = cssClass;
Items = new List<ApplicationMenuItem>();
Items = new ApplicationMenuItemList();
}
/// <summary>
@ -127,5 +128,10 @@ namespace Volo.Abp.UI.Navigation
{
return "MenuItem_" + Name;
}
public override string ToString()
{
return $"[ApplicationMenuItem] Name = {Name}";
}
}
}

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.UI.Navigation;
namespace Volo.Abp.Ui.Navigation
{
public class ApplicationMenuItemList : List<ApplicationMenuItem>
{
public ApplicationMenuItemList()
{
}
public ApplicationMenuItemList(int capacity)
: base(capacity)
{
}
public ApplicationMenuItemList(IEnumerable<ApplicationMenuItem> collection)
: base(collection)
{
}
public void Normalize()
{
RemoveEmptyItems();
Order();
}
private void RemoveEmptyItems()
{
RemoveAll(item => item.IsLeaf && item.Url.IsNullOrEmpty());
}
private void Order()
{
//TODO: Is there any way that is more performant?
var orderedItems = this.OrderBy(item => item.Order).ToArray();
Clear();
AddRange(orderedItems);
}
}
}

@ -1,4 +1,4 @@
using System.Collections.Generic;
using Volo.Abp.Ui.Navigation;
namespace Volo.Abp.UI.Navigation
{
@ -7,6 +7,6 @@ namespace Volo.Abp.UI.Navigation
/// <summary>
/// Menu items.
/// </summary>
IList<ApplicationMenuItem> Items { get; }
ApplicationMenuItemList Items { get; }
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
@ -38,10 +39,14 @@ namespace Volo.Abp.UI.Navigation
return menu;
}
protected virtual void NormalizeMenu(ApplicationMenu menu)
protected virtual void NormalizeMenu(IHasMenuItems menuWithItems)
{
//TODO: Should also consider sub menus, recursively, bottom to top!
menu.Items.RemoveAll(item => item.IsLeaf && item.Url.IsNullOrEmpty());
foreach (var menuItem in menuWithItems.Items)
{
NormalizeMenu(menuItem);
}
menuWithItems.Items.Normalize();
}
}
}

@ -29,6 +29,9 @@ namespace Volo.Abp.UI.Navigation
mainMenu.Items[1].Items[0].Name.ShouldBe("Administration.UserManagement");
mainMenu.Items[1].Items[1].Name.ShouldBe("Administration.RoleManagement");
mainMenu.Items[1].Items[2].Name.ShouldBe("Administration.DashboardSettings");
mainMenu.Items[1].Items[3].Name.ShouldBe("Administration.SubMenu1");
mainMenu.Items[1].Items[3].Items[0].Name.ShouldBe("Administration.SubMenu1.1");
mainMenu.Items[1].Items[3].Items[1].Name.ShouldBe("Administration.SubMenu1.2");
}
[DependsOn(typeof(AbpUiNavigationModule))]
@ -89,6 +92,12 @@ namespace Volo.Abp.UI.Navigation
administration.AddItem(new ApplicationMenuItem("Administration.DashboardSettings", "Dashboard Settings", url: "/admin/settings/dashboard"));
administration.AddItem(
new ApplicationMenuItem("Administration.SubMenu1", "Sub menu 1")
.AddItem(new ApplicationMenuItem("Administration.SubMenu1.1", "Sub menu 1.1", url: "/submenu1/submenu1_1"))
.AddItem(new ApplicationMenuItem("Administration.SubMenu1.2", "Sub menu 1.2", url: "/submenu1/submenu1_2"))
);
return Task.CompletedTask;
}
}

@ -25,7 +25,16 @@ namespace Volo.Abp.SettingManagement.Web.Navigation
//TODO: Localize
//var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<IdentityResource>>();
context.Menu.AddItem(new ApplicationMenuItem(SettingManagementMenuNames.GroupName, "Settings", "/SettingManagement", icon: "fa fa-cog", order: int.MaxValue - 1000));
context.Menu
.GetAdministration()
.AddItem(
new ApplicationMenuItem(
SettingManagementMenuNames.GroupName,
"Settings",
"/SettingManagement",
icon: "fa fa-cog"
)
);
return Task.CompletedTask;
}

@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Volo.Abp.SettingManagement.Web.Navigation
namespace Volo.Abp.SettingManagement.Web.Navigation
{
public class SettingManagementMenuNames
{
public const string GroupName = "SettingManagement";
public const string Settings = GroupName + ".Settings";
}
}

Loading…
Cancel
Save