コード例 #1
0
        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);
        }
コード例 #2
0
        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()));
        }
コード例 #3
0
        public static int GetNodeLevel(this SiteMapNodeModel node)
        {
            var level = 0;

            while (node.Parent != null)
            {
                level++;
                node = node.Parent;
            }

            return(level);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 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);
 }
コード例 #12
0
        /// <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;
        }
コード例 #13
0
 public static bool HasAccessToNode(this IPrincipal principal, SiteMapNodeModel siteMapNodeModel)
 {
     return(_UserHasAccessToNode(principal, _GetNodeRoles(MvcSiteMapProvider.SiteMaps.Current.FindSiteMapNodeFromKey(siteMapNodeModel.Key))));
 }
コード例 #14
0
 public static string GetIconElement(this SiteMapNodeModel node)
 {
     return(node.GetNodeLevel() <= 2
         ? $"<i class=\"fa { node.ImageUrl.Trim('/') }\"></i>"
         : string.Empty);
 }
コード例 #15
0
        /// <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;
        }
コード例 #16
0
 private static IHtmlString GetArrowIcon(this SiteMapNodeModel node)
 {
     return(new MvcHtmlString(node.Children.Any()
         ? "<span class=\"fa fa-chevron-down\"></span>"
         : string.Empty));
 }
コード例 #17
0
 public static string GetStyleDisplayBlockIfIsInCurrentPath(this SiteMapNodeModel node)
 {
     return(node.IsInCurrentPath && IsNormalMenuSize() ? "display:block" : string.Empty);
 }
コード例 #18
0
 public static string GetActiveCssClassIfIsInCurrentPath(this SiteMapNodeModel node)
 {
     return(node.IsInCurrentPath && IsNormalMenuSize() ? "active" : string.Empty);
 }
コード例 #19
0
 public static string GetCurrentPageCssClassIfIsCurrentNode(this SiteMapNodeModel node)
 {
     return(node.IsCurrentNode ? "current-page" : string.Empty);
 }