public void BuildHierarchyTree_OtherNodes_AreNotIncluded() { HierarchyNode<ContentItem> node = new TreeHierarchyBuilder(a_b).Build(); ItemHierarchyNavigator ih = new ItemHierarchyNavigator(node); EnumerableAssert.DoesntContain(ih.EnumerateAllItems(), a); EnumerableAssert.DoesntContain(ih.EnumerateAllItems(), a_a); EnumerableAssert.DoesntContain(ih.EnumerateAllItems(), a_a_a); }
public override void ProcessRequest(HttpContext context) { string target = context.Request["target"] ?? Targets.Preview; var selection = new SelectionUtility(context.Request, N2.Context.Current); ContentItem selectedItem = selection.SelectedItem; context.Response.ContentType = "text/plain"; ItemFilter filter = Engine.EditManager.GetEditorFilter(context.User); IContentAdapterProvider adapters = Engine.Resolve<IContentAdapterProvider>(); var node = new TreeHierarchyBuilder(selectedItem, 2) .Children((item) => adapters.ResolveAdapter<NodeAdapter>(item).GetChildren(item, Interfaces.Managing)) .Build(); string selectableTypes = context.Request["selectableTypes"]; string selectableExtensions = context.Request["selectableExtensions"]; TreeUtility.Write(node, selectedItem, adapters, filter, selectableTypes, selectableExtensions, excludeRoot: true, target: target, writer: context.Response.Output); }
public override void ProcessRequest(HttpContext context) { string target = context.Request["target"] ?? Targets.Preview; var selection = new SelectionUtility(context.Request, N2.Context.Current); ContentItem selectedNode = selection.SelectedItem; context.Response.ContentType = "text/plain"; ItemFilter filter = Engine.EditManager.GetEditorFilter(context.User); IContentAdapterProvider adapters = Engine.Resolve<IContentAdapterProvider>(); var root = new TreeHierarchyBuilder(selectedNode, 2) .Children((item) => adapters.ResolveAdapter<NodeAdapter>(item).GetChildren(item, Interfaces.Managing)) .Build(); TreeNode tn = (TreeNode)new N2.Web.Tree(root) .LinkProvider(node => Web.UI.Controls.Tree.BuildLink(adapters.ResolveAdapter<NodeAdapter>(node), node, node.Path == selectedNode.Path, target)) .Filters(filter) .ToControl(); Web.UI.Controls.Tree.AppendExpanderNodeRecursive(tn, filter, target, adapters); RenderControls(tn.Controls, context.Response.Output); }
private void BuildControlHierarchy(ContentItem currentItem, ContentItem startPage) { if (currentItem == null) currentItem = startPage; ItemList children = currentItem.GetChildren(); if (children.Count > 0) currentItem = children[0]; IEnumerable<ContentItem> ancestors = GetAncestors(currentItem, startPage); ContentItem startingPoint = GetStartingPoint(); if (startingPoint != null) { HierarchyBuilder builder = null; if (BranchMode) { builder = new BranchHierarchyBuilder(currentItem, startingPoint); } else { builder = new TreeHierarchyBuilder(startingPoint, MaxLevels); } HierarchyNode<ContentItem> node = builder.Children(Filters).Build(); if (node.Current != null) { AddControlsRecursive(this, node, CurrentItem, ancestors); } } }
public void BuildHierarchyTree_CanTree_Depth1() { HierarchyNode<ContentItem> node = new TreeHierarchyBuilder(a, 1).Build(); ItemHierarchyNavigator ih = new ItemHierarchyNavigator(node); EnumerableAssert.Count(1, ih.EnumerateAllItems()); }
public void CanBuild_Partial_HierarchyTree() { HierarchyNode<ContentItem> node = new TreeHierarchyBuilder(a_a).Build(); ItemHierarchyNavigator ih = new ItemHierarchyNavigator(node); EnumerableAssert.Count(3, ih.EnumerateAllItems()); }
public void Parent_IsSet() { HierarchyNode<ContentItem> node = new TreeHierarchyBuilder(a, 3).Build(); Assert.That(node.Parent, Is.Null); Assert.That(node.Children[0].Parent, Is.EqualTo(node)); Assert.That(node.Children[0].Children[0].Parent, Is.EqualTo(node.Children[0])); }
public void HierarchyNodeCanWrite_Hierarchy_ToString() { HierarchyNode<ContentItem> node = new TreeHierarchyBuilder(a, 2).Build(); var result = node.ToString((c) => "[" + c.ID, (p) => "<", p => ">", (c) => "]"); Assert.That(result, Is.EqualTo("[1<[2][3]>]")); }
internal static HierarchyNode<ContentItem> BuildTreeStructure(ItemFilter filter, IContentAdapterProvider adapters, ContentItem selectedItem, int maxDepth) { var structure = new TreeHierarchyBuilder(selectedItem, maxDepth) .Children((item) => { var q = new N2.Persistence.Sources.Query { Parent = item, OnlyPages = true, Interface = Interfaces.Managing, Filter = filter }; return adapters.ResolveAdapter<NodeAdapter>(item).GetChildren(q); }) .Build(); return structure; }