INodeManipulator - trouble with submenus and depth property

Sep 28, 2012 at 9:25 AM

Hi,

Is there a reason why the Depth,First and last  properties for the MenuNode are read only? 

public int Depth { get ; }
public bool First { get ; }
public bool Last { get ; }

 I understand that you can pick these up from the node structure passed via the return of the "ManipulateNodes" function (My first thought was this is how it's done), but the depth doesn;t seem to be working.  I don't have any submenus, despite creating the required Children nodes and because I can't set the depth means a depth of "0" is created for these node....so I'm assuming this is the reason for the submenus not displaying.   Of course, does this mean the same happens for the first and last properties?

Are there any examples of the INodeManipulator in action, I basically want to use DDRMenu for the new version of NB_Store, but this is causing an issue with that.  I've tried to create the structure with an XML file and it all works OK.  Unfortunatly I can't do it like that, becuase I need to set the Selected to true or false in real time and writeing a file for each possible user is a no go!

Any advice is welcome.....in the meantime I'll continue looking, to see if there is something I've missed?

Regards,

Dave.

 

Sep 28, 2012 at 9:58 AM

OK got it, sorry.

Had to start looking at code...I hate that :-)....I needed to pass the parent node into the children.

For anyone struggling with this here what I've managed to get working as a recursive function...although you'll have to change anything according to your needs and database structure...

        private List<MenuNode> GetCatNodeXml(string parentItemId = "0", bool recursive = true, int depth = 0, MenuNode pnode = null)
        {
           
            var objCtrl = new NBrightGenController();
            var strFilter = " and (ParentItemId = " + parentItemId + " and typecode = 'CATEGORY') ";
            var strOrderBy = " order by [XMLData].value('(genxml/hidden/sortorder)[1]','nvarchar(10)'),[XMLData].value('(genxml/lang/genxml/textbox/txtname)[1]','nvarchar(50)') ";
            var nodes = new List<MenuNode>();

            var l = objCtrl.GetListWithLang(PortalSettings.Current.PortalId, -1, "CATEGORY", strFilter, strOrderBy, 0, 0, 0, 0, "CATEGORYLANG", "");

            var lp = 0;
            foreach (var obj in l)
            {
                var n = new MenuNode();

                n.Parent = pnode;

                n.TabId = obj.ItemID;
                n.Text = obj.GetXmlProperty("genxml/lang/genxml/textbox/txtname");
                n.Title = obj.GetXmlProperty("genxml/lang/genxml/textbox/txtsummary");
                n.Url = "?catid=" + obj.ItemID.ToString("");
                if (obj.GUIDKey != "")
                {
                    var objLang = objCtrl.GetInfoLang(PortalSettings.Current.PortalId, obj.ModuleId, obj.ItemID.ToString(""), NBrightCore.common.Utils.GetCurrentCulture(),"CATEGORYLANG");
                    if (objLang.GUIDKey != "")
                    {
                        n.Url = "?category=" + objLang.GUIDKey;                       
                    }
                }
                n.Enabled = true;
                if (obj.GetXmlProperty("genxml/checkbox/chkenabled").ToLower() == "false") n.Enabled = false;
                n.Selected = false;
                if ((_catid == obj.ItemID.ToString("")) | (_catguidkey == obj.GUIDKey)) n.Selected = true;
                n.Breadcrumb = false;
                n.Separator = false;
                n.LargeImage = obj.GetXmlProperty("genxml/hidden/fup1");
                n.Icon = obj.GetXmlProperty("genxml/hidden/fup1");
                n.Keywords = obj.GetXmlProperty("genxml/lang/genxml/textbox/txtkeywords");
                n.Description = obj.GetXmlProperty("genxml/lang/genxml/textbox/txtdescription");
                n.CommandName = "";
                //n.CommandArgument = string.Format("entrycount={0}|moduleid={1}", obj.GetXmlProperty("genxml/hidden/entrycount"), obj.ModuleId.ToString(""));

                if (recursive && depth < 10) //stop infinate loop, only allow 10 sub levels
                {
                    depth += 1;
                    var childrenNodes = GetCatNodeXml(obj.ItemID.ToString(""), true, depth, n);
                    if (childrenNodes.Count > 0)
                    {
                        n.Children = childrenNodes;
                    }
                }

                nodes.Add(n);


            }

            return nodes;

        }