Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marcel van Helmont 68 posts 259 karma points c-trib
    Jan 20, 2014 @ 10:34
    Marcel van Helmont
    0

    Custom Multilevel tree

    Hello,

    Does anybody knows how to pass a node type in a tree?

    protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings){
    var nodes = new TreeNodeCollection();
    
    if (id == Constants.System.Root.ToInvariantString())
    {
        var level1 = CreateTreeNode(id, id, queryStrings, "Level1", "icon-folder-close", true);
        level1.NodeType = "level1";
        nodes.Add(level1);
    }
    else
    {
        //how can i get the nodetype here so i can create nodes by there nodetype
    }
    
    return nodes
    }
    
    protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings){
    var menu = new MenuItemCollection();
    
    if (id == Constants.System.Root.ToInvariantString())
    {
        menu.DefaultMenuAlias = ActionNew.Instance.Alias;
        menu.Items.Add<ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
    }
    else
    {
        // and also here how can i get the node type to make the menu based on a nodetype
    }
    }
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2014 @ 12:06
    Jeroen Breuer
    0

    Did you already read this documentation? http://umbraco.github.io/Belle/#/tutorials/Creating-Editors-Trees

    Jeroen

  • Marcel van Helmont 68 posts 259 karma points c-trib
    Jan 20, 2014 @ 12:16
    Marcel van Helmont
    0

    Yes i have read the documentation, but there never been a word on multi level trees.. Only 1 level, i am currently working on a way thats use one table of nodes with a nodetype set in it and zo i can have multiple levels with different types.. But it would be nice that i can be done in de treecontroller..

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2014 @ 12:34
    Jeroen Breuer
    0

    If you can't find it in the documentation it might be a good idea to look into the v7 source code. There are some multilevel trees in Umbraco itself so you can probably find how it's done.

    Jeroen

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jan 23, 2014 @ 12:05
    David Brendel
    0

    The GetTreeNodes method has an id as first parameter. You can check this id to see which nodes you have to return.

    if (id == global::Umbraco.Core.Constants.System.Root.ToInvariantString())
            {
                menu.Items.Add(new MenuItem("createCalendar", "Create Calendar"));
                menu.Items.Add(new MenuItem("createLocation", "Create Location"));
            }
            else if (id == "calendarTree")
            {
                menu.Items.Add(new MenuItem("createCalendar", "Create Calendar"));
            }
    

    You can set this id as the first parameter on the CreateTreeNode-method

  • Shaun 248 posts 475 karma points
    Apr 28, 2014 @ 12:40
    Shaun
    0

    Did anyone find a solution for this in the end?

    I can't really use the id to work out the nodetype as I have certain nodes that could have a variety of node types as children. All the ID really tells me is where it is located on the tree, not the type of node it is.

    I've looked in what passes for the documentation and seen nothing in there. I've also looked in the code and it doesn't seem as if they are passing any node information to getmenufornode at all.

     

  • Sören Deger 733 posts 2844 karma points c-trib
    Jul 16, 2015 @ 20:04
    Sören Deger
    1

    Hi all,

    I have also search a solution for a multi level tree in a custom section. But all solutions and snippets that I found was about 1 or 2 level trees. I have not found the solution to check the nodetyp, but I have found another solution to handle this with the nodelevel. I can check the nodelevel with the special custom string id. Here is my complete code:

    [Umbraco.Web.Trees.Tree("mhTicketsystem", "mhTicketsystemTree", "Ticketsystem" )]
        [PluginController("mhTicketsystem")]
        public class tsTreeController : TreeController
        {
            protected override TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            { 
                //check if we're rendering the root node's children
                if (id == Constants.System.Root.ToInvariantString())
                {
                    var nodes = new TreeNodeCollection();
    
                    var ticketsystemApi = new TicketsystemApiController();
    
                    IEnumerable<Ticketsystem> ticketsystemList = ticketsystemApi.GetAll();
                    if (ticketsystemList != null)
                    {
                        if (ticketsystemList.Count() != 0)
                        {
                            foreach (var ticketsystem in ticketsystemList)
                            {
                                var node = CreateTreeNode(
                                    ticketsystem.Id.ToString(),
                                    "-1",
                                    queryStrings,
                                    ticketsystem.Name,
                                    "icon-ticket",
                                    true);
    
                                nodes.Add(node);
                            }
                        }
                        else
                        {
                            var node = CreateTreeNode(
                                    "-1",
                                    "-1",
                                    queryStrings,
                                    "First create a Ticketsystem, please",
                                    "icon-home",
                                    false);
    
                            nodes.Add(node);
                        }
    
                        return nodes;
                    }
    
                }
                else
                {
                    int level = id.Count(c => c == '-');
    
                    switch (level)
                    {
                        case 0:
                            return GetChildTreeNodesTicketsystem(id, queryStrings);
                        case 1:
                            if (id.Contains("settings"))
                            {
                                return GetChildTreeNodesSettings(id, queryStrings);
                            } else if (id.Contains("tickets"))
                            {
                                return GetChildTreeNodesTickets(id, queryStrings);
                            }
                            break;
                        case 2:
                            return GetChildTreeNodesCompany(id, queryStrings);
                    }
    
                }
                throw new NotSupportedException();
            }
    
            private TreeNodeCollection GetChildTreeNodesTickets(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
                var nodes = new TreeNodeCollection {
                        CreateTreeNode("tickets-create" + id.Substring(id.IndexOf('-')), id, queryStrings, "Create", "icon-company", false),
                        CreateTreeNode("tickets-reports" + id.Substring(id.IndexOf('-')), id, queryStrings, "Reports", "icon-company", false)
                    };
                return nodes;
            }
    
            protected TreeNodeCollection GetChildTreeNodesTicketsystem(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
                var nodes = new TreeNodeCollection {
                    CreateTreeNode("settings-" + id, id, queryStrings, "Settings", "icon-settings", true, "mhTicketsystem/mhTicketsystemTree/settings/1"),
                    CreateTreeNode("tickets-" + id, id, queryStrings,"Tickets","icon-document",true)
                    };
                return nodes;
            }
    
            protected TreeNodeCollection GetChildTreeNodesSettings (string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
                var nodes = new TreeNodeCollection {
                        CreateTreeNode("settings-company" + id.Substring(id.IndexOf('-')), id, queryStrings, "Company", "icon-company", true, "mhTicketsystem/mhTicketsystemTree/company/1")
                    };
                return nodes;
            }
    
            protected TreeNodeCollection GetChildTreeNodesCompany(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
                var nodes = new TreeNodeCollection
                {
                    CreateTreeNode("settings-company-Departments" + id.Substring(id.LastIndexOf('-')), id, queryStrings, "Departments", "icon-library", false, "mhTicketsystem/mhTicketsystemTree/company_department/1"),
                    CreateTreeNode("settings-company-Employees" + id.Substring(id.LastIndexOf('-')), id, queryStrings, "Employees", "icon-male-and-female", false, "mhTicketsystem/mhTicketsystemTree/company_employee/1")
                };
                return nodes;
            }
    
            protected override MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
                var menu = new MenuItemCollection();
                if (id == Constants.System.Root.ToInvariantString())
                {
                    // root actions              
                    menu.Items.Add<CreateChildEntity, ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
                    menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);
                    return menu;
                }
                else if (!id.Contains('-'))
                {
                    menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
    
                }
                return menu;
            }
        }
    

    I hope this helps everyone with the same requirements for a multilevel tree ;-)

    Cheers, Sören

  • Ian 178 posts 752 karma points
    Dec 18, 2015 @ 14:19
    Ian
    0

    @Sören, way too little information on multi level trees in umbraco, your post gave that hint needed to know how to do it!

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 18, 2015 @ 14:35
    Sören Deger
    0

    Hi Ian,

    thanks for the feedback :-)

Please Sign in or register to post replies

Write your reply to:

Draft