Copied to clipboard

Flag this post as spam?

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


  • Shaun 248 posts 475 karma points
    Apr 11, 2014 @ 15:48
    Shaun
    0

    Missing Root Node in Umbraco V7 Custom Section Tree

    Hi All

    I'm trying to follow the "modern" method of creating a tree in a custom section. I can't seem to get the root ndoe to appear though, and it's driving me mad.

    I've taken a lot from here

    http://www.enkelmedia.se/blogg/2013/11/22/creating-custom-sections-in-umbraco-7-part-1.aspx

    Here is my Application class

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    using umbraco.businesslogic;
    using umbraco.interfaces;
    
    namespace myproject.BusinessLogic
    {
        [Application("ClientZone", "ClientZone", "icon-file-cabinet", 15)]
        public class ClientZoneApplication : IApplication { }  
    }

    and it generates the following in /config/applications.config

     <add alias="ClientZone" name="ClientZone" icon="icon-file-cabinet" sortOrder="15" />

     

    Here is my tree controller class

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Http.Formatting;
    using System.Web;
    
    using Umbraco.Web.Models.Trees;
    using Umbraco.Web.Mvc;
    using Umbraco.Web.Trees;
    
    namespace myproject.BusinessLogic
    {
        [PluginController("ClientZone")]
        [Umbraco.Web.Trees.Tree("ClientZone", "ClientZoneTree", "Client Zone", iconClosed: "icon-folder")]
        public class ClientZoneTreeController : TreeController
        {
            protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
            {           
                    var nodes = new TreeNodeCollection();
                    var item = this.CreateTreeNode("dashboard", id, queryStrings, "My item", "icon-truck", true);
                    nodes.Add(item);
                    return nodes;
    
    
            }
    
            protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
            {
                var menu = new MenuItemCollection();
                //menu.DefaultMenuAlias = ActionNew.Instance.Alias;
                //menu.Items.Add<ActionNew>("Create");
                return menu;
            }
        }
    }

    and here is what is generated in my /config/trees.config 

    <add initialize="true" sortOrder="0" alias="ClientZoneTree" application="ClientZone" title="Client Zone" iconClosed="icon-folder" iconOpen="icon-folder-open" type="myproject.BusinessLogic.ClientZoneTreeController, myproject" />

    Now I would expect this to generate a folder icon with the word "Client Zone" next to it. Clicking on that should open up the tree to display a truck icon and the phrase "my item".

    However, all I get is the truck Icon. No Root. No folder. :(

    I've been all over it and can't see what I'm doing wrong. Can anyone help?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 12, 2014 @ 21:12
    Jan Skovgaard
    0

    Hi Shaun

    Have you checked that your user is actually allowed to see the section you're adding?

    This got me when I was playing around with adding custom sections and trees - I was pulling my hair of untill Warren Buckley said..."Have you given your user access to the section?"...So try to check...that's probably it...so simple...so frustrating! :D

    /Jan

  • Shaun 248 posts 475 karma points
    Apr 14, 2014 @ 11:42
    Shaun
    0

    Hi Jan

    Thanks for your reply. Yeah, I have the section set to visible on the user. I can see the section icon and click through to the section. It's just the root node doesn't appear.

    I've found a way around the problem. I can set up a new node using CreateTreeNode inside my TreeNodeCollection, and use that as my root.

    What is odd is that this line here...

     [Umbraco.Web.Trees.Tree("ClientZone", "ClientZoneTree", "Client Zone", iconClosed: "icon-folder")]

    ...doesn't seem to create the root node, which is strange, as from the parameters being sent to it, you'd expect it to generate one.

  • Tom Maton 387 posts 660 karma points
    May 10, 2014 @ 18:54
    Tom Maton
    0

    Hi Shaun,

    Did you ever solve this? As i'm running into the same problem and cant find a resolution anywhere :(

    Thanks,
    Tom 

  • Shaun 248 posts 475 karma points
    May 12, 2014 @ 11:10
    Shaun
    0

    Hi Tom

    From what I can see there is no solution as such, it's just that the functionality of the treenodes doesn't match what is laughably described as the documentation.

    In the end I went for this approach.

     [Tree("mycustomsection", "mycustomsectiontree", "my custom section")]
     [PluginController("mycustomsection")]
     public class mycustomsectionTreeController : TreeController
    {


    I'm not using all the attribute properties as suggested in the earlier links, as they don't do anything, I am setting a plugincontroller though, to keep all my code neat.

    This next bit occurs immediately inside the treecontroller class. If it doesn't work it's because I'm having to anonymise it, and simplify it as i copy n paste it over.

    protected override Umbraco.Web.Models.Trees.TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
    {
    var tree = new Umbraco.Web.Models.Trees.TreeNodeCollection();
    //check if we're rendering the root node if (id == Constants.System.Root.ToInvariantString()) {
    var RootNode = CreateTreeNode("1", "-1", queryStrings, "my root node"); RootNode.HasChildren = true; tree.Add(RootNode);
    }
    else if(id == "1") {
    //this is a child of the root node
    var childnode = CreateTreeNode("1-1", "1", queryStrings, "my first child node");
    var otherchildnode = CreateTreeNode "1-2", "1", queryStrings "my second child node");
    tree.Add(childnode);
    tree.Add(otherchildnode);
    }
    else if(id.StartsWith("1-"))
    {
    //this must be a third level node, e.g. one that's under the child nodes.
    }
    return tree; //this tree doesn't suport rendering more than 1 level throw new NotSupportedException();

    It's a bit clunky, but it does the job.

Please Sign in or register to post replies

Write your reply to:

Draft