Copied to clipboard

Flag this post as spam?

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


  • Bilal Haidar 144 posts 410 karma points
    May 08, 2015 @ 10:59
    Bilal Haidar
    0

    Root node not showing in a custom section

    Hi, I am following the source code written by Dave Woestenborghs on creating custom sections. The source code can be found here: https://bitbucket.org/dawoe/duugcustomsections/src

    When I add few customers, they appear below each other with no grouping root node. How to be able to do so?

    Here is some code snippets:

    [Tree("duug-customers", "duug-customers-tree", "Customers")]
    [PluginController("DUUG")]
    public class CustomerTreeController : TreeController
    {
        private const string CustomerPrefix = "customer-";
    
        protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
        {
            // if not root, return all nodes
            if (id != Constants.System.Root.ToInvariantString()) throw new NotSupportedException();
    
            var nodes = new TreeNodeCollection();
            var ctrl = new CustomersController();
            var customerRoute = string.Format("{0}{1}/edit/", queryStrings.GetValue<string>("application"),
                this.TreeAlias.EnsureStartsWith('/'));
    
            nodes.AddRange(ctrl.GetAll().Select(customer => CreateTreeNode(string.Format("{0}{1}", CustomerPrefix, customer.Id.ToString(CultureInfo.InvariantCulture)), Constants.System.Root.ToInvariantString(), queryStrings, customer.Name, "icon-client", false, string.Format("{0}{1}", customerRoute, customer.Id))));
    
            return nodes;
        }
    }
    

    Any idea?

    Thanks

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 08, 2015 @ 11:12
    Dave Woestenborghs
    100

    Hi Bilal,

    This because you have only one tree in your section and you add all your items to that.

    Have a look at the source code here : https://bitbucket.org/dawoe/umbukfestival2014

    In this example I have 2 trees and you see the behavior you want.

    Dave

  • Bilal Haidar 144 posts 410 karma points
    May 08, 2015 @ 12:30
    Bilal Haidar
    0

    In fact, I added the following to get a root node:

    if (id == Constants.System.Root.ToInvariantString())
            {
                nodes.Add(CreateTreeNode("customersTree", Constants.System.Root.ToInvariantString(), queryStrings,
                    "Customers", "icon-folder", true));
            }
            else if (id == "customersTree")
            {
                var ctrl = new CustomersController();
                var customerRoute = string.Format("{0}{1}/edit/", queryStrings.GetValue<string>("application"),
                    this.TreeAlias.EnsureStartsWith('/'));
    
                nodes.AddRange(
                    ctrl.GetAll()
                        .Select(
                            customer =>
                                CreateTreeNode(
                                    string.Format("{0}{1}", CustomerPrefix,
                                        customer.Id.ToString(CultureInfo.InvariantCulture)),
                                    Constants.System.Root.ToInvariantString(), queryStrings, customer.Name,
                                    "icon-client", false, string.Format("{0}{1}", customerRoute, customer.Id))));
    
            }
    

    But now the thing is, where in Umbraco I would specify a view to be shown when the section is clicked? Like a landing page or so.

    Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies