I'm playing around with creating custom sections and trees in Umbraco 7.2.
My section is working fine but for some reason I can't get my tree to show up - There are no errors messages in the browser console and nor are there any errors in the /app_data/logs file.
The full code for my tree class looks like the following
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;
using Umbraco.Web.Models.Trees;
using umbraco.BusinessLogic.Actions;
using System.Net.Http;
using System.Net.Http.Formatting;
using Umbraco.Core;
using umbraco;
namespace MyTree.Trees
{
[PluginController("Products")]
[Tree("Products", "productsTree", "Products", iconClosed: "icon-doc")]
public class SharewishAppTreeController : TreeController
{
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
// check if we're rendering the root node's children
if (id == Constants.System.Root.ToInvariantString())
{
// empty tree
var tree = new TreeNodeCollection();
// but if we wanted to add nodes -
return tree;
}
// this tree doesn't support rendering more than 1 level
throw new NotSupportedException();
}
protected override MenuItemCollection GetMenuForNode(string id, 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;
}
menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
return menu;
}
}
}
I have a 7.1.8 installation with a custom tree, and the code looks very similar to yours. There might of course be something specific to 7.2, but could you try the following htings:
What is the value of Constants.System.Root.ToInvariantString()? Should be -1.
What happens if you don't return an empty tree collection?
In GetTreeNodes, try writing something to the log right before your if-statement. If that works, we can take it from there ;)
Has your tree been added to /config/trees.config? If so, could you paste the line here?
I tried using the above code on a fresh installation on 7.1.8 - Now I see some of the tree but if I choose to right click I get this error message in the console log
No menuUrl property found on the tree node, cannot load menuangular.min.js:63 (anonymous function)angular.min.js:54 (anonymous function)angular.min.js:92 e.$applyumbraco.directives.js:2203 (anonymous function)jquery-2.0.3.min.js:10 x.event.dispatchjquery-2.0.3.min.js:10 y.handle
So surely something is wrong but I can't quite figure out what it is.
I'm not quite sure how to use the logger either :)
For now I just want to have my tree working and be able to see one single node listed in it.
My code looks a lot like yours. Also if I copy your example code and update GetTreeNodes method to add a node, it works fine in my 7.2 installation:
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) {
// check if we're rendering the root node's children
if (id == Constants.System.Root.ToInvariantString()) {
// empty tree
var tree = new TreeNodeCollection();
var node = CreateTreeNode("Hai", "-1", queryStrings, "Howdy");
tree.Add(node);
// but if we wanted to add nodes -
return tree;
}
// this tree doesn't support rendering more than 1 level
throw new NotSupportedException();
}
If that still doesn't work, can you try posting your applications.config and trees.config here? Just to make sure the aliases are right ;)
Regarding the log, you can call it this way. If the GetTreeNodes is called, you should be able to find Hellooooooooo? in the log file :
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) {
LogHelper.Info<SharewishAppTreeController>("Hellooooooooo?");
// check if we're rendering the root node's children
if (id == Constants.System.Root.ToInvariantString()) {
// empty tree
var tree = new TreeNodeCollection();
var node = CreateTreeNode("Hai", "-1", queryStrings, "Howdy");
tree.Add(node);
// but if we wanted to add nodes -
return tree;
}
// this tree doesn't support rendering more than 1 level
throw new NotSupportedException();
}
Ok...So it seems like I'm not allowed to call my TreeController none of these names
SharewishAppTreeController
ProductsTreeController
But if I name it "ProductItemsTreeController" then it works fine...which I'm not sure I quite understand.
This code works...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;
using Umbraco.Web.Models.Trees;
using umbraco.BusinessLogic.Actions;
using System.Net.Http;
using System.Net.Http.Formatting;
using Umbraco.Core;
using umbraco;
using Umbraco.Core.Logging;
namespace Sharewish.Trees.Trees
{
[PluginController("Products")]
[Tree("products", "ProductsTree", "Products")]
public class ProductItemsTreeController : TreeController
//SharewishAppTreeController
//ProductsTreeController
{
protected override Umbraco.Web.Models.Trees.TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
//check if we're rendering the root node's children
if (id == global::Umbraco.Core.Constants.System.Root.ToInvariantString())
{
var tree = new TreeNodeCollection
{
CreateTreeNode("1", id, queryStrings, "Products","icon-folder",true)
};
return tree;
}
//this tree doesn't suport rendering more than 1 level
throw new NotSupportedException();
}
protected override Umbraco.Web.Models.Trees.MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
menu.Items.Add(new MenuItem("create", "Create"));
return menu;
}
}
}
So what is the proper way to name the tree controller? Should it have the same name as the section application name/alias? Or should one be able to name it anything?
I think the important thing to notice that the alias of the application in your latest example is now products rather than Products in your first example. The alias is case-sensitive (which I why I suggested you to sent the contents of both applications.configand trees.config).
I had a similar problem and thanks to your comments, kind solved it but I still have some difficulties. On a test project that I created I was trying to add a new section with custom trees and after some time I managed it. But when I wanted to do the same on one of my current projects (for production) I wasn't very successful even though I followed the exact same steps.
At the beginning my tree wasn't showing up in the menu as in your case and then I manually added a new tree inside the section, and somehow ended up like this (1st image - test project; 2nd - production).
Can someone explain to me why on one project the tree is shown as a folder(as it supposed) and on the other it's shown as the root menu? Which isn't showing up if there are no child nodes inside the tree. Also I was using the same code in both projects.
[Tree("example", "peopleTree", "People")]
[PluginController("Example")]
public class PeopleTreeController: TreeController
{
protected override Umbraco.Web.Models.Trees.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 ctrl = new PersonApiController();
var nodes = new TreeNodeCollection();
foreach (var person in ctrl.GetAll())
{
var node = CreateTreeNode(
person.Id.ToString(),
"-1",
queryStrings,
person.ToString(),
"icon-user",
false);
nodes.Add(node);
}
return nodes;
}
//this tree doesn't suport rendering more than 1 level
throw new NotSupportedException();
}
protected override Umbraco.Web.Models.Trees.MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
if (id == Constants.System.Root.ToInvariantString())
{
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
{
//menu.DefaultMenuAlias = ActionDelete.Instance.Alias;
menu.Items.Add< ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
}
return menu;
}
}
Just to confirm, I tested with a custom tree in 7.1.9, 7.2.0 and 7.2.1. As you point out, the behavior has changed from 7.2.0.
With only a very quick glance through the list of commits, I can't find anything mentioning this change, and therefore also not whether this was an intentional change. I haven't tested the create action, but it makes sense to show the sections because of this.
You can try either pinging Sebastiaan on Twitter, or just create an issue right away, and someone who knows why it was changed, will hopefully have a look at it ;)
Just to chime in - I think there should be created an issue for this. Even though Sebastiaan is good at answering at Twitter etc. I think it can also be pretty stressful for the guys sometimes and since it's something that concerns all who may be creating custom sections and trees it's better to file the issue so everyone can see it and the HQ guys can handle it.
Custom tree in Umbraco 7.2 not showing up
Hi guys
I'm playing around with creating custom sections and trees in Umbraco 7.2.
My section is working fine but for some reason I can't get my tree to show up - There are no errors messages in the browser console and nor are there any errors in the /app_data/logs file.
The full code for my tree class looks like the following
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using Umbraco.Web.Mvc; using Umbraco.Web.Trees; using Umbraco.Web.Models.Trees; using umbraco.BusinessLogic.Actions; using System.Net.Http; using System.Net.Http.Formatting; using Umbraco.Core; using umbraco;
What am I doing wrong?
Cheers, Jan
I have a 7.1.8 installation with a custom tree, and the code looks very similar to yours. There might of course be something specific to 7.2, but could you try the following htings:
Constants.System.Root.ToInvariantString()
? Should be-1
.Hi Anders
May I have a peak at your code?
I tried using the above code on a fresh installation on 7.1.8 - Now I see some of the tree but if I choose to right click I get this error message in the console log
No menuUrl property found on the tree node, cannot load menuangular.min.js:63 (anonymous function)angular.min.js:54 (anonymous function)angular.min.js:92 e.$applyumbraco.directives.js:2203 (anonymous function)jquery-2.0.3.min.js:10 x.event.dispatchjquery-2.0.3.min.js:10 y.handle
So surely something is wrong but I can't quite figure out what it is.
I'm not quite sure how to use the logger either :)
For now I just want to have my tree working and be able to see one single node listed in it.
Cheers, Jan
My code looks a lot like yours. Also if I copy your example code and update GetTreeNodes method to add a node, it works fine in my 7.2 installation:
If that still doesn't work, can you try posting your
applications.config
andtrees.config
here? Just to make sure the aliases are right ;)Regarding the log, you can call it this way. If the GetTreeNodes is called, you should be able to find
Hellooooooooo?
in the log file :Hi Anders
So finally came back from a birthday brunch so I can see if I can succeed with adding that tree this evening :)
The text does not appear in the log file and my trees.config looks like this, which seems right to me
But perhaps my override is wrong somehow since it seems that nothing is ever logged?
/Jan
Hi Anders
Ok...So it seems like I'm not allowed to call my TreeController none of these names
But if I name it "ProductItemsTreeController" then it works fine...which I'm not sure I quite understand.
This code works...
So what is the proper way to name the tree controller? Should it have the same name as the section application name/alias? Or should one be able to name it anything?
/Jan
I think the important thing to notice that the alias of the application in your latest example is now
products
rather thanProducts
in your first example. The alias is case-sensitive (which I why I suggested you to sent the contents of bothapplications.config
andtrees.config
).Below is the contents of my config files:
applications.config
trees.config
Also notice, that if you switch between
products
andProducts
in your code,trees.config
might not necessarily be updated.Hi Anders
Thank you very much for clearing that up. Such a tiny thing that took me so long to figure out :D
It's working now and I've learned something new, which is always nice.
I should probably do a write-up so I don't forget this again.
/Jan
hello everyone,
I had a similar problem and thanks to your comments, kind solved it but I still have some difficulties. On a test project that I created I was trying to add a new section with custom trees and after some time I managed it. But when I wanted to do the same on one of my current projects (for production) I wasn't very successful even though I followed the exact same steps.
At the beginning my tree wasn't showing up in the menu as in your case and then I manually added a new tree inside the section, and somehow ended up like this (1st image - test project; 2nd - production).
Can someone explain to me why on one project the tree is shown as a folder(as it supposed) and on the other it's shown as the root menu? Which isn't showing up if there are no child nodes inside the tree. Also I was using the same code in both projects.
Hi Jan and Anders,
do you know if anything has changed in 7.2.0? I have created a package with a custom section. This works great in 7.1.6, 7.1.7, 7.1.8 and 7.1.9.
But in 7.2.0 and 7.2.1 the custom tree is not showing.
Any ideas?
Best
Sören
Here more informations:
applications.config:
trees.config:
Code:
Best
Sören
It should be look like this (works in 7.1.6 - 7.1.9):
But in 7.2.0 and 7.2.1 I see only this:
No error in console. No error in umbraco log.
Any ideas?
Sören
Ok, I have found the cause. It seems to happen when there is no node in the custom tree!
If I update my code in GetTreeNodes function to this it works:
But I think it must be possible to see the section correctly with no nodes in custom tree. The solution above is not the perfect solution.
Before 7.2.0 I can right click to "MAILBOXES" and can create with "create" in context menu the root items for this custom tree without problems.
Is this an issue in 7.2.0 and 7.2.1?
Sören
Just to confirm, I tested with a custom tree in 7.1.9, 7.2.0 and 7.2.1. As you point out, the behavior has changed from 7.2.0.
With only a very quick glance through the list of commits, I can't find anything mentioning this change, and therefore also not whether this was an intentional change. I haven't tested the create action, but it makes sense to show the sections because of this.
You can try either pinging Sebastiaan on Twitter, or just create an issue right away, and someone who knows why it was changed, will hopefully have a look at it ;)
Hi guys
Just to chime in - I think there should be created an issue for this. Even though Sebastiaan is good at answering at Twitter etc. I think it can also be pretty stressful for the guys sometimes and since it's something that concerns all who may be creating custom sections and trees it's better to file the issue so everyone can see it and the HQ guys can handle it.
Just my 2 cents :)
/Jan
Great! Thank you for feedback! I have create an issue, you can vote for it here:
http://issues.umbraco.org/issue/U4-6168
Best,
Sören
I am completely new to coding but, hope so I will learn soon. :) Thanks
is working on a reply...