Skip to content

Commit

Permalink
GH-112 Simplify (and possibly fasten) extraction of breadcrumb nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-yagodin committed Nov 18, 2019
1 parent 23baebf commit aa4cb89
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions R7.Epsilon/Menus/DropCrumb/DropCrumb.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,18 @@
return (NodeActiveCssClass (node) + " " + NodeDisabledCssClass (node)).Trim ();
}

MenuNode FindCurrentNodeRecursive (MenuNode node)
{
if (node.Selected) {
return node;
}

foreach (var node1 in node.Children) {
var node2 = FindCurrentNodeRecursive (node1);
if (node2 != null) {
return node2;
}
}

return null;
}

IList<MenuNode> GetBreadcrumbNodes (MenuNode root)
{
var currentNode = FindCurrentNodeRecursive (root);
var nodes = new List<MenuNode> ();
while (currentNode != null) {
nodes.Insert (0, currentNode);
currentNode = currentNode.Parent;
var node = root;
var nodes = new List<MenuNode> { node };
while (!node.Selected && node.HasChildren ()) {
var breadcrumbNode = node.Children.FirstOrDefault (n => n.Breadcrumb);
if (breadcrumbNode == null) {
break;
}
nodes.Add (breadcrumbNode);
node = breadcrumbNode;
}

return nodes;
}

Expand Down

0 comments on commit aa4cb89

Please sign in to comment.