private static void BuildExpandableTree(IList <NavBE> list, ExpandableNavPage node, PageBE page) { uint node_id = node.NavPage.Id; ulong homepageId = DekiContext.Current.Instance.HomePageId; uint parentId = (node_id == homepageId) ? 0 : node_id; foreach (NavBE child in list) { if ((child.ParentId == parentId) & (child.Id != homepageId)) { Title childTitle = Title.FromDbPath((NS)child.NameSpace, child.Title, child.DisplayName); // skip children if they are siblings of the top User: or Template: page if (((page.Title.IsUser) || (page.Title.IsSpecial) || (page.Title.IsTemplate)) && (node_id == homepageId) && !childTitle.IsParentOf(page.Title)) { continue; } var sChild = new ExpandableNavPage(child); sChild.Parent = node; node.Children.Add(sChild); ///recursive. BuildExpandableTree(list, sChild, page); } } if (node_id == page.ID) { node.IsSelected = true; } if (node_id == homepageId) { node.IsHomepage = true; } }
private static XDoc CreateExpandableTree(IList <NavBE> list, PageBE page) { List <ExpandableNavPage> tree = new List <ExpandableNavPage>(); bool onlyChildren = list.Count(s => s.ParentId == 0 || s.ParentId == DekiContext.Current.Instance.HomePageId) == 0; foreach (NavBE node in list) { uint node_id = node.Id; ulong homepageId = DekiContext.Current.Instance.HomePageId; uint parentId = (node_id == homepageId) ? 0 : node_id; ulong node_parent_id = node.ParentId; // fix parent_id: it's stored as zero for home and children of home if ((node_parent_id == 0) && (node_id != homepageId)) { node_parent_id = homepageId; } // fix page_parent_id: it's stored as zero for home and children of home ulong page_parent_id = (ulong)page.ParentID; if ((page_parent_id == 0) && (page.ID != homepageId)) { page_parent_id = homepageId; } // don't include siblings root user pages if (((page.Title.IsUser) || (page.Title.IsSpecial) || (page.Title.IsTemplate)) && (page_parent_id == homepageId) && (node_parent_id == homepageId) && (node_id != page.ID)) { continue; } var sNode = new ExpandableNavPage(node); BuildExpandableTree(list, sNode, page); if (onlyChildren || (node.ParentId == 0 || node.ParentId == DekiContext.Current.Instance.HomePageId)) { tree.Add(sNode); } } tree[tree.Count - 1].LastParent = true; XDoc result = new XDoc("tree"); return(CreateExpandableTreeDoc(ref result, tree)); }
private static void CreateExpandableTreeChildrenDoc(ref XDoc result, ExpandableNavPage branch) { uint nodeID = branch.NavPage.Id; // fix page_parent_id: it's stored as zero for home and children of home Title nodeTitle = Title.FromDbPath((NS)branch.NavPage.NameSpace, branch.NavPage.Title, branch.NavPage.DisplayName); string name = nodeTitle.AsUserFriendlyName(); List <string> css = new List <string>(); result.Start("ul"); if (branch.Parent != null && branch.Parent.Children[branch.Parent.Children.Count - 1] == branch) { css.Add("lastNode"); } else if (branch.LastParent) { css.Add("lastNode"); } if (branch.IsHomepage) { css.Add("homepage"); } result.Attr("class", String.Join(" ", css.ToArray())); css.Clear(); result.Start("li"); result.Attr("id", "n" + nodeID); bool isChild = false; css.Add("node"); if (branch.IsAncestor) { css.Add("ancestor"); } if (branch.IsSelected) { css.Add("selected"); } if (branch.IsHomepage) { css.Add("homeNode"); } else { if (branch.Children.Count > 0 || branch.NavPage.ChildCount > 0) { css.Add(branch.IsAncestor || branch.IsSelected ? "parentOpen" : "parentClosed"); } else { css.Add("child"); isChild = true; } } result.Attr("class", String.Join(" ", css.ToArray())); ///Icon Spacer result.Start("div"); result.Attr("class", "icon"); if (!isChild) { result.Attr("onclick", "DekiExpandableNav.Toggle(this,event);"); } ///Link. result.Start("a").Value(name); const string stopBubbelingScript = @"if (!event) var event = window.event; event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation();"; result.Attr("onclick", stopBubbelingScript); if (css.Contains("selected")) { result.Attr("class", "selected"); } else if (css.Contains("ancestor")) { result.Attr("class", "ancestor"); } else if (branch.IsHomepage) { result.Attr("class", "homepage"); } result.Attr("title", name); result.Attr("href", Utils.AsPublicUiUri(nodeTitle)); result.End(); result.End(); if (branch.Children.Count > 0 && branch.NavPage.Id != DekiContext.Current.Instance.HomePageId) { foreach (ExpandableNavPage cBranch in branch.Children) { CreateExpandableTreeChildrenDoc(ref result, cBranch); } } result.End(); result.End(); }
private static void CreateExpandableTreeChildrenDoc(ref XDoc result, ExpandableNavPage branch) { uint nodeID = branch.NavPage.Id; // fix page_parent_id: it's stored as zero for home and children of home Title nodeTitle = Title.FromDbPath((NS)branch.NavPage.NameSpace, branch.NavPage.Title, branch.NavPage.DisplayName); string name = nodeTitle.AsUserFriendlyName(); List<string> css = new List<string>(); result.Start("ul"); if(branch.Parent != null && branch.Parent.Children[branch.Parent.Children.Count - 1] == branch) { css.Add("lastNode"); } else if(branch.LastParent) { css.Add("lastNode"); } if(branch.IsHomepage) { css.Add("homepage"); } result.Attr("class", String.Join(" ", css.ToArray())); css.Clear(); result.Start("li"); result.Attr("id", "n" + nodeID); bool isChild = false; css.Add("node"); if(branch.IsAncestor) { css.Add("ancestor"); } if(branch.IsSelected) { css.Add("selected"); } if(branch.IsHomepage) { css.Add("homeNode"); } else { if(branch.Children.Count > 0 || branch.NavPage.ChildCount > 0) { css.Add(branch.IsAncestor || branch.IsSelected ? "parentOpen" : "parentClosed"); } else { css.Add("child"); isChild = true; } } result.Attr("class", String.Join(" ", css.ToArray())); ///Icon Spacer result.Start("div"); result.Attr("class", "icon"); if(!isChild) { result.Attr("onclick", "DekiExpandableNav.Toggle(this,event);"); } ///Link. result.Start("a").Value(name); const string stopBubbelingScript = @"if (!event) var event = window.event; event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation();"; result.Attr("onclick", stopBubbelingScript); if(css.Contains("selected")) { result.Attr("class", "selected"); } else if(css.Contains("ancestor")) { result.Attr("class", "ancestor"); } else if(branch.IsHomepage) { result.Attr("class", "homepage"); } result.Attr("title", name); result.Attr("href", Utils.AsPublicUiUri(nodeTitle)); result.End(); result.End(); if(branch.Children.Count > 0 && branch.NavPage.Id != DekiContext.Current.Instance.HomePageId) { foreach(ExpandableNavPage cBranch in branch.Children) { CreateExpandableTreeChildrenDoc(ref result, cBranch); } } result.End(); result.End(); }
private static void BuildExpandableTree(IList<NavBE> list, ExpandableNavPage node, PageBE page) { uint node_id = node.NavPage.Id; ulong homepageId = DekiContext.Current.Instance.HomePageId; uint parentId = (node_id == homepageId) ? 0 : node_id; foreach(NavBE child in list) { if((child.ParentId == parentId) & (child.Id != homepageId)) { Title childTitle = Title.FromDbPath((NS)child.NameSpace, child.Title, child.DisplayName); // skip children if they are siblings of the top User: or Template: page if(((page.Title.IsUser) || (page.Title.IsSpecial) || (page.Title.IsTemplate)) && (node_id == homepageId) && !childTitle.IsParentOf(page.Title)) { continue; } var sChild = new ExpandableNavPage(child); sChild.Parent = node; node.Children.Add(sChild); ///recursive. BuildExpandableTree(list, sChild, page); } } if(node_id == page.ID) { node.IsSelected = true; } if(node_id == homepageId) { node.IsHomepage = true; } }
private static XDoc CreateExpandableTree(IList<NavBE> list, PageBE page) { List<ExpandableNavPage> tree = new List<ExpandableNavPage>(); bool onlyChildren = list.Count(s => s.ParentId == 0 || s.ParentId == DekiContext.Current.Instance.HomePageId) == 0; foreach(NavBE node in list) { uint node_id = node.Id; ulong homepageId = DekiContext.Current.Instance.HomePageId; uint parentId = (node_id == homepageId) ? 0 : node_id; ulong node_parent_id = node.ParentId; // fix parent_id: it's stored as zero for home and children of home if((node_parent_id == 0) && (node_id != homepageId)) { node_parent_id = homepageId; } // fix page_parent_id: it's stored as zero for home and children of home ulong page_parent_id = (ulong)page.ParentID; if((page_parent_id == 0) && (page.ID != homepageId)) { page_parent_id = homepageId; } // don't include siblings root user pages if(((page.Title.IsUser) || (page.Title.IsSpecial) || (page.Title.IsTemplate)) && (page_parent_id == homepageId) && (node_parent_id == homepageId) && (node_id != page.ID)) { continue; } var sNode = new ExpandableNavPage(node); BuildExpandableTree(list, sNode, page); if(onlyChildren || (node.ParentId == 0 || node.ParentId == DekiContext.Current.Instance.HomePageId)) { tree.Add(sNode); } } tree[tree.Count - 1].LastParent = true; XDoc result = new XDoc("tree"); return CreateExpandableTreeDoc(ref result, tree); }