Does anybody knows how to pass a node type in a tree?
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings){
var nodes = new TreeNodeCollection();
if (id == Constants.System.Root.ToInvariantString())
{
var level1 = CreateTreeNode(id, id, queryStrings, "Level1", "icon-folder-close", true);
level1.NodeType = "level1";
nodes.Add(level1);
}
else
{
//how can i get the nodetype here so i can create nodes by there nodetype
}
return nodes
}
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings){
var menu = new MenuItemCollection();
if (id == Constants.System.Root.ToInvariantString())
{
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
menu.Items.Add<ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
}
else
{
// and also here how can i get the node type to make the menu based on a nodetype
}
}
Yes i have read the documentation, but there never been a word on multi level trees.. Only 1 level, i am currently working on a way thats use one table of nodes with a nodetype set in it and zo i can have multiple levels with different types.. But it would be nice that i can be done in de treecontroller..
If you can't find it in the documentation it might be a good idea to look into the v7 source code. There are some multilevel trees in Umbraco itself so you can probably find how it's done.
I can't really use the id to work out the nodetype as I have certain nodes that could have a variety of node types as children. All the ID really tells me is where it is located on the tree, not the type of node it is.
I've looked in what passes for the documentation and seen nothing in there. I've also looked in the code and it doesn't seem as if they are passing any node information to getmenufornode at all.
I have also search a solution for a multi level tree in a custom section. But all solutions and snippets that I found was about 1 or 2 level trees. I have not found the solution to check the nodetyp, but I have found another solution to handle this with the nodelevel. I can check the nodelevel with the special custom string id. Here is my complete code:
[Umbraco.Web.Trees.Tree("mhTicketsystem", "mhTicketsystemTree", "Ticketsystem" )]
[PluginController("mhTicketsystem")]
public class tsTreeController : TreeController
{
protected override TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
//check if we're rendering the root node's children
if (id == Constants.System.Root.ToInvariantString())
{
var nodes = new TreeNodeCollection();
var ticketsystemApi = new TicketsystemApiController();
IEnumerable<Ticketsystem> ticketsystemList = ticketsystemApi.GetAll();
if (ticketsystemList != null)
{
if (ticketsystemList.Count() != 0)
{
foreach (var ticketsystem in ticketsystemList)
{
var node = CreateTreeNode(
ticketsystem.Id.ToString(),
"-1",
queryStrings,
ticketsystem.Name,
"icon-ticket",
true);
nodes.Add(node);
}
}
else
{
var node = CreateTreeNode(
"-1",
"-1",
queryStrings,
"First create a Ticketsystem, please",
"icon-home",
false);
nodes.Add(node);
}
return nodes;
}
}
else
{
int level = id.Count(c => c == '-');
switch (level)
{
case 0:
return GetChildTreeNodesTicketsystem(id, queryStrings);
case 1:
if (id.Contains("settings"))
{
return GetChildTreeNodesSettings(id, queryStrings);
} else if (id.Contains("tickets"))
{
return GetChildTreeNodesTickets(id, queryStrings);
}
break;
case 2:
return GetChildTreeNodesCompany(id, queryStrings);
}
}
throw new NotSupportedException();
}
private TreeNodeCollection GetChildTreeNodesTickets(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection {
CreateTreeNode("tickets-create" + id.Substring(id.IndexOf('-')), id, queryStrings, "Create", "icon-company", false),
CreateTreeNode("tickets-reports" + id.Substring(id.IndexOf('-')), id, queryStrings, "Reports", "icon-company", false)
};
return nodes;
}
protected TreeNodeCollection GetChildTreeNodesTicketsystem(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection {
CreateTreeNode("settings-" + id, id, queryStrings, "Settings", "icon-settings", true, "mhTicketsystem/mhTicketsystemTree/settings/1"),
CreateTreeNode("tickets-" + id, id, queryStrings,"Tickets","icon-document",true)
};
return nodes;
}
protected TreeNodeCollection GetChildTreeNodesSettings (string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection {
CreateTreeNode("settings-company" + id.Substring(id.IndexOf('-')), id, queryStrings, "Company", "icon-company", true, "mhTicketsystem/mhTicketsystemTree/company/1")
};
return nodes;
}
protected TreeNodeCollection GetChildTreeNodesCompany(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection
{
CreateTreeNode("settings-company-Departments" + id.Substring(id.LastIndexOf('-')), id, queryStrings, "Departments", "icon-library", false, "mhTicketsystem/mhTicketsystemTree/company_department/1"),
CreateTreeNode("settings-company-Employees" + id.Substring(id.LastIndexOf('-')), id, queryStrings, "Employees", "icon-male-and-female", false, "mhTicketsystem/mhTicketsystemTree/company_employee/1")
};
return nodes;
}
protected override MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
if (id == Constants.System.Root.ToInvariantString())
{
// root actions
menu.Items.Add<CreateChildEntity, ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);
return menu;
}
else if (!id.Contains('-'))
{
menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
}
return menu;
}
}
I hope this helps everyone with the same requirements for a multilevel tree ;-)
Custom Multilevel tree
Hello,
Does anybody knows how to pass a node type in a tree?
Did you already read this documentation? http://umbraco.github.io/Belle/#/tutorials/Creating-Editors-Trees
Jeroen
Yes i have read the documentation, but there never been a word on multi level trees.. Only 1 level, i am currently working on a way thats use one table of nodes with a nodetype set in it and zo i can have multiple levels with different types.. But it would be nice that i can be done in de treecontroller..
If you can't find it in the documentation it might be a good idea to look into the v7 source code. There are some multilevel trees in Umbraco itself so you can probably find how it's done.
Jeroen
The GetTreeNodes method has an id as first parameter. You can check this id to see which nodes you have to return.
You can set this id as the first parameter on the CreateTreeNode-method
Did anyone find a solution for this in the end?
I can't really use the id to work out the nodetype as I have certain nodes that could have a variety of node types as children. All the ID really tells me is where it is located on the tree, not the type of node it is.
I've looked in what passes for the documentation and seen nothing in there. I've also looked in the code and it doesn't seem as if they are passing any node information to getmenufornode at all.
Hi all,
I have also search a solution for a multi level tree in a custom section. But all solutions and snippets that I found was about 1 or 2 level trees. I have not found the solution to check the nodetyp, but I have found another solution to handle this with the nodelevel. I can check the nodelevel with the special custom string id. Here is my complete code:
I hope this helps everyone with the same requirements for a multilevel tree ;-)
Cheers, Sören
@Sören, way too little information on multi level trees in umbraco, your post gave that hint needed to know how to do it!
Hi Ian,
thanks for the feedback :-)
is working on a reply...