/// <summary> /// Retrieve all descendants /// </summary> /// <param name="node">the node</param> /// <returns></returns> private void GetDescendants(SiteMapNodeModel node) { foreach (var child in node.Children) { descendants.Add(child); GetDescendants(child); } }
/// <summary> /// Retrieve all ancestors /// </summary> /// <param name="node">the node</param> /// <returns></returns> private void GetAncestors(SiteMapNodeModel node) { if (node.Parent != null) { ancestors.Add(node.Parent); GetAncestors(node.Parent); } }
/// <summary> /// Retrieve all descendants /// </summary> /// <param name="node">the node</param> /// <returns></returns> private void GetDescendants(SiteMapNodeModel node) { var sortedNodes = SortSiteMapNodes <SiteMapNodeModel>(node.Children); foreach (var child in sortedNodes) { descendants.Add(child); GetDescendants(child); } }
/// <summary> /// Retrieve all descendants /// </summary> /// <param name="node">the node</param> /// <returns></returns> private void GetDescendants(SiteMapNodeModel node) { IEnumerable <SiteMapNodeModel> sortedNodes; if (node.Children.Any(x => x.Order != 0)) { sortedNodes = node.Children.OrderBy(x => x.Order); } else { sortedNodes = node.Children; } foreach (var child in sortedNodes) { descendants.Add(child); GetDescendants(child); } }
} // default = true public static string GetAttribute(this SiteMapNodeModel node, string name, bool inherit = true) { // look for parent with matching value if (inherit) { while (node != null && !node.Attributes.Any(x => x.Key == name)) { node = node.Parent; } } // return value from node if (node != null) { return(node.Attributes.FirstOrDefault(x => x.Key == name).Value as string); } return(null); }
/// <summary> /// Maps to SiteMapNodeModel. /// </summary> /// <param name="node">The node.</param> /// <param name="mvcNode">The MVC node.</param> /// <param name="sourceMetadata">The source metadata provided by the HtmlHelper.</param> /// <returns>SiteMapNodeModel instance.</returns> public static SiteMapNodeModel MapToSiteMapNodeModel(SiteMapNode node, MvcSiteMapNode mvcNode, IDictionary<string, object> sourceMetadata) { var nodeToAdd = new SiteMapNodeModel { Area = (mvcNode != null ? mvcNode.Area : ""), Controller = (mvcNode != null ? mvcNode.Controller : ""), Action = (mvcNode != null ? mvcNode.Action : ""), Title = node.Title, Description = node.Description, TargetFrame = (mvcNode == null ? "" : mvcNode.TargetFrame), ImageUrl = (mvcNode == null ? "" : mvcNode.ImageUrl), Url = node.Url, IsCurrentNode = node == node.Provider.CurrentNode, IsInCurrentPath = node.IsInCurrentPath(), IsRootNode = node == node.Provider.RootNode, IsClickable = (mvcNode == null || mvcNode.Clickable), RouteValues = (mvcNode != null ? mvcNode.RouteValues : new Dictionary<string, object>()), MetaAttributes = (mvcNode != null ? mvcNode.MetaAttributes : new Dictionary<string, string>()), SourceMetadata = sourceMetadata }; return nodeToAdd; }
public static SiteMapNodeModel MapToSiteMapNodeModel(SiteMapNode node, MvcSiteMapNode mvcNode, IDictionary<string, object> sourceMetadata) { var model = new SiteMapNodeModel() { Area = mvcNode != null ? mvcNode.Area : "", Controller = mvcNode != null ? mvcNode.Controller : "", Action = mvcNode != null ? mvcNode.Action : "", Title = node.Title, Description = node.Description, TargetFrame = mvcNode == null ? "" : mvcNode.TargetFrame, ImageUrl = mvcNode == null ? "" : mvcNode.ImageUrl, Url = node.Url, IsCurrentNode = node == node.Provider.CurrentNode, IsInCurrentPath = SiteMapNodeExtensions.IsInCurrentPath(node), IsRootNode = node == node.Provider.RootNode, IsClickable = mvcNode == null || mvcNode.Clickable, RouteValues = mvcNode != null ? mvcNode.RouteValues : (IDictionary<string, object>)new Dictionary<string, object>(), MetaAttributes = mvcNode != null ? mvcNode.MetaAttributes : (IDictionary<string, string>)new Dictionary<string, string>(), SourceMetadata = sourceMetadata }; return model; }
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="sourceMetadata">User-defined meta data.</param> /// <param name="startingNode">The starting node.</param> /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param> /// <returns>The model.</returns> internal static SiteMapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel, bool visibilityAffectsDescendants) { // Build model var model = new SiteMapHelperModel(); var node = startingNode; // Check if a starting node has been given if (node == null) { return model; } // Check ACL if (node.IsAccessibleToUser()) { // Add node? var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata, Int32.MaxValue, false, startingNodeInChildLevel, visibilityAffectsDescendants); // Check visibility if (node.IsVisible(sourceMetadata)) { model.Nodes.Add(nodeToAdd); // Add child nodes if (visibilityAffectsDescendants && startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Children); } } // Add child nodes if (!visibilityAffectsDescendants && startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Children); } } return model; }
public static string Group(this SiteMapNodeModel node, bool inherit = false) { return(node.GetAttribute("group", inherit)); }
/// <summary> /// Retrieve all descendants /// </summary> /// <param name="node">the node</param> /// <returns></returns> private void GetDescendants(SiteMapNodeModel node) { IEnumerable<SiteMapNodeModel> sortedNodes; if (node.Children.Any(x => x.Order != 0)) { sortedNodes = node.Children.OrderBy(x => x.Order); } else { sortedNodes = node.Children; } foreach (var child in sortedNodes) { descendants.Add(child); GetDescendants(child); } }
public static bool Visible(this SiteMapNodeModel node, bool inherit = false) { return(node.GetAttribute("visible", inherit) != "false"); } // default = true
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="sourceMetadata">User-defined meta data.</param> /// <param name="startingNode">The starting node.</param> /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param> /// <param name="showStartingNode">Show starting node if set to <c>true</c>.</param> /// <param name="maxDepth">The max depth.</param> /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param> /// <returns>The model.</returns> private static MenuHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent) { // Build model var model = new MenuHelperModel(); var node = startingNode; // Check if a starting node has been given if (node == null) { return model; } // Check ACL if (node.IsAccessibleToUser()) { // Add node? var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata, maxDepth, drillDownToCurrent, startingNodeInChildLevel); // Check visibility if (node.IsVisible(sourceMetadata)) { if (showStartingNode || !startingNodeInChildLevel) { model.Nodes.Add(nodeToAdd); } // Add child nodes if (startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Children); } } } return model; }
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="startingNode">The starting node.</param> /// <param name="sourceMetadata">User-defined meta data.</param> /// <returns>The model.</returns> private static SiteMapPathHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode) { // Build model var model = new SiteMapPathHelperModel(); var node = startingNode; while (node != null) { bool nodeVisible = node.IsVisible(sourceMetadata); if (nodeVisible && node.IsAccessibleToUser()) { var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata); model.Nodes.Add(nodeToAdd); } node = node.ParentNode; } model.Nodes.Reverse(); return model; }
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="sourceMetadata">User-defined meta data.</param> /// <param name="startingNode">The starting node.</param> /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param> /// <returns>The model.</returns> private static SiteMapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel) { // Build model var model = new SiteMapHelperModel(); var node = startingNode; // Check visibility and ACL if (node != null && node.IsVisible(sourceMetadata) && node.IsAccessibleToUser()) { // Add node var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata); model.Nodes.Add(nodeToAdd); // Add child nodes if (startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Descendants); } } return model; }
//<li class="nav-title">Theme</li> public static string Icon(this SiteMapNodeModel node, bool inherit = true) { return(node.GetAttribute("icon", inherit)); }