public static string MenuParentClass(this HtmlHelper htmlHelper, SiteMapNodeModel node) { var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action"); var currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller"); var exists = node.Children.Any(c => (string.Equals(c.Action, currentAction) && string.Equals(c.Controller, currentController))); return(exists ? "active" : string.Empty); }
public static IHtmlString GetNonClickableLinkElement(this SiteMapNodeModel node) { var tagBuilder = new TagBuilder("a"); tagBuilder.InnerHtml += node.GetIconElement(); tagBuilder.InnerHtml += node.Title; tagBuilder.InnerHtml += node.GetArrowIcon(); return(new MvcHtmlString(tagBuilder.ToString())); }
public static int GetNodeLevel(this SiteMapNodeModel node) { var level = 0; while (node.Parent != null) { level++; node = node.Parent; } return(level); }
internal static MenuHelperModel BuildModel(IMenuNode node) { var model = new MenuHelperModel(); if (node == null) { return(model); } if (node.IsAccessibleToUser()) { var nodeToAdd = new SiteMapNodeModel(node); 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); }
public static bool IsActiveNode(this SiteMapNodeModel model, ViewContext context) { bool isRootNode = model.IsRootNode; bool isCurrentPath = model.IsInCurrentPath; bool isCurrentNode = model.IsCurrentNode; //bool isCurrentNode = (context.Controller.ValueProvider.GetValue("action").RawValue.ToString().Equals(model.Action, StringComparison.CurrentCultureIgnoreCase) // && context.Controller.ValueProvider.GetValue("controller").RawValue.ToString().Equals(model.Controller, StringComparison.InvariantCultureIgnoreCase)); if (isCurrentNode) { return(true); } if (isCurrentPath && !isRootNode) { return(true); } return(false); }
/// <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), 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); }
/// <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 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); }
public static string GetNodeClass(this HtmlHelper htmlHelper, SiteMapNodeModel node) { return(node.Attributes.ContainsKey("Class") ? node.Attributes["Class"].ToString() : node.Parent != null ? node.Parent.Attributes["Class"].ToString(): string.Empty); }
/// <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, SiteMapNode 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(helper.SiteMap, node, sourceMetadata); model.Nodes.Add(nodeToAdd); } node = node.GetParentNode(helper.SiteMap); } model.Nodes.Reverse(); return model; }
public static bool HasAccessToNode(this IPrincipal principal, SiteMapNodeModel siteMapNodeModel) { return(_UserHasAccessToNode(principal, _GetNodeRoles(MvcSiteMapProvider.SiteMaps.Current.FindSiteMapNodeFromKey(siteMapNodeModel.Key)))); }
public static string GetIconElement(this SiteMapNodeModel node) { return(node.GetNodeLevel() <= 2 ? $"<i class=\"fa { node.ImageUrl.Trim('/') }\"></i>" : string.Empty); }
/// <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> /// <param name="visibilityAffectsDescendants"><b>true</b> if the visibility provider should affect the current node as well as all descendant nodes; otherwise <b>false</b>.</param> /// <returns>The model.</returns> internal static MenuHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent, bool visibilityAffectsDescendants) { // 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(helper.SiteMap, node, sourceMetadata, maxDepth, drillDownToCurrent, startingNodeInChildLevel, visibilityAffectsDescendants); // Check visibility if (node.IsVisible(sourceMetadata)) { if (showStartingNode || !startingNodeInChildLevel) { 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; }
private static IHtmlString GetArrowIcon(this SiteMapNodeModel node) { return(new MvcHtmlString(node.Children.Any() ? "<span class=\"fa fa-chevron-down\"></span>" : string.Empty)); }
public static string GetStyleDisplayBlockIfIsInCurrentPath(this SiteMapNodeModel node) { return(node.IsInCurrentPath && IsNormalMenuSize() ? "display:block" : string.Empty); }
public static string GetActiveCssClassIfIsInCurrentPath(this SiteMapNodeModel node) { return(node.IsInCurrentPath && IsNormalMenuSize() ? "active" : string.Empty); }
public static string GetCurrentPageCssClassIfIsCurrentNode(this SiteMapNodeModel node) { return(node.IsCurrentNode ? "current-page" : string.Empty); }