Exemple #1
0
        public void GetContextNavigationLinks_Root_Success()
        {
            ILocalization testLocalization = TestFixture.ParentLocalization;

            NavigationLinks navLinks = _testNavigationProvider.GetContextNavigationLinks(testLocalization.Path, testLocalization);

            Assert.IsNotNull(navLinks, "navLinks");
            OutputJson(navLinks);

            Assert.AreEqual(1, navLinks.Items.Count, "navLinks.Items.Count");
            AssertValidLink(navLinks.Items[0], testLocalization.Path + "/index", "Home", null, "navLinks.Items[0]");
        }
        public void GetContextNavigationLinks_TaxonomyTestPage2_Success()
        {
            Localization testLocalization = TestFixture.ParentLocalization;
            string       testUrlPath      = testLocalization.GetAbsoluteUrlPath(TestFixture.TaxonomyTestPage2RelativeUrlPath);

            NavigationLinks navLinks = _testNavigationProvider.GetContextNavigationLinks(testUrlPath, testLocalization);

            Assert.IsNotNull(navLinks, "navLinks");
            OutputJson(navLinks);

            AssertExpectedLinks(navLinks.Items);
        }
Exemple #3
0
        /// <summary>
        /// Gets Navigation Links for the context navigation panel for the given request URL path.
        /// </summary>
        /// <param name="requestUrlPath">The request URL path.</param>
        /// <param name="localization">The Localization.</param>
        /// <returns>The Navigation Links.</returns>
        public NavigationLinks GetContextNavigationLinks(string requestUrlPath, Localization localization)
        {
            using (new Tracer(requestUrlPath, localization))
            {
                SitemapItem navModel = GetNavigationModel(localization);
                if (!(navModel is TaxonomyNode))
                {
                    // No Navigation Taxonomy found in this Localization; fallback to the StaticNavigationProvider.
                    return(_fallbackNavigationProvider.GetContextNavigationLinks(requestUrlPath, localization));
                }

                SitemapItem contextNode = navModel.FindSitemapItem(requestUrlPath.NormalizePageUrlPath());
                if (contextNode != null && !(contextNode is TaxonomyNode))
                {
                    contextNode = contextNode.Parent;
                }

                List <Link> links = new List <Link>();
                if (contextNode != null)
                {
                    links.AddRange(contextNode.Items.Where(i => i.Visible).Select(i => i.CreateLink(localization)));
                }

                return(new NavigationLinks
                {
                    Items = links
                });
            }
        }
        public virtual ActionResult Navigation(EntityModel entity, string navType, int containerSize = 0)
        {
            using (new Tracer(entity, navType, containerSize))
            {
                SetupViewData(entity, containerSize);

                INavigationProvider navigationProvider = SiteConfiguration.NavigationProvider;
                string          requestUrlPath         = Request.Url.LocalPath;
                Localization    localization           = WebRequestContext.Localization;
                NavigationLinks model;
                switch (navType)
                {
                case "Top":
                    model = navigationProvider.GetTopNavigationLinks(requestUrlPath, localization);
                    break;

                case "Left":
                    model = navigationProvider.GetContextNavigationLinks(requestUrlPath, localization);
                    break;

                case "Breadcrumb":
                    model = navigationProvider.GetBreadcrumbNavigationLinks(requestUrlPath, localization);
                    break;

                default:
                    throw new DxaException("Unexpected navType: " + navType);
                }

                EntityModel sourceModel = (EnrichModel(entity) as EntityModel) ?? entity;
                model.XpmMetadata         = sourceModel.XpmMetadata;
                model.XpmPropertyMetadata = sourceModel.XpmPropertyMetadata;

                return(View(sourceModel.MvcData.ViewName, model));
            }
        }