public Task <List <PageListItem> > LoadALlPages() { var pages = contentLoader.GetDescendents(ContentReference.StartPage); var result = new List <PageListItem>(); foreach (var item in pages) { var page = contentLoader.Get <PageData>(item); if (page.ContentLink != ContentReference.StartPage || page.ParentLink != ContentReference.StartPage) { var parents = contentLoader.GetAncestors(page.ContentLink); var url = page.URLSegment; foreach (var parent in parents) { if (parent is PageData pageData && pageData.ContentLink != ContentReference.StartPage) { url = pageData.URLSegment + "/" + url; } } if (!result.Any(x => x.Key == page.ContentLink.ToString())) { result.Add(new PageListItem() { Key = page.ContentLink.ToString(), Name = page.Name, Type = page.PageTypeName, Url = url }); } } } return(Task.FromResult(result)); }
public ActionResult Edit(Guid?guid) { var vm = new EditWebhookViewModel(); vm.Webhook = (guid == null) ? new WebhookPostModel() : new WebhookPostModel(_repo.GetWebhook(guid.Value)); if (vm.Webhook.ParentId > 0) { var parentRef = new ContentReference(vm.Webhook.ParentId); if (!ContentReference.IsNullOrEmpty(parentRef)) { var parentContent = _contentLoader.Get <IContent>(parentRef); if (parentContent != null) { vm.CurrentContentName = parentContent.Name; vm.CurrentContentAncestors = _contentLoader.GetAncestors(parentRef).Select(x => x.ContentLink.ID).ToList(); } } } vm.ContentTypes = _typeRepo.List().Select(x => new SelectListItem { Text = x.DisplayName ?? x.Name, Value = x.ID.ToString() }).ToList(); vm.EventTypes = new List <SelectListItem>(); foreach (var eventType in _repo.GetEventTypes()) { vm.EventTypes.Add(new SelectListItem { Value = eventType.Key, Text = _localizationService.GetString("/Webhooks/EventTypes/" + eventType.Key, eventType.Key) }); } return(View(vm)); }
protected IPageViewModel <TPage> CreatePageViewModel <TPage>(TPage currentPage) where TPage : SitePageData { var viewmodel = PageViewModel.Create(currentPage); viewmodel.Loader = loader; viewmodel.SiteDefinition = this.siteDefinitionResolver.GetByContent(ContentReference.StartPage, false); viewmodel.StartPage = loader.Get <StartPage>(ContentReference.StartPage); viewmodel.MenuPages = FilterForVisitor .Filter(loader.GetChildren <SitePageData>(ContentReference.StartPage)) .Cast <SitePageData>().Where(page => page.VisibleInMenu); viewmodel.AncestorPages = FilterForVisitor .Filter(loader.GetAncestors(currentPage.ContentLink)) .Cast <SitePageData>().Where(page => page.VisibleInMenu); if (viewmodel.AncestorPages.Count() <= 1) { viewmodel.SubMenuRootPage = currentPage; } else { viewmodel.SubMenuRootPage = viewmodel.AncestorPages.FirstOrDefault(); } viewmodel.SubMenuRootPage = loader.Get <SitePageData>(viewmodel.SubMenuRootPage.ContentLink, viewmodel.CurrentPage.Language); viewmodel.SubMenuPages = FilterForVisitor .Filter(loader.GetChildren <SitePageData>(viewmodel.SubMenuRootPage.ContentLink)) .Cast <SitePageData>().Where(page => page.VisibleInMenu); viewmodel.Section = currentPage.ContentLink.GetSection(); return(viewmodel); }
public RestResult PermanentDelete(ContentReference id) { Validator.ThrowIfNull("id", id); var content = _contentLoader.Get <IContent>(id); if (!content.QueryDistinctAccess(AccessLevel.Delete)) { throw new HttpException(403, "You do not have access rights to empty this waste basket."); } var secondReverseParent = _contentLoader.GetAncestors(content.ContentLink).Reverse().ElementAt(1); if (!_contentProviderManager.IsWastebasket(secondReverseParent.ContentLink)) { throw new HttpException(400, "Not a valid wastebasket."); } var actionResponse = new ActionResponse <ContentReference> { ExtraInformation = secondReverseParent.ContentLink }; _contentRepository.Delete(id, true, AccessLevel.NoAccess); return(Rest(actionResponse)); }
public override ActionResult Index(BreadcrumbBlock currentBlock) { var destination = currentBlock.DestinationPage as ContentReference; if (ContentReference.IsNullOrEmpty(currentBlock.DestinationPage)) { destination = _pageRouteHelper.ContentLink; } var ancestors = _contentLoader.GetAncestors(destination).Where(x => x is PageData).Select(x => x as PageData).Reverse(); var model = new BreadcrumbBlockViewModel(currentBlock); if (ancestors != null && ancestors.Count() > 0) { var breadcrumb = new List <BreadcrumbItem>(); foreach (var page in ancestors) { breadcrumb.Add(new BreadcrumbItem(page, Url)); } breadcrumb.Add(new BreadcrumbItem(_contentLoader.Get <IContent>(destination) as PageData, Url)); model.Breadcrumb.AddRange(breadcrumb.Where(x => !string.IsNullOrEmpty(x.Url))); } return(PartialView("~/Features/Blocks/BreadcrumbBlock/BreadcrumbBlock.cshtml", model)); }
private static IEnumerable <PageData> NavigationPath( ContentReference contentLink, IContentLoader contentLoader, ContentReference fromLink = null) { fromLink = fromLink ?? ContentReference.RootPage; //Find all pages between the current and the //"from" page, in top-down order. var path = contentLoader.GetAncestors(contentLink) .Reverse() .SkipWhile(x => ContentReference.IsNullOrEmpty(x.ParentLink) || !x.ParentLink.CompareToIgnoreWorkID(fromLink)) .OfType <PageData>() .ToList(); //In theory the current content may not be a page. //We check that and, if it is, add it to the end of //the content tree path. var currentPage = contentLoader .Get <IContent>(contentLink) as PageData; if (currentPage != null) { path.Add(currentPage); } return(path); }
public virtual List <LinkItem> GetPageBreadcrumbs(PageData currentPage) { List <LinkItem> linkItems = new List <LinkItem>(); var parents = ContentLoader.GetAncestors(currentPage.ContentLink) .Reverse() .Cast <PageData>() .Where(p => p.ContentLink != PageReference.RootPage); if (parents != null) { foreach (var parent in parents) { var linkItem = new LinkItem { Href = parent.ContentLink.GetFriendlyUrl(), Title = parent.Name, LinkText = parent.Name, Active = true }; linkItems.Add(linkItem); } } linkItems.Add(new LinkItem { Href = currentPage.ContentLink.GetFriendlyUrl(), Title = currentPage.Name, LinkText = currentPage.Name, Active = false }); return(linkItems); }
public static void RenderSubNavigation(this HtmlHelper html, ContentReference contentLink = null, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); contentLoader = contentLoader ?? ServiceLocator.Current.GetInstance <IContentLoader>(); //Find all pages between the current and the //start page, in top-down order. var path = contentLoader.GetAncestors(contentLink) .Reverse().SkipWhile(x => ContentReference.IsNullOrEmpty(x.ParentLink) || !x.ParentLink.CompareToIgnoreWorkID(ContentReference.StartPage)).OfType <PageData>().Select(x => x.PageLink) .ToList(); //In theory the current content may not be a page. //We check that and, if it is, add it to the end of //the content tree path. var currentPage = contentLoader.Get <IContent>(contentLink) as PageData; if (currentPage != null) { path.Add(currentPage.PageLink); } var root = path.FirstOrDefault(); if (root == null) { //We're not on a page below the start page, //meaning that there's nothing to render. return; } RenderSubNavigationLevel(html, root, path, contentLoader); }
protected List <KeyValuePair <string, string> > GetBreadCrumb(string catalogCode) { var model = new List <KeyValuePair <string, string> >(); model.Add(new KeyValuePair <string, string>("Home", "/")); var entryLink = _referenceConverter.GetContentLink(catalogCode); if (entryLink != null) { var entry = _contentLoader.Get <CatalogContentBase>(entryLink); var product = entry; if (entry is VariationContent) { var parentLink = (entry as VariationContent).GetParentProducts().FirstOrDefault(); if (!ContentReference.IsNullOrEmpty(parentLink)) { product = _contentLoader.Get <CatalogContentBase>(parentLink); } } var ancestors = _contentLoader.GetAncestors(product.ContentLink); foreach (var anc in ancestors.Reverse()) { if (anc is NodeContent) { model.Add(new KeyValuePair <string, string>(anc.Name, anc.PublicUrl(_urlResolver))); } } } return(model); }
private IEnumerable <ISettingsPage> GetSettingsPages(ContentReference contentReference) { foreach (var ancestor in Enumerable.Repeat(contentReference, 1).Concat(_contentLoader.GetAncestors(contentReference)?.Select(c => c.ContentLink))) { if (_contentLoader.TryGet <ISettingsPage>(ancestor, out var settingPage)) { yield return(settingPage); } } }
/// <summary> /// Get ancestor categories. /// </summary> /// <param name="entryContent">The entry content.</param> /// <param name="contentLoader">The content loader.</param> /// <returns>Collection of category content.</returns> public static IEnumerable <NodeContent> GetAncestorCategories( this EntryContentBase entryContent, IContentLoader contentLoader) { return(entryContent.GetCategories() .SelectMany(parentLink => contentLoader.GetAncestors(parentLink) .OfType <NodeContent>() .Concat(new[] { contentLoader.Get <NodeContent>(parentLink) })) .Distinct(new NodeContentComparer())); }
private List <KeyValuePair <string, string> > GetBreadCrumb(Models.BlogItemPage currentPage) { var breadCrumb = new List <KeyValuePair <string, string> >(); var ancestors = _contentLoader.GetAncestors(currentPage.ContentLink) .Select(x => x as BlogListPage.Models.BlogListPage) .Where(x => x != null); breadCrumb = ancestors.Reverse().Select(x => new KeyValuePair <string, string>(x.MetaTitle, x.PublicUrl(_urlResolver))).ToList(); return(breadCrumb); }
private ContentReference GetCategory(CatalogContentBase content) { if (content is NodeContent) { return(content.ContentLink); } var category = _contentLoader.GetAncestors(content.ContentLink).Last(x => x is NodeContent); return(category.ContentLink); }
//public ActionResult Logout() //{ // FormsAuthentication.SignOut(); // return RedirectToAction("Index"); //} protected IPageViewModel <TPage> CreatePageViewModel <TPage>( TPage currentPage) where TPage : SitePageData { var ancestors = loader.GetAncestors(currentPage.ContentLink); var viewmodel = PageViewModel.Create(currentPage); viewmodel.StartPage = loader.Get <StartPage>(ContentReference.StartPage); viewmodel.MenuPages = FilterForVisitor.Filter( loader.GetChildren <SitePageData>(ContentReference.StartPage)) .Cast <SitePageData>().Where(page => page.VisibleInMenu); viewmodel.Section = currentPage.ContentLink.GetSection(); return(viewmodel); }
public virtual IContent GetSection(ContentReference contentLink) { var currentContent = _contentLoader.Get <IContent>(contentLink); if (currentContent.ParentLink != null && currentContent.ParentLink.CompareToIgnoreWorkID(SiteDefinition.Current.StartPage)) { return(currentContent); } return(_contentLoader.GetAncestors(contentLink) .OfType <PageData>() .SkipWhile(x => x.ParentLink == null || !x.ParentLink.CompareToIgnoreWorkID(SiteDefinition.Current.StartPage)) .FirstOrDefault()); }
public string GetUrl(ContentReference contentReference) { var startPage = _startPages.Value.FirstOrDefault(x => x == contentReference.ToReferenceWithoutVersion()); if (startPage != null) { return(_urlResolver.GetUrl(startPage)); } var ancestorLinks = _contentLoader.GetAncestors(contentReference) .Select(x => x.ContentLink.ToReferenceWithoutVersion()); startPage = _startPages.Value.FirstOrDefault(x => ancestorLinks.Contains(x)); return(_urlResolver.GetUrl(startPage ?? ContentReference.StartPage)); }
private IList <string> ParentTagsForCategory(NodeContent category) { var result = new List <string>(); IEnumerable <NodeContent> ancestors = _contentLoader .GetAncestors(category.ContentLink) .OfType <NodeContent>(); foreach (var ancestor in ancestors) { result.Add(ancestor.Code.SanitizeKey()); } return(result); }
public static System.Collections.Generic.ICollection <string> GetVirtualPathNodes(ContentReference contentLink, IContentLoader contentLoader) { Validator.ThrowIfNull("contentLink", contentLink); Validator.ThrowIfNull("contentLoader", contentLoader); var collection = new Collection <string>(); foreach (IContent current in contentLoader.GetAncestors(contentLink).Reverse()) { collection.Add(current.ContentGuid.ToString()); } var content = contentLoader.Get <IContent>(contentLink); collection.Add(content.ContentGuid.ToString()); return(collection); }
public IEnumerable <Webhook> GetWebhooksForContentEvent(IContent content, EventType eventType) { var ancestors = _contentLoader.GetAncestors(content.ContentLink).Select(x => x.ContentLink.ID); var lang = (content as ILocalizable)?.Language.Name ?? "-"; IEnumerable <Webhook> hooks; using (var store = _dataStoreFactory.CreateStore(typeof(Webhook))) { hooks = store.Items <Webhook>().Where(x => ancestors.Contains(x.ParentId) || x.ParentId.Equals(content.ContentLink.ID)).ToList(); } return(hooks.Where(x => (x.ContentTypes == null || x.ContentTypes.Length.Equals(0) || x.ContentTypes.Contains(content.ContentTypeID)) && (x.EventTypes == null || x.EventTypes.Length.Equals(0) || x.EventTypes.Contains(eventType.Key)))); }
private IEnumerable <ISettingsPage> GetSettingsPages(IContent content) { var rtnList = new List <ISettingsPage>(); var ancenters = Enumerable.Repeat(content, 1).Concat(_contentLoader.GetAncestors(content.ContentLink)); foreach (var ancenter in ancenters) { if (ancenter is ISettingsPage settingsPage) { rtnList.Add(settingsPage); } var settingsPages = _contentLoader.GetChildren <ISettingsPage>(ancenter.ContentLink); rtnList.AddRange(settingsPages); } return(rtnList); }
public virtual async System.Threading.Tasks.Task PageViewed(HttpContextBase context, PageData pageData) { if (pageData == null || !PageIsInViewMode()) { await System.Threading.Tasks.Task.CompletedTask; } var site = _siteDefinitionResolver.GetByContent(pageData.ContentLink, true); var ancesctors = _contentLoader.GetAncestors(pageData.ContentLink).Select(c => c.ContentGuid).ToArray(); try { var user = new UserData { Name = PrincipalInfo.CurrentPrincipal?.Identity?.Name, Email = EPiServerProfile.Current?.Email, }; var pageDataTrackingModel = new EpiPageViewWrapper { Epi = new EpiPageView { ContentGuid = pageData.ContentGuid, Language = pageData.Language?.Name, SiteId = site.Id, Ancestors = ancesctors, } }; var trackingData = new TrackingData <EpiPageViewWrapper> { EventType = "epiPageView", PageTitle = pageData.Name, User = user, Value = $"Viewed {pageData.Name}", Payload = pageDataTrackingModel }; await _trackingService.Track(trackingData, context); } catch (Exception ex) { _logger.Error(ex.Message, ex); } }
public string GetUrl(ContentReference contentReference) { var siteDefinition = _siteDefinitions.Value.FirstOrDefault(x => x.StartPage.ToReferenceWithoutVersion() == contentReference.ToReferenceWithoutVersion()); if (siteDefinition != null) { return(ResolveUrlForSite(siteDefinition)); } var ancestorLinks = _contentLoader.GetAncestors(contentReference) .Select(x => x.ContentLink.ToReferenceWithoutVersion()); siteDefinition = _siteDefinitions.Value.FirstOrDefault(x => ancestorLinks.Contains(x.StartPage.ToReferenceWithoutVersion())); if (siteDefinition == null) { throw new ApplicationException("No site found for " + contentReference); } return(ResolveUrlForSite(siteDefinition)); }
public static PageData GetAncestorAtLevel(this PageData page, ContentReference rootPage, int offset, IContentLoader contentLoader) { if (page == null) { throw new ArgumentNullException("page"); } if (ContentReference.IsNullOrEmpty(rootPage)) { throw new ArgumentException("rootPage"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Offset cannot be negative"); } if (contentLoader == null) { contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>(); } var list = contentLoader.GetAncestors(page.ContentLink) .Reverse() .Select(x => x.ContentLink) .ToList(); if (list.Count > 0 && list[0].CompareToIgnoreWorkID(rootPage)) { if (list.Count == offset + 1) { return(page); } if (list.Count > offset + 1) { return(contentLoader.Get <PageData>(list[offset + 1])); } } return(null); }
public static void RenderMainNavigation( this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; //Top level elements writer.WriteLine("<nav class=\"navbar navbar-inverse\">"); writer.WriteLine("<ul class=\"nav navbar-nav\">"); if (includeRoot) { //Link to the root page if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine( html.PageLink(rootLink).ToHtmlString()); writer.WriteLine("</li>"); } //Retrieve and filter the root pages children contentLoader = contentLoader ?? ServiceLocator.Current.GetInstance<IContentLoader>(); var topLevelPages = contentLoader .GetChildren<PageData>(rootLink); topLevelPages = FilterForVisitor.Filter(topLevelPages) .OfType<PageData>() .Where(x => x.VisibleInMenu); //Retrieve the "path" from the current page up to the //root page in the content tree in order to check if //a link should be highlighted. var currentBranch = contentLoader.GetAncestors(contentLink) .Select(x => x.ContentLink) .ToList(); currentBranch.Add(contentLink); //Link to the root pages children foreach (var topLevelPage in topLevelPages) { if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString()); writer.WriteLine("</li>"); } //Close top level element writer.WriteLine("</ul>"); writer.WriteLine("</nav>"); }
public override IEnumerable <IContent> GetAncestors(ContentReference contentLink) { return(_defaultContentLoader.GetAncestors(contentLink)); }
public ActionResult Index(DemoPage currentPage) { // Andrahandsalternativ till Constructor Injection // var loader1 = ServiceLocator.Current.GetInstance<IContentLoader>(); var currentPageId = currentPage.ContentLink; // ID of a page is always in ContentLink property var startPageId = ContentReference.StartPage; IEnumerable <IContent> pages = loader.GetChildren <IContent>(startPageId); //Tvättar bort sidor som man inte får eller kan länka till IEnumerable <PageData> filteredListOfPages = FilterForVisitor.Filter(pages).Cast <PageData>(); //Tvätta bort sidor som inte ska synas i navigeringen. IEnumerable <PageData> listWithPagesVisibleInNavigation = filteredListOfPages.Where(p => p.VisibleInMenu == true); // Ladda in alla föräldrar var allAncestors = loader.GetAncestors(currentPageId); // Bygg en lista med MenuItem som view model för menyn. var list = new List <MenuItem>(); foreach (var page in listWithPagesVisibleInNavigation) { var item = new MenuItem(); item.Page = page; item.Active = allAncestors.Contains(page); list.Add(item); } // Laddar nyheter med GetChildren IEnumerable <PageData> myListOfPages = new List <PageData>(); // Hämta sidor under sidan som egenskapen IdOfParentPageToList pekar ut if (!ContentReference.IsNullOrEmpty(currentPage.IdOfParentPageToList)) { myListOfPages = loader.GetChildren <PageData>(currentPage.IdOfParentPageToList); } // Ladda nyheter med databas sök PageReference startPageForSearch = new PageReference(startPageId); var criterias = new PropertyCriteriaCollection { new PropertyCriteria { Type = PropertyDataType.String, Name = "PageName", Condition = CompareCondition.Contained, Value = "alloy" } }; var result = query.FindPagesWithCriteria(startPageForSearch, criterias); var model = new DemoPageViewModel(); model.CurrentPage = currentPage; model.MainMenuList = listWithPagesVisibleInNavigation; model.MainMenuListWithItems = list; model.MyListOfPages = myListOfPages; model.RootPageOfMyListOfPages = loader.Get <PageData>(currentPage.IdOfParentPageToList); model.SearchResult = result; return(View(model)); }
private static IEnumerable<PageData> NavigationPath( ContentReference contentLink, IContentLoader contentLoader, ContentReference fromLink = null) { fromLink = fromLink ?? ContentReference.RootPage; //Find all pages between the current and the //"from" page, in top-down order. var path = contentLoader.GetAncestors(contentLink) .Reverse() .SkipWhile(x => ContentReference.IsNullOrEmpty(x.ParentLink) || !x.ParentLink.CompareToIgnoreWorkID(fromLink)) .OfType<PageData>() .ToList(); //In theory the current content may not be a page. //We check that and, if it is, add it to the end of //the content tree path. var currentPage = contentLoader .Get<IContent>(contentLink) as PageData; if (currentPage != null) { path.Add(currentPage); } return path; }
public static void RenderMainNavigation(this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; // top level writer.WriteLine("<nav class=\"navbar navbar-inverse\">"); writer.WriteLine("<ul class=\"nav navbar-nav\">"); if (includeRoot) { if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(rootLink).ToHtmlString()); writer.WriteLine("</li>"); } // hämta ut alla barn från start contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); var topLevelPages = contentLoader.GetChildren<PageData>(rootLink); topLevelPages = FilterForVisitor.Filter(topLevelPages).OfType<PageData>().Where(x => x.VisibleInMenu); var currentBranch = contentLoader.GetAncestors(contentLink).Select(x => x.ContentLink).ToList(); currentBranch.Add(contentLink); //skriv ut dom foreach (var topLevelPage in topLevelPages) { if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString()); writer.WriteLine("</li>"); } //Close top level writer.WriteLine("</ul"); writer.WriteLine("</nav>"); }
public ActionResult Index(TestsPage currentPage) { //retrieving the start page from the current page (current page must not be a sibling of Start page) var startPage = _contentLoader.GetAncestorOrSelf <StartPage>(currentPage); //test the 'or self' part of the function - must return the currentPage var selfPage = _contentLoader.GetAncestorOrSelf <TestsPage>(currentPage); //testing the 'get ancestor' function var ancestorSitePage = _contentLoader.GetAncestor <StartPage>(currentPage); //find the first descendent with the name = 'Find a reseller' var descendentTest = _contentLoader.GetDescendent <StandardPage>(startPage, x => x.Name == "Find a reseller"); //find all the ancestors of the 'Find a reseller' page var ancestors = _contentLoader.GetAncestors(descendentTest); //find all the standard page ancestors of the 'Find a reseller' page var ancestorsPredicateType = _contentLoader.GetAncestors <StandardPage>(descendentTest); //find all the ancestors with more than 2 children Func <IContent, bool> predicateNumChildren = x => _contentLoader.GetChildren <IContentData>(x.ContentLink).Count() > 2; var ancestorsPredicateNumChildren = _contentLoader.GetAncestors(descendentTest, predicateNumChildren); //find the first product descendant of start page var descendantCurrentPage = _contentLoader.GetDescendent <ProductPage>(startPage); //find the first descendant of start page that is a standard page and starts with 'White' var descendentMultiPredicate = _contentLoader.GetDescendent <StandardPage>(startPage, x => x.Name.StartsWith("White")); //find all the product descendents of start page var descendentsProductPages = _contentLoader.GetDescendents <ProductPage>(startPage); //find all the siblings of the current page var testSiblingsCurrentPage = _contentLoader.Siblings(currentPage); //find all the product siblings of the current page var testTypedSiblingsCurrentPage = _contentLoader.Siblings <ProductPage>(currentPage); //find the next sibling by name of the page named 'alloy plan' var alloyPlanPage = _contentLoader.FirstChild <IContent>(ContentReference.StartPage); var nextSibling = _contentLoader.FollowingSibling <IContent, string>(alloyPlanPage, x => x.Name); //find the previous sibling by 'sort order' property Func <IContent, int> sortingPredicate = x => (int)x.Property["PagePeerOrder"].Value; var previousSibling = _contentLoader.PreviousSibling <ProductPage, int>(currentPage, sortingPredicate); var testValues = new TestsViewModel { TestAncestorStartPage = startPage, TestAncestorOrSelf = selfPage, TestAncestor = ancestorSitePage, TestDescendentWithPredicate = descendentTest, TestAncestors = ancestors, TestAncestorsPredicateType = ancestorsPredicateType, TestAncestorsPredicateNumChildren = ancestorsPredicateNumChildren, TestStartDescendentProductPage = descendantCurrentPage, TestDescendentMultiPredicate = descendentMultiPredicate, TestDescendentsPredicateType = descendentsProductPages, TestSiblingsCurrentPage = testSiblingsCurrentPage, TestTypedSiblingsCurrentPage = testTypedSiblingsCurrentPage, TestNextSiblingByName = nextSibling, TestPreviousSiblingBySortOrder = previousSibling, }; ViewBag.TestsObjects = testValues; var model = PageViewModel.Create(currentPage); return(View(model)); }
/// <summary> /// /// </summary> /// <param name="html"></param> /// <param name="rootLink"></param> /// <param name="contentLink"></param> /// <param name="includeRoot"></param> /// <param name="contentLoader"></param> public static void RenderMainNavigation(this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; writer.WriteLine("<nav class='navbar navbar-expand-md navbar-light bg-light'>"); writer.WriteLine("<a class='navbar-brand' href='#'>Acquire EPiServer</a>"); writer.WriteLine("<button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarSupportedContent' aria-controls='navbarSupportedContent' aria-expanded='false' aria-label='Toggle navigation'>"); writer.WriteLine("<span class='navbar-toggler-icon'></span>"); writer.WriteLine("</button>"); writer.WriteLine("<div class='collapse navbar-collapse' id='navbarSupportedContent'>"); writer.WriteLine("<ul class='navbar-nav mr-auto'>"); if (includeRoot) { if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active nav-item\">"); } else { writer.WriteLine("<li class=\"nav-item\">"); } writer.WriteLine(html.PageLink(rootLink, null, new { @class = "nav-link" }).ToHtmlString()); writer.WriteLine("</li>"); } contentLoader = contentLoader ?? ServiceLocator.Current.GetInstance <IContentLoader>(); var topLevelPages = contentLoader.GetChildren <PageData>(rootLink); // Filtering out the pages which should not be appeared in the menu topLevelPages = FilterForVisitor.Filter(topLevelPages).OfType <PageData>().Where(x => x.VisibleInMenu); var currentBranch = contentLoader.GetAncestors(contentLink).Select(x => x.ContentLink).ToList(); currentBranch.Add(contentLink); // Processing further with top level pages foreach (var topLevelPage in topLevelPages) { // Checking if current location is equal to content link. if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active nav-item\">"); } else { writer.WriteLine("<li class=\"nav-item\">"); } writer.WriteLine(html.PageLink(topLevelPage, null, new { @class = "nav-link" }).ToHtmlString()); writer.WriteLine("</li>"); } writer.WriteLine("</ul>"); writer.WriteLine("<form class='form-inline my-2 my-lg-0'>"); writer.WriteLine("<input class='form-control mr-sm-2' type='search' placeholder='Search' aria-label='Search'>"); writer.WriteLine("<button class='btn btn-outline-success my-2 my-sm-0' type='submit'>Search</button>"); writer.WriteLine("</form>"); writer.WriteLine("</div>"); writer.WriteLine("</nav>"); }
/// <summary> /// Determines if <see cref="IContent"/> is a <see cref="ContentFolder"/> or any subclass like ContentAssetFolder /// </summary> /// <param name="content">The <see cref="IContent"/> to test</param> /// <returns><code>true</code> if <see cref="IContent"/> is of type <see cref="ContentFolder"/>; otherwise <code>false</code></returns> public virtual bool IsCapable(IContent content) { return(_contentLoader.GetAncestors(content.ContentLink).Any(x => x is ContentAssetFolder folder && folder.ContentOwnerID != System.Guid.Empty)); }
/// <summary> /// Gets IContent ancestors /// </summary> /// <param name="content"></param> /// <returns></returns> public IEnumerable <ContentReference> GetAncestors(IContent content) { return(_contentLoader.GetAncestors(content.ContentLink)?.Select(c => c.ContentLink)); }
private static IEnumerable<PageData> NavigationPath(ContentReference contentLink, IContentLoader contentLoader, ContentReference fromLink = null) { fromLink = fromLink ?? ContentReference.RootPage; var path = contentLoader.GetAncestors(contentLink) .Reverse() .SkipWhile(x => ContentReference.IsNullOrEmpty(x.ParentLink) || !x.ParentLink.CompareToIgnoreWorkID(ContentReference.StartPage)) .OfType<PageData>() .ToList(); var currentPage = contentLoader.Get<IContent>(contentLink) as PageData; if (currentPage != null) { path.Add(currentPage); } return path; }
public static void RenderMainNavigation( this HtmlHelper html, PageReference rootLink = null, ContentReference contentLink = null, bool includeRoot = true, IContentLoader contentLoader = null) { contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink(); rootLink = rootLink ?? ContentReference.StartPage; var writer = html.ViewContext.Writer; //Top level elements writer.WriteLine("<nav class=\"navbar navbar-inverse\">"); writer.WriteLine("<ul class=\"nav navbar-nav\">"); if (includeRoot) { //Link to the root page if (rootLink.CompareToIgnoreWorkID(contentLink)) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine( html.PageLink(rootLink).ToHtmlString()); writer.WriteLine("</li>"); } //Retrieve and filter the root pages children contentLoader = contentLoader ?? ServiceLocator.Current.GetInstance <IContentLoader>(); var topLevelPages = contentLoader .GetChildren <PageData>(rootLink); topLevelPages = FilterForVisitor.Filter(topLevelPages) .OfType <PageData>() .Where(x => x.VisibleInMenu); //Retrieve the "path" from the current page up to the //root page in the content tree in order to check if //a link should be highlighted. var currentBranch = contentLoader.GetAncestors(contentLink) .Select(x => x.ContentLink) .ToList(); currentBranch.Add(contentLink); //Link to the root pages children foreach (var topLevelPage in topLevelPages) { if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink))) { writer.WriteLine("<li class=\"active\">"); } else { writer.WriteLine("<li>"); } writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString()); writer.WriteLine("</li>"); } //Close top level element writer.WriteLine("</ul>"); writer.WriteLine("</nav>"); }