public void BuildModel_Case1_DontShowStartingNode_ShouldReturnAllNodesAtRootLevelWithoutStartingNode()
        {
            // @Html.MvcSiteMap().Menu(false)

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase1();
            var startingNode = siteMap.RootNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = MenuHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: true,
                showStartingNode: false,
                maxDepth: Int32.MaxValue,
                drillDownToCurrent: false,
                visibilityAffectsDescendants: true);

            // Assert
            Assert.AreEqual("About", result.Nodes[0].Title);
            Assert.AreEqual("Contact", result.Nodes[1].Title);

            // Check counts
            Assert.AreEqual(0, result.Nodes[0].Children.Count);
            Assert.AreEqual(0, result.Nodes[1].Children.Count);
        }
        /// <summary>
        /// Builds the model.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="startingNode">The starting node.</param>
        /// <returns>The model.</returns>
        private static SiteMapPathHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode)
        {
            // Build model
            var model = new SiteMapPathHelperModel();
            var node = startingNode;
            while (node != null)
            {
                var mvcNode = node as MvcSiteMapNode;

                // Check visibility
                bool nodeVisible = true;
                if (mvcNode != null)
                {
                    nodeVisible = mvcNode.VisibilityProvider.IsVisible(
                        node, HttpContext.Current, SourceMetadata);
                }

                // Check ACL
                if (nodeVisible && node.IsAccessibleToUser(HttpContext.Current))
                {
                    // Add node
                    var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, SourceMetadata);
                    model.Nodes.Add(nodeToAdd);
                }
                node = node.ParentNode;
            }
            model.Nodes.Reverse();

            return model;
        }
        public void BuildModel_Case1_StartingNodeNotInChildLevel_ShouldReturnHierarchicalNodes()
        {
            // @Html.MvcSiteMap().SiteMap(false)

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase1();
            var startingNode = siteMap.RootNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = SiteMapHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: false,
                visibilityAffectsDescendants: true);

            // Assert
            // Tree structure - 3 nodes
            Assert.AreEqual("Home", result.Nodes[0].Title);
            Assert.AreEqual("About", result.Nodes[0].Children[0].Title);
            Assert.AreEqual("Contact", result.Nodes[0].Children[1].Title);

            // Check Counts
            Assert.AreEqual(1, result.Nodes.Count);
            Assert.AreEqual(2, result.Nodes[0].Children.Count);
            Assert.AreEqual(0, result.Nodes[0].Children[0].Children.Count);
            Assert.AreEqual(0, result.Nodes[0].Children[1].Children.Count);
        }
Example #4
0
 /// <summary>
 /// Builds the model.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="startingNode">The starting node.</param>
 /// <returns>The model.</returns>
 private static SiteMapTitleHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode)
 {
     // Map to model
     var mvcNode = startingNode as MvcSiteMapNode;
     return new SiteMapTitleHelperModel
     {
         CurrentNode = SiteMapNodeModelMapper.MapToSiteMapNodeModel(startingNode, mvcNode, SourceMetadata)
     };
 }
Example #5
0
 /// <summary>
 /// Builds the model.
 /// </summary>
 /// <param name="helper">The helper.</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>
 /// <returns>The model.</returns>
 private static MainMenuSitemapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return(BuildModel(helper, startingNode, startingNodeInChildLevel, showStartingNode, maxDepth, false));
 }
Example #6
0
 /// <summary>
 /// Mains the menu.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="showStartingNode">if set to <c>true</c> [show starting node].</param>
 /// <param name="maxDepth">The max depth.</param>
 /// <returns>MvcHtmlString.</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, bool showStartingNode, int maxDepth)
 {
     return(MainMenu(helper, helper.Provider.RootNode, true, showStartingNode, maxDepth, false));
 }
Example #7
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, string templateName)
 {
     return(MainMenu(helper, templateName, helper.Provider.RootNode, true, true, Int32.MaxValue, false));
 }
Example #8
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="startingNodeInChildLevel">Show starting node 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>
 /// <returns>Html markup</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, string templateName, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return(MainMenu(helper, templateName, startingNode, startingNodeInChildLevel, showStartingNode, maxDepth, false));
 }
Example #9
0
 /// <summary>
 /// Builds the model.
 /// </summary>
 /// <param name="helper">The helper.</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, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent)
Example #10
0
 /// <summary>
 /// Gets previous node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="templateName">Name of the template.</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Previous(this MvcSiteMapHtmlHelper helper, string templateName, object sourceMetadata)
 {
     return(Previous(helper, "Previous", templateName, string.Empty, sourceMetadata));
 }
Example #11
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="text">The text to display for the node.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper, string text, string templateName)
 {
     return(Next(helper, text, templateName, string.Empty));
 }
        public void BuildModel_Case3_CurrentNodeNotVisible_StartingNodeInChildLevel_NotShowStartingNode_MaxDepth3_visibilityNotAffectsDescendants_ShouldReturn4Nodes()
        {
            // Start at /Root/AB
            // Expect a list of all visible children and grandchildren of invisible children and great grandchildren (don't exist but no error is expected) of /Root/AB (4 nodes)

            // Html.MvcSiteMap().Menu(null, Html.MvcSiteMap().SiteMap.CurrentNode, true, false, 3, false, false, new SourceMetadataDictionary())

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase3();
            ((FakeSiteMap)siteMap).SetCurrentNode(siteMap.FindSiteMapNode("/Root/AB"));
            var startingNode = siteMap.CurrentNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = MenuHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: true,
                showStartingNode: false,
                maxDepth: 3,
                drillDownToCurrent: false,
                visibilityAffectsDescendants: false);

            // Assert
            Assert.AreEqual("ABAA", result.Nodes[0].Title);
            Assert.AreEqual("ABAB", result.Nodes[1].Title);
            Assert.AreEqual("ABB", result.Nodes[2].Title);
            Assert.AreEqual("ABC", result.Nodes[3].Title);

            // Check counts
            Assert.AreEqual(4, result.Nodes.Count);
            Assert.AreEqual(0, result.Nodes[0].Children.Count);
            Assert.AreEqual(0, result.Nodes[1].Children.Count);
            Assert.AreEqual(0, result.Nodes[2].Children.Count);
            Assert.AreEqual(0, result.Nodes[3].Children.Count);
        }
Example #13
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="startingNode">The starting node (the "current node" for the desired view).</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper, ISiteMapNode startingNode)
 {
     return(Next(helper, null, startingNode, new SourceMetadataDictionary()));
 }
Example #14
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="sourceMetadata">User-defined meta data.</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata)
 {
     return(Next(helper, null, sourceMetadata));
 }
Example #15
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper)
 {
     return(Next(helper, "Next", null, string.Empty));
 }
Example #16
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="templateName">Name of the template.</param>
 /// <param name="startingNode">The starting node (the "current node" for the desired view).</param>
 /// <param name="sourceMetadata">User-defined meta data.</param>
 /// <returns>Next node for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper, string templateName, ISiteMapNode startingNode, SourceMetadataDictionary sourceMetadata)
 {
     return(Next(helper, "Next", templateName, startingNode, sourceMetadata));
 }
Example #17
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="text">The text to display for the node.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <param name="startingNodeKey">The key of the starting node (the "current node" for the desired view).</param>
 /// <param name="sourceMetadata">User-defined meta data.</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper, string text, string templateName, string startingNodeKey, object sourceMetadata)
 {
     return(Next(helper, text, templateName, startingNodeKey, new SourceMetadataDictionary(sourceMetadata)));
 }
Example #18
0
        /// <summary>
        /// Build a menu, based on the MvcSiteMap
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="startFromCurrentNode">Start from current node if set to <c>true</c>.</param>
        /// <param name="startingNodeInChildLevel">Show starting node in child level if set to <c>true</c>.</param>
        /// <param name="showStartingNode">Show starting node if set to <c>true</c>.</param>
        /// <returns>Html markup</returns>
        public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, bool startFromCurrentNode, bool startingNodeInChildLevel, bool showStartingNode)
        {
            SiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode(helper.Provider) : helper.Provider.RootNode;

            return(MainMenu(helper, startingNode, startingNodeInChildLevel, showStartingNode, Int32.MaxValue, false));
        }
Example #19
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="templateName">Name of the template.</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper, string templateName, object sourceMetadata)
 {
     return(Next(helper, "Next", templateName, string.Empty, sourceMetadata));
 }
        public void BuildModel_Case2_StartingNodeNotInChildLevel_VisibilyDoesntAffectDescendants_ShouldReturnHierarchialNodes()
        {
            // @Html.MvcSiteMap().Menu(true, false, true, false)

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase2();
            var startingNode = siteMap.RootNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = MenuHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: false,
                showStartingNode: true,
                maxDepth: Int32.MaxValue,
                drillDownToCurrent: false,
                visibilityAffectsDescendants: false);

            // Assert
            Assert.AreEqual("Home", result.Nodes[0].Title);
            Assert.AreEqual("About", result.Nodes[0].Children[0].Title);
            Assert.AreEqual("About Me", result.Nodes[0].Children[0].Children[0].Title);
            Assert.AreEqual("About You", result.Nodes[0].Children[0].Children[1].Title);

            // "Contact" is inaccessible - should be skipped. So should its child node "ContactSomebody".
            Assert.AreEqual("Categories", result.Nodes[0].Children[1].Title);

            Assert.AreEqual("Cameras", result.Nodes[0].Children[1].Children[0].Title);
            Assert.AreEqual("Nikon Coolpix 200", result.Nodes[0].Children[1].Children[0].Children[0].Title);
            Assert.AreEqual("Canon Ixus 300", result.Nodes[0].Children[1].Children[0].Children[1].Title);

            // "Memory Cards" is not visible. However its children should be in its place.
            Assert.AreEqual("Kingston 256 GB SD", result.Nodes[0].Children[1].Children[1].Title);
            Assert.AreEqual("Sony 256 GB SD", result.Nodes[0].Children[1].Children[2].Title);
            Assert.AreEqual("Sony SD Card Reader", result.Nodes[0].Children[1].Children[2].Children[0].Title);

            // Check counts
            Assert.AreEqual(1, result.Nodes.Count);
            Assert.AreEqual(2, result.Nodes[0].Children.Count); // Home
            Assert.AreEqual(2, result.Nodes[0].Children[0].Children.Count); // About
            Assert.AreEqual(0, result.Nodes[0].Children[0].Children[0].Children.Count); // About Me
            Assert.AreEqual(0, result.Nodes[0].Children[0].Children[1].Children.Count); // About You
            Assert.AreEqual(3, result.Nodes[0].Children[1].Children.Count); // Categories
            Assert.AreEqual(2, result.Nodes[0].Children[1].Children[0].Children.Count); // Cameras
            Assert.AreEqual(0, result.Nodes[0].Children[1].Children[0].Children[0].Children.Count); // Nikon Coolpix 200
            Assert.AreEqual(0, result.Nodes[0].Children[1].Children[0].Children[1].Children.Count); // Canon Ixus 300
            Assert.AreEqual(0, result.Nodes[0].Children[1].Children[1].Children.Count); // Kingston 256 GB SD
            Assert.AreEqual(1, result.Nodes[0].Children[1].Children[2].Children.Count); // Sony 256 GB SD
            Assert.AreEqual(0, result.Nodes[0].Children[1].Children[2].Children[0].Children.Count); // Sony SD Card Reader
        }
Example #21
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <param name="startingNodeLevel">The starting node level.</param>
 /// <param name="startingNodeInChildLevel">Show starting node 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>
 /// <returns>Html markup</returns>
 public static MvcHtmlString Tabs(this MvcSiteMapHtmlHelper helper, string templateName, int startingNodeLevel, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return(Tabs(helper, templateName, startingNodeLevel, startingNodeInChildLevel, showStartingNode, maxDepth, false, false));
 }
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="startingNodeLevel">The starting node level.</param>
 /// <param name="startingNodeInChildLevel">Show starting node 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>
 /// <returns>Html markup</returns>
 public static MvcHtmlString Pills(this MvcSiteMapHtmlHelper helper, int startingNodeLevel, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return(Pills(helper, startingNodeLevel, startingNodeInChildLevel, showStartingNode, maxDepth, false, false));
 }
Example #23
0
        public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper)
        {
            MenuHelperModel model = BuildModel(MVCSiteMap.StartingNode);

            //MenuNode node = new MenuNode();
            //node.Title = "tesst1";
            //node.Url = "dsdsd";
            //node.IsClickable = false;
            //SiteMapNodeModel nodemodel = new SiteMapNodeModel(node);


            //MenuNode node2 = new MenuNode();
            //node.Title = "tesst22221";
            //node.Url = "dsdsd2222";
            //node.IsClickable = false;
            //SiteMapNodeModel nodemodel2 = new SiteMapNodeModel(node);


            //MenuNode node3 = new MenuNode();
            //node.Title = "tesst333";
            //node.Url = "dsdsd33";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel3 = new SiteMapNodeModel(node);


            //MenuNode node4 = new MenuNode();
            //node.Title = "tesst331";
            //node.Url = "dsdsd333";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel4 = new SiteMapNodeModel(node);


            //MenuNode node5 = new MenuNode();
            //node.Title = "tesst335553";
            //node.Url = "dsdsd35553";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel5 = new SiteMapNodeModel(node);


            //MenuNode node6 = new MenuNode();
            //node.Title = "tesst366631";
            //node.Url = "dsdsd336663";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel6 = new SiteMapNodeModel(node);

            //nodemodel3.Children.Add(nodemodel6);
            //nodemodel3.Children.Add(nodemodel5);

            //nodemodel2.Children.Add(nodemodel3);
            //nodemodel2.Children.Add(nodemodel4);


            //MenuHelperModel menu = new MenuHelperModel();
            //menu.Nodes.Add(nodemodel);
            //menu.Nodes.Add(nodemodel2);


            return(helper
                   .CreateHtmlHelperForModel(model)
                   .DisplayFor(m => model, null));
        }
Example #24
0
 /// <summary>
 /// Gets next node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="text">The text to display for the node.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Next(this MvcSiteMapHtmlHelper helper, string text, string templateName, SourceMetadataDictionary sourceMetadata)
 {
     return(Next(helper, text, templateName, string.Empty, sourceMetadata));
 }
Example #25
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="startingNodeLevel">The starting node level.</param>
 /// <param name="maxDepth">The max depth.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString Nav(this MvcSiteMapHtmlHelper helper, int startingNodeLevel, int maxDepth)
 {
     return(Nav(helper, startingNodeLevel, maxDepth, false, false));
 }
Example #26
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="startingNodeInChildLevel">Show starting node 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="drillDownToContent">if set to <c>true</c> [drill down to content].</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToContent)
 {
     return(MainMenu(helper, null, startingNode, startingNodeInChildLevel, showStartingNode, maxDepth, drillDownToContent));
 }
Example #27
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="startingNodeInChildLevel">Show starting node 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>
 /// <returns>Html markup</returns>
 public static MvcHtmlString Nav(this MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return(Nav(helper, startingNode, startingNodeInChildLevel, showStartingNode, maxDepth, false));
 }
Example #28
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <param name="startingNodeLevel">The starting node level.</param>
 /// <param name="maxDepth">The max depth.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, string templateName, int startingNodeLevel, int maxDepth)
 {
     return(MainMenu(helper, templateName, startingNodeLevel, maxDepth, false, false));
 }
Example #29
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <param name="showStartingNode">Show starting node if set to <c>true</c>.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString Nav(this MvcSiteMapHtmlHelper helper, string templateName, bool showStartingNode)
 {
     return(Nav(helper, templateName, helper.Provider.RootNode, true, showStartingNode, Int32.MaxValue, false));
 }
Example #30
0
        /// <summary>
        /// Builds the model.
        /// </summary>
        /// <param name="helper">The helper.</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 MainMenuSitemapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent)
        {
            // Build model
            var model = new MainMenuSitemapHelperModel();
            var node  = startingNode;

            // Check if a starting node has been given
            if (node == null)
            {
                return(model);
            }

            var  mvcNode          = node as MvcSiteMapNode;
            bool continueBuilding = ReachedMaximalNodelevel(maxDepth, node, drillDownToCurrent);

            // Check if maximal node level has not been reached
            if (!continueBuilding)
            {
                return(model);
            }

            // Check visibility
            bool nodeVisible = true;

            if (mvcNode != null)
            {
                nodeVisible = mvcNode.VisibilityProvider.IsVisible(
                    node, HttpContext.Current, TabsSourceMetadata);
            }

            // Check ACL
            if (node.IsAccessibleToUser(HttpContext.Current))
            {
                // Add node?
                var nodeToAdd = MapToSiteMapNodeModel(node, mvcNode, TabsSourceMetadata);

                if (nodeVisible)
                {
                    if (showStartingNode || !startingNodeInChildLevel)
                    {
                        model.Nodes.Add(nodeToAdd);
                    }
                }

                // Add child nodes
                if (node.HasChildNodes)
                {
                    foreach (SiteMapNode childNode in node.ChildNodes)
                    {
                        var childNodes = BuildModel(helper, childNode, false, true, maxDepth - 1, drillDownToCurrent).Nodes;
                        foreach (var childNodeToAdd in childNodes)
                        {
                            if (!startingNodeInChildLevel)
                            {
                                nodeToAdd.Children.Add(childNodeToAdd);
                            }
                            else
                            {
                                model.Nodes.Add(childNodeToAdd);
                            }
                        }
                    }
                }
            }

            return(model);
        }
Example #31
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="templateName">Name of the template.</param>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="startingNodeInChildLevel">Show starting node in child level if set to <c>true</c>.</param>
 /// <param name="showStartingNode">Show starting node if set to <c>true</c>.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString Nav(this MvcSiteMapHtmlHelper helper, string templateName, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode)
 {
     return(Nav(helper, templateName, startingNode, startingNodeInChildLevel, showStartingNode, Int32.MaxValue, false));
 }
Example #32
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="showStartingNode">Show starting node if set to <c>true</c>.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, bool showStartingNode)
 {
     return(MainMenu(helper, helper.Provider.RootNode, true, showStartingNode, Int32.MaxValue, false));
 }
Example #33
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString Nav(this MvcSiteMapHtmlHelper helper)
 {
     return(Nav(helper, helper.Provider.RootNode, true, true, Int32.MaxValue, false));
 }
Example #34
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="startingNodeInChildLevel">Show starting node in child level if set to <c>true</c>.</param>
 /// <param name="showStartingNode">Show starting node if set to <c>true</c>.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode)
 {
     return(MainMenu(helper, startingNode, startingNodeInChildLevel, showStartingNode, Int32.MaxValue, false));
 }
Example #35
0
 /// <summary>
 /// Gets Breadcrumb path for the current request
 /// </summary>
 /// <param name="helper">MvcBreadcrumbHtmlHelper instance</param>
 /// <returns>Breadcrumb path for the current request</returns>
 public static MvcHtmlString Breadcrumb(this MvcSiteMapHtmlHelper helper)
 {
     return(Breadcrumb(helper, null));
 }
        public void BuildModel_Case2_StartingNodeNotInChildLevel_MaxDepth2_ShouldReturnHierarchialNodesTo2Levels()
        {
            // @Html.MvcSiteMap().Menu(0, false, true, 3)

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase2();
            var startingNode = siteMap.RootNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = MenuHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: false,
                showStartingNode: true,
                maxDepth: 2,
                drillDownToCurrent: false,
                visibilityAffectsDescendants: true);

            // Assert
            Assert.AreEqual("Home", result.Nodes[0].Title);
            Assert.AreEqual("About", result.Nodes[0].Children[0].Title);
            Assert.AreEqual("About Me", result.Nodes[0].Children[0].Children[0].Title);
            Assert.AreEqual("About You", result.Nodes[0].Children[0].Children[1].Title);

            // "Contact" is inaccessible - should be skipped. So should its child node "ContactSomebody".
            Assert.AreEqual("Categories", result.Nodes[0].Children[1].Title);

            Assert.AreEqual("Cameras", result.Nodes[0].Children[1].Children[0].Title);

            // "Memory Cards" is not visible.

            // Check counts
            Assert.AreEqual(1, result.Nodes.Count);
            Assert.AreEqual(2, result.Nodes[0].Children.Count); // Home
            Assert.AreEqual(2, result.Nodes[0].Children[0].Children.Count); // About
            Assert.AreEqual(0, result.Nodes[0].Children[0].Children[0].Children.Count); // About Me
            Assert.AreEqual(0, result.Nodes[0].Children[0].Children[1].Children.Count); // About You
            Assert.AreEqual(1, result.Nodes[0].Children[1].Children.Count); // Categories
            Assert.AreEqual(0, result.Nodes[0].Children[1].Children[0].Children.Count); // Cameras
        }
 /// <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>
 /// <returns>The model.</returns>
 private static MenuHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return BuildModel(helper, sourceMetadata, startingNode, startingNodeInChildLevel, showStartingNode, maxDepth, false, helper.SiteMap.VisibilityAffectsDescendants);
 }
        public void BuildModel_Case3_CurrentNodeNotVisible_StartingNodeInChildLevel_NotShowStartingNode_MaxDepth2_visibilityNotAffectsDescendants_ShouldReturn3Nodes()
        {
            // Start at /Root/AA which is not visible
            // Expect a list with all visible direct children of /Root/AA (3 nodes)
            // First in the list will have 1 child node

            // Html.MvcSiteMap().Menu(null, Html.MvcSiteMap().SiteMap.CurrentNode, true, false, 2, false, false, new SourceMetadataDictionary())

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase3();
            ((FakeSiteMap)siteMap).SetCurrentNode(siteMap.FindSiteMapNode("/Root/AA"));
            var startingNode = siteMap.CurrentNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = MenuHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: true,
                showStartingNode: false,
                maxDepth: 2,
                drillDownToCurrent: false,
                visibilityAffectsDescendants: false);

            // Assert
            Assert.AreEqual("AAA", result.Nodes[0].Title);
            Assert.AreEqual("AAB", result.Nodes[1].Title);
            Assert.AreEqual("AAC", result.Nodes[2].Title);

            // Check counts
            Assert.AreEqual(3, result.Nodes.Count);
            Assert.AreEqual(1, result.Nodes[0].Children.Count);
            Assert.AreEqual(0, result.Nodes[1].Children.Count);
            Assert.AreEqual(0, result.Nodes[2].Children.Count);
        }
        /// <summary>
        /// Builds the model.
        /// </summary>
        /// <param name="helper">The helper.</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, SiteMapNode startingNode, bool startingNodeInChildLevel)
        {
            // Build model
            var model = new SiteMapHelperModel();
            var node = startingNode;

                var mvcNode = node as MvcSiteMapNode;

                // Check visibility
                bool nodeVisible = true;
                if (mvcNode != null)
                {
                    nodeVisible = mvcNode.VisibilityProvider.IsVisible(
                        node, HttpContext.Current, SourceMetadata);
                }

                // Check ACL
                if (nodeVisible && node.IsAccessibleToUser(HttpContext.Current))
                {
                    // Add node
                    var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, SourceMetadata);
                    model.Nodes.Add(nodeToAdd);

                    // Add child nodes
                    if (node.HasChildNodes) {
                        foreach (SiteMapNode childNode in node.ChildNodes)
                        {
                            foreach (var childNodeToAdd in BuildModel(helper, childNode, false).Nodes)
                            {
                                if (!startingNodeInChildLevel)
                                {
                                    nodeToAdd.Children.Add(childNodeToAdd);
                                }
                                else
                                {
                                    model.Nodes.Add(childNodeToAdd);
                                }
                            }
                        }
                    }
                }

            return model;
        }
        public void BuildModel_Case3_CurrentNodeNotVisible_StartingNodeInChildLevel_NotShowStartingNode_visibilityAffectsDescendants_ShouldReturn0Nodes()
        {
            // Html.MvcSiteMap().Menu(null, Html.MvcSiteMap().SiteMap.CurrentNode, true, false, int32.MaxValue, false, true, new SourceMetadataDictionary())

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase3();
            ((FakeSiteMap)siteMap).SetCurrentNode(siteMap.FindSiteMapNode("/Root/AB"));
            var startingNode = siteMap.CurrentNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = MenuHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: true,
                showStartingNode: false,
                maxDepth: Int32.MaxValue,
                drillDownToCurrent: false,
                visibilityAffectsDescendants: true);

            // Check counts
            Assert.AreEqual(0, result.Nodes.Count);
        }
 /// <summary>
 /// Builds the model.
 /// </summary>
 /// <param name="helper">The helper.</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>
 /// <returns>The model.</returns>
 private static SitemapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return BuildModel(helper, startingNode, startingNodeInChildLevel, showStartingNode, maxDepth, false);
 }
        /// <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;
        }
Example #43
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>
 /// <returns>The model.</returns>
 private static MenuHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth)
 {
     return BuildModel(helper, sourceMetadata, startingNode, startingNodeInChildLevel, showStartingNode, maxDepth, false);
 }
        /// <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;
        }
 /// <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;
     // Check visibility and ACL
     if (node != null && node.IsVisible(sourceMetadata) && node.IsAccessibleToUser())
     {
         // Add node
         model.Nodes.AddRange((new SiteMapNodeModel(node, sourceMetadata)).Ancestors);
     }
     return model;
 }
        /// <summary>
        /// Builds the model.
        /// </summary>
        /// <param name="helper">The helper.</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 SitemapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent)
        {
            // Build model
            var model = new SitemapHelperModel();
            var node = startingNode;

            // Check if a starting node has been given
            if (node == null)
            {
                return model;
            }

            var mvcNode = node as MvcSiteMapNode;
            bool continueBuilding = ReachedMaximalNodelevel(maxDepth, node, drillDownToCurrent);

            // Check if maximal node level has not been reached
            if (!continueBuilding)
            {
                return model;
            }

            // Check visibility
            bool nodeVisible = true;
            if (mvcNode != null)
            {
                nodeVisible = mvcNode.VisibilityProvider.IsVisible(
                    node, HttpContext.Current, PillsSourceMetadata);
            }

            // Check ACL
            if (node.IsAccessibleToUser(HttpContext.Current))
            {
                // Add node?
                var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, PillsSourceMetadata);
                if (nodeVisible)
                {
                    if (showStartingNode || !startingNodeInChildLevel)
                    {
                        model.Nodes.Add(nodeToAdd);
                    }
                }

                // Add child nodes
                if (node.HasChildNodes)
                {
                    foreach (SiteMapNode childNode in node.ChildNodes)
                    {
                        var childNodes = BuildModel(helper, childNode, false, true, maxDepth - 1, drillDownToCurrent).Nodes;
                        foreach (var childNodeToAdd in childNodes)
                        {
                            if (!startingNodeInChildLevel)
                            {
                                nodeToAdd.Children.Add(childNodeToAdd);
                            }
                            else
                            {
                                model.Nodes.Add(childNodeToAdd);
                            }
                        }
                    }
                }
            }

            return model;
        }
        public void BuildModel_Case2_StartingNodeNotInChildLevel_ShouldReturnHierarchicalNodes()
        {
            // @Html.MvcSiteMap().Menu(false)

            // Arrange
            var siteMap = HtmlHelperTestCases.CreateFakeSiteMapCase2();
            var startingNode = siteMap.RootNode;
            HtmlHelper helper = new HtmlHelper(this.viewContext.Object, this.iView.Object);
            MvcSiteMapHtmlHelper helperExtension = new MvcSiteMapHtmlHelper(helper, siteMap, false);

            // Act
            var result = SiteMapHelper.BuildModel(
                helper: helperExtension,
                sourceMetadata: new SourceMetadataDictionary(),
                startingNode: startingNode,
                startingNodeInChildLevel: false,
                visibilityAffectsDescendants: true);

            // Assert
            Assert.AreEqual("Home", result.Nodes[0].Title);
            Assert.AreEqual("About", result.Nodes[0].Children[0].Title);
            Assert.AreEqual("About Me", result.Nodes[0].Children[0].Children[0].Title);
            Assert.AreEqual("About You", result.Nodes[0].Children[0].Children[1].Title);

            // "Contact" is inaccessible - should be skipped. So should its child node "ContactSomebody".
            Assert.AreEqual("Categories", result.Nodes[0].Children[1].Title);

            Assert.AreEqual("Cameras", result.Nodes[0].Children[1].Children[0].Title);
            Assert.AreEqual("Nikon Coolpix 200", result.Nodes[0].Children[1].Children[0].Children[0].Title);
            Assert.AreEqual("Canon Ixus 300", result.Nodes[0].Children[1].Children[0].Children[1].Title);

            // "Memory Cards" is not visible. None of its children should be visible.
            Assert.AreEqual(1, result.Nodes[0].Children[1].Children.Count);
        }
Example #48
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>
        /// <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;
        }
Example #49
0
 /// <summary>
 /// Build a menu, based on the MvcSiteMap
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="startingNodeLevel">The starting node level.</param>
 /// <param name="maxDepth">The max depth.</param>
 /// <param name="allowForwardSearch">if set to <c>true</c> allow forward search. Forward search will search all parent nodes and child nodes, where in other circumstances only parent nodes are searched.</param>
 /// <returns>Html markup</returns>
 public static MvcHtmlString MainMenu(this MvcSiteMapHtmlHelper helper, int startingNodeLevel, int maxDepth, bool allowForwardSearch)
 {
     return(MainMenu(helper, startingNodeLevel, maxDepth, allowForwardSearch, false));
 }
        /// <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;
        }
Example #51
0
 /// <summary>
 /// Gets previous node in the document outline for the current request
 /// </summary>
 /// <param name="helper">MvcSiteMapHtmlHelper instance</param>
 /// <param name="text">The text to display for the node.</param>
 /// <returns>SiteMap path for the current request</returns>
 public static MvcHtmlString Previous(this MvcSiteMapHtmlHelper helper, string text)
 {
     return(Previous(helper, text, string.Empty));
 }