Copied to clipboard

Flag this post as spam?

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


  • rasb 162 posts 218 karma points
    Jul 23, 2009 @ 00:39
    rasb
    0

    Custom section in Dashboard

    Hi guys,

    I am trying to create a new custom section in the dashboard, in order to easily view some logfiles, that are important to the website administrators. 

    I have created the section and gotten a tree drawn by following this guide:

    http://our.umbraco.org/wiki/reference/api-cheatsheet/tree-api---to-create-custom-treesapplications

    So far so good...

    I also have a UserControl that can display the logs for me, but what I can't find anywhere is how to render that UserControl in the content window, and how do I pass parameters from the tree to that user control. 

    Thanks,
    RasB

    Umbraco 4.0.2.1
    .Net 3.5
    IIS 6
    Windows 2003

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 23, 2009 @ 01:12
    Aaron Powell
    0

    Do you want it to be a dashboard item, ie - shown when you click the root node in your application, or an item you select from the tree?

    For the former you need to add the user control do the dashboard.config file (in the /config folder) but you can't pass parameters.

    Otherwise you need to have the action of the tree item you want load the ASPX which the user control.

  • rasb 162 posts 218 karma points
    Jul 23, 2009 @ 08:00
    rasb
    0

    Hi Slace,

    It is the later, I want to set the action for the tree node. I have found out how to that as well. I can see that in the document as well. 

    But what I haven't found out is where do I put the UserControl so i can use it? What URL should I tell the browser to get?

    /RasB

  • Petr Snobelt 923 posts 1535 karma points
    Jul 23, 2009 @ 08:16
  • rasb 162 posts 218 karma points
    Jul 23, 2009 @ 08:22
    rasb
    0

    Hi Petr,

    Thanks, that looks cool, but not exactly what I am looking for. These are a specific kind of logs, and I need to interact with the logs in a specific way.

    /RasB

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Jul 23, 2009 @ 08:38
    Richard Soeteman
    100

    Hi Rasb,

     

    You need to add your own aspx page that that contains your usercontrol and stor it in the /umbraco/settings folder . Then create a custom tree like described in  Simple Tree Example (loadLanguages) and change the aspx page used in their with your own page.

    Then you have to update the umbracoAppTree database table. I cannot find a really good article that describes what to do here, but basically copy and paste a record and change the columsn appAlias to the alias of your custom section, TreeAlias to something unique for your tree and TreeHandlerAssemby and TreeHandlerType to the assembly and type you are using.

    Hope it helps you,

    Richard

    btw Agree with Petr that there is already a logviewer package... 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 23, 2009 @ 08:44
  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 23, 2009 @ 08:50
    Aaron Powell
    1

    I have some source code in this post which also shows how to do custom trees (but it's Umbraco 4.1 preview based) http://www.aaron-powell.com/blog/july-2009/creating-custom-dataproviders-for-linq-to-umbraco.aspx

    You need to set the Action property of the XmlTreeNode object you're putting into your tree

  • rasb 162 posts 218 karma points
    Jul 23, 2009 @ 09:14
    rasb
    0

    @Richard

    You need to add your own aspx page that that contains your usercontrol and stor it in the /umbraco/settings folder .

    Thanks, that was exactly what I was looking for! That one line really needs to be in that Wiki article. I thought I had to use a macro, like I do when I use User Controls on the public site.

    @Jeroen

    Yes I had a look at those articles yesterday. Realle good, and got me very far.

    @slace

    Thanks, have used that blog entry as well. But I was looking for that one piece of information that Richard gave me.

    Thanks guys! Love the speed at which people reply with here!

    /RasB

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 23, 2009 @ 10:19
    Aaron Powell
    0

    Glad to see my blogs are coming in handy for people :D

  • rasb 162 posts 218 karma points
    Jul 23, 2009 @ 12:01
    rasb
    0

    Hey guys,

    Just one more question... how do I nest nodes in the tree?

    /RasB

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 23, 2009 @ 12:08
  • rasb 162 posts 218 karma points
    Jul 23, 2009 @ 12:29
    rasb
    0

    Never mind guys, I figured out that I had to use the 

    xNode.Source

    Took me a while to figure out how it worked.

    /RasB

  • Ross Allan 3 posts 21 karma points
    Jul 30, 2009 @ 20:52
    Ross Allan
    0

    Any chance someone could post a small snippet of code demonstrating adding child nodes?

    I've currently got a hard coded tree:

    - test 1
    - test 2

    But I want:

    - test 1
      - test 1.1
      - test 1.2
    - test 2

    I've read the articles mentioned above but i'm not getting anywhere. I tried playing around with xNode.source =  this.getTreeServiceUrl() setting the id to either the parent or the child id but all I get is the tree recursing infinitely.

    I'm probably missing something obvious, any help is much appreciated.

  • Ross Allan 3 posts 21 karma points
    Jul 30, 2009 @ 21:06
    Ross Allan
    0

    This is roughly my current code (I'm at home so this is from memory)

    public override void Render(ref XmlTree tree)
    {
                    XmlTreeNode xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = "0";
                    xNode.Text = "Test 1";
                    xNode.Action = "javascript:openTest("0");";
                    xNode.Icon = "folder.gif";
                    xNode.OpenIcon = "folder_o.gif";
                    tree.Add(xNode);

                    XmlTreeNode xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = "1";
                    xNode.Text = "Test 2";
                    xNode.Action = "javascript:openTest("1");";
                    xNode.Icon = "folder.gif";
                    xNode.OpenIcon = "folder_o.gif";
                    tree.Add(xNode);

                    //This should be a child of Test 1
                    XmlTreeNode xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = "3";
                    xNode.Text = "Test 1.1";
                    xNode.Action = "javascript:openTest("3");";
                    xNode.Icon = "folder.gif";
                    xNode.OpenIcon = "folder_o.gif";
                    tree.Add(xNode);

    }

  • rasb 162 posts 218 karma points
    Jul 31, 2009 @ 00:02
    rasb
    2

    Hi Ross,

    Sorry about that... I really should have posted my code when I found the solution. I just didn't really have the time, so I decided to just post the little clue.

     

    xNode.Source

    The trick as far as I have figured it out (wasn't able to find much documentation on this, so I did a lot of debugging to figure it out) is that the the method

    public override void Render(ref XmlTree tree) {...}

    Is called sort of recursively. But only sort of. The method is called in a context, and that context is a node with an id. The tree isn't actually built until a user tries to expand it, and at that point the Render method is called again, and this time in the context of the node you are trying to expand.

    As you have already seen with your code it creates three nodes on the same level instead of nesting them. You need to tell the tree that the node has children and what the context is. You this like this:

    //The node has children
    xNode.HasChildren = true;
    //The context of the children is this node.
    xNode.Source = this.GetTreeServiceUrl(xNode.NodeID);

    You need to distiguish between the different contexts when creating nodes. The context is available like this:

    //This is the context supplied by setting the xNode.Source property
    this.id

    In the simplest form this is just a conditional statement like if. So a very simpe example that holds the three nodes you have posted would be:

    public override void Render(ref XmlTree tree)
    {

    if (this.id == -1) //When the context is -1, the nodes are added to the top level. {

    //First node                 XmlTreeNode xNode = XmlTreeNode.Create(this);                 xNode.NodeID = "0";                 xNode.Text = "Test 1";                 xNode.Action = "javascript:openTest("0");";                 xNode.Icon = "folder.gif";                 xNode.OpenIcon = "folder_o.gif";                 tree.Add(xNode);

    //Second node                 xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = "1";
                    xNode.Text = "Test 2";
                    xNode.Action = "javascript:openTest("1");";
                    xNode.Icon = "folder.gif";
                    xNode.OpenIcon = "folder_o.gif"; xNode.HasChilden = true; xNode.Source = this.GetTreeServiceUrl(xNode.NodeID);
                    tree.Add(xNode);

    } else if (this.id == 1) // The second node has NodeId 1, so that's what we'll check for. {

                    XmlTreeNode xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = "3";
                    xNode.Text = "Test 1.1";
                    xNode.Action = "javascript:openTest("3");";
                    xNode.Icon = "folder.gif";
                    xNode.OpenIcon = "folder_o.gif";
                    tree.Add(xNode); } }

     

     

    Hmmm... I can't see, to get out of this preformatted style. But I am also done. This can of course be done much more sophisticated and generic, but I hope you get the idea.

    /RasB

  • Ross Allan 3 posts 21 karma points
    Jul 31, 2009 @ 09:58
    Ross Allan
    0

    That's perfect, thanks.

  • Sa 118 posts 152 karma points
    Oct 21, 2009 @ 12:45
    Sa
    0

    folks.,

    i have difficulty in loading the tree as per the above code..

    the nodes are getting repeated. any pointers?

  • greengiant83 88 posts 109 karma points
    Mar 30, 2011 @ 22:58
    greengiant83
    0

    The code provided does load the first two recursively.  It seems that xNode.NodeID is irrelevant.  If instead of calling this.GetTreeServiceUrl with a string id, it needs to be called with an integer id instead, which will get passed back as this.id when its children are loaded.  Atleast this is the case in version 4.6.1

     

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft