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, 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.
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...
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!
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.
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.
{
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.
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
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
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.
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
BTW There allready is LogViewer Packages
http://packages.umbraco.org/packages/umbraco-utilities/logviewer?callback=&version=
http://www.gordonsaxby.me.uk/umbraco-stuff/log-viewer-for-umbraco-v3-and-v4-.aspx
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
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...
Hello,
Here are some more examples:
http://blog.sitereactor.dk/2009/04/26/google-analytics-for-umbraco-first-installment/
http://www.simm.dk/umbraco-corner/articles/making-custom-sections-and-trees-inside-umbraco---part-i.aspx
I used the first website as an example to create my own section.
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
@Richard
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
Glad to see my blogs are coming in handy for people :D
Hey guys,
Just one more question... how do I nest nodes in the tree?
/RasB
More info can be found at this topic:
http://our.umbraco.org/forum/developers/extending-umbraco/3080-Add-child-nodes-to-custom-Umbraco-section
You can also found info about it in the wiki:
http://our.umbraco.org/wiki/reference/api-cheatsheet/tree-api---to-create-custom-treesapplications
Never mind guys, I figured out that I had to use the
Took me a while to figure out how it worked.
/RasB
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.
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);
}
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.
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
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:
You need to distiguish between the different contexts when creating nodes. The context is available like this:
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
That's perfect, thanks.
folks.,
i have difficulty in loading the tree as per the above code..
the nodes are getting repeated. any pointers?
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
is working on a reply...