public async Task <IViewComponentResult> InvokeAsync(string viewName, string filterName, string startingNodeKey) { TreeNode <NavigationNode> rootNode = await builder.GetTree(); NavigationViewModel model = new NavigationViewModel( startingNodeKey, filterName, Request.HttpContext, urlHelper, rootNode, permissionResolver, prefixProvider.GetPrefix(), log); return(View(viewName, model)); }
public async Task <IViewComponentResult> InvokeAsync(string viewName, string filterName, string startingNodeKey) { var rootNode = await builder.GetTree(); var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); NavigationViewModel model = new NavigationViewModel( startingNodeKey, filterName, Request.HttpContext, urlHelper, rootNode, permissionResolvers, nodeFinders, prefixProvider.GetPrefix(), log); return(View(viewName, model)); }
private async Task <TreeNode <NavigationNode> > BuildTreeInternal(NavigationTreeBuilderService service) { NavigationNode rootNav; var project = await projectService.GetCurrentProjectSettings(); IPage homePage = null; if ( project != null && project.UseDefaultPageAsRootNode && !string.IsNullOrEmpty(project.DefaultPageSlug) ) { //make the home page the "root" which contains all the other pages homePage = await pageService.GetPageBySlug(project.Id, project.DefaultPageSlug); } var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); var folderPrefix = prefixProvider.GetPrefix(); if ((homePage != null) && project.UseDefaultPageAsRootNode) { rootNav = new NavigationNode(); rootNav.IsRootNode = true; rootNav.Key = homePage.Id; rootNav.Text = homePage.Title; rootNav.Url = pageRouteHelper.ResolveHomeUrl(urlHelper, folderPrefix); // urlHelper.Content("~/" + folderPrefix); } else { rootNav = new NavigationNode(); rootNav.IsRootNode = true; rootNav.Key = "pagesRoot"; rootNav.Title = "Home"; rootNav.Text = "Home"; rootNav.Url = pageRouteHelper.ResolveHomeUrl(urlHelper, folderPrefix); // rootNav.Url = urlHelper.Content("~/" + folderPrefix); //rootNav.ChildContainerOnly = true; } var treeRoot = new TreeNode <NavigationNode>(rootNav); var rootList = await pageService.GetRootPages().ConfigureAwait(false); var rootListCount = rootList.Count(); var blogPosition = project.BlogPagePosition; if (project.AddBlogToPagesTree) { if (blogPosition > rootListCount) { blogPosition = rootListCount; } } var didAddBlog = false; if (rootListCount <= 1) { // if there are no pages we won't hit the loop below so go ahead and add the blog page if (project.AddBlogToPagesTree) { var node = new NavigationNode(); node.Key = project.BlogPageText; node.ParentKey = "RootNode"; node.Text = project.BlogPageText; if (project.BlogMenuLinksToNewestPost) { node.Action = "MostRecent"; node.Controller = "Blog"; node.Url = urlHelper.Action("MostRecent", "Blog"); } else { node.Action = "Index"; node.Controller = "Blog"; node.Url = urlHelper.Action("Index", "Blog"); } node.ComponentVisibility = project.BlogPageNavComponentVisibility; var blogNode = treeRoot.AddChild(node); didAddBlog = true; } } //rootList.Insert() var rootPosition = 1; foreach (var page in rootList) { var node = new NavigationNode(); if (!didAddBlog && (project.AddBlogToPagesTree && rootPosition == blogPosition)) { node.Key = project.BlogPageText; node.ParentKey = "RootNode"; node.Text = project.BlogPageText; if (project.BlogMenuLinksToNewestPost) { node.Action = "MostRecent"; node.Controller = "Blog"; node.Url = urlHelper.Action("MostRecent", "Blog"); } else { node.Action = "Index"; node.Controller = "Blog"; node.Url = urlHelper.Action("Index", "Blog"); } node.ComponentVisibility = project.BlogPageNavComponentVisibility; var blogNode = treeRoot.AddChild(node); node = new NavigationNode(); // new it up again for use below } if (project.UseDefaultPageAsRootNode && (homePage != null && homePage.Id == page.Id)) { rootPosition += 1; await AddChildNodes(treeRoot, project, folderPrefix).ConfigureAwait(false); continue; } node.Key = page.Id; node.ParentKey = page.ParentId; node.Text = page.Title; node.ViewRoles = page.ViewRoles; if (string.IsNullOrEmpty(folderPrefix)) { node.Url = urlHelper.RouteUrl(pageRouteHelper.PageIndexRouteName, new { slug = page.Slug }); } else { node.Url = urlHelper.RouteUrl(pageRouteHelper.FolderPageIndexRouteName, new { slug = page.Slug }); } // for unpublished pages PagesNavigationNodePermissionResolver // will look for projectid in CustomData and if it exists // filter node from view unless user has edit permissions if (!page.IsPublished) { node.CustomData = project.Id; } var treeNode = treeRoot.AddChild(node); await AddChildNodes(treeNode, project, folderPrefix).ConfigureAwait(false); rootPosition += 1; } return(treeRoot); }