#18896: Fixing multi-depth hierarchy in MenuWidgets

Work Item: 18896

--HG--
branch : 1.x
This commit is contained in:
sebros@SEBROS3.redmond.corp.microsoft.com
2012-09-19 11:38:07 -07:00
parent 7482cdba07
commit 877d2d1394
@@ -41,6 +41,7 @@ namespace Orchard.Core.Navigation.Drivers {
return "MenuWidget"; return "MenuWidget";
} }
} }
protected override DriverResult Display(MenuWidgetPart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(MenuWidgetPart part, string displayType, dynamic shapeHelper) {
return ContentShape( "Parts_MenuWidget", () => { return ContentShape( "Parts_MenuWidget", () => {
if(part.Menu == null) { if(part.Menu == null) {
@@ -85,7 +86,7 @@ namespace Orchard.Core.Navigation.Drivers {
menuItem.Items = Enumerable.Empty<MenuItem>(); menuItem.Items = Enumerable.Empty<MenuItem>();
} }
// apply level limites to breadcrumb // apply level limits to breadcrumb
menuItems = menuItems.Skip(part.StartLevel - 1); menuItems = menuItems.Skip(part.StartLevel - 1);
if (part.Levels > 0) { if (part.Levels > 0) {
menuItems = menuItems.Take(part.Levels); menuItems = menuItems.Take(part.Levels);
@@ -119,7 +120,9 @@ namespace Orchard.Core.Navigation.Drivers {
IEnumerable<MenuItem> topLevelItems = menuItems.ToList(); IEnumerable<MenuItem> topLevelItems = menuItems.ToList();
if(part.StartLevel > 1) { if(part.StartLevel > 1) {
topLevelItems = selectedPath.Where(x => x.Selected); // the selected path will return the whole selected hierarchy
// intersecting will return the root selected menu item
topLevelItems = topLevelItems.Intersect(selectedPath.Where(x => x.Selected)).ToList();
} }
if (topLevelItems.Any()) { if (topLevelItems.Any()) {
@@ -133,19 +136,24 @@ namespace Orchard.Core.Navigation.Drivers {
topLevelItems = temp; topLevelItems = temp;
} }
// apply display level // apply display level ?
if(part.Levels > 0) { if(part.Levels > 0) {
var current = topLevelItems.ToList(); var current = topLevelItems.ToList();
for (; i < part.Levels - part.StartLevel; i++ ) { for (int j=1; j < part.Levels; j++ ) {
var temp = new List<MenuItem>(); var temp = new List<MenuItem>();
foreach (var menuItem in current) { foreach (var menuItem in current) {
temp.AddRange(menuItem.Items); temp.AddRange(menuItem.Items);
} }
current = temp; current = temp;
} }
foreach(var menuItem in current) {
topLevelItems = current;
// cut the sub-levels of any selected menu item
foreach (var menuItem in topLevelItems) {
menuItem.Items = Enumerable.Empty<MenuItem>(); menuItem.Items = Enumerable.Empty<MenuItem>();
} }
} }
menuItems = topLevelItems; menuItems = topLevelItems;
@@ -153,7 +161,6 @@ namespace Orchard.Core.Navigation.Drivers {
} }
menuShape.MenuName(menuName); menuShape.MenuName(menuName);
NavigationHelper.PopulateMenu(shapeHelper, menuShape, menuShape, menuItems); NavigationHelper.PopulateMenu(shapeHelper, menuShape, menuShape, menuItems);