Copied to clipboard

Flag this post as spam?

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


  • Bo Jacobsen 608 posts 2406 karma points
    Aug 24, 2017 @ 20:36
    Bo Jacobsen
    0

    Custom section tree node route path takes from view folder

    Hi all.

    Using Umbraco 7.6.5

    I am playing around with Custom Sections, and are stuck trying to set the route path.

    if i set the route path to myCustomSection/settings/edit/1 it will try and take the edit.html from /View/settings/edit.html, how can i change it to take from /App_Plugins/MyPlugin/backoffice/settings/edit.html ?

    Here is an exsampel.

    // Let's say my tree alias is Parent.
    protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
    {
        if (id == "-1")
        {
            var rootNodes = new TreeNodeCollection();
    
            // This one takes the view correct at /App_Plugins/MyPlugin/backoffice/parent/edit.html
            var folder = CreateTreeNode("0", "-1", queryStrings, "Parent", "icon-truck color-blue", true);
            rootNodes.Add(folder);
    
            return rootNodes;
        }
        else
        {
            switch (id)
            {
                case "0":
                    var childNodes = new TreeNodeCollection();
    
                    // This one trying to get /View/settings/edit.html
                    var settings = CreateTreeNode("1", "0", queryStrings, "Settings", "icon-settings-alt color-blue", false, "myCustomSection/settings/edit/1");
                    childNodes.Add(settings);
    
                    // This one trying to get /View/child/edit.html
                    var anotherChild = CreateTreeNode("1", "0", queryStrings, "anotherChild", "icon-untitled color-blue", false, "myCustomSection/child/edit/1");                
                    childNodes.Add(anotherChild);
    
                    return childNodes;
            }
        }
    
        //this tree doesn't suport rendering any more levels
        throw new NotSupportedException();
    }
    

    Any help is appreciated.

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Aug 24, 2017 @ 21:39
    Kevin Jump
    101

    Hi

    the routes have to match both the appAlias and tree alias to be found. if they don't then umbraco goes back into looking in the views folder.

    so if for example you have a tree controller with

    [Tree("cutomSection", "customTree", "Tree Name")]
    

    all your views will need to be in the form

    "customSection/customTree/{view}/{id}"
    

    and your views will need to match

    /App_Plugins/customSection/backoffice/customTree/view.html
    
  • Bo Jacobsen 608 posts 2406 karma points
    Aug 25, 2017 @ 15:24
    Bo Jacobsen
    0

    Hi Kevin.

    Thanks for answering.

    So what you are saying is that my route for settings should be myCustomSection/CustomTree/settings/1 and for the other child it should be myCustomSection/CustomTree/child/1.

    What about delete and add? How would you then add those?

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Aug 25, 2017 @ 18:47
    Kevin Jump
    0

    HI

    for children in the path they go on the end . with the action the thing after the tree.

    so if we assume the node id of the child node is 1 then

    myCustomSection/Customtree/settings/1 
    

    would point to.

    /app_plugins/myCustomSection/backoffice/CustomTree/settings.html
    

    and

    myCustomSection/CustomTree/edit/1 
    

    points to

    .../backoffice/customtree/edit.html 
    

    similar for delete etc...

    myCustomSection/CustomTree/delete/1 
    myCustomSection/CustomTree/add/1 
    
    ...../backoffice/customtree/delete.html
    ...../backoffice/customtree/add.html
    

    to get the id at the end you can access $routeParams.id in your angular controller for each element.

    It doesn't really matter how deep your tree gets what you have to do is still point to the items in the root of the customtree folder. and pass in the ID of the item in the tree as the final parameter.

  • Bo Jacobsen 608 posts 2406 karma points
    Aug 26, 2017 @ 19:45
    Bo Jacobsen
    0

    Hi

    I am still confused, i hope you can bear with me.

    What i get from this is i could use the Edit/Add/Delete for one node type. Actually i think Edit is also used for Add.

    But what about other node types in the same tree?

    Let's say, i got 2 different node types.

    First nodetype i use: (works)

    Route = myCustomSection/Customtree/edit/1
    View= /app_plugins/myCustomSection/backoffice/CustomTree/edit.html
    
    // Menu        
    var menu = new MenuItemCollection();
    
    // /app_plugins/myCustomSection/backoffice/CustomTree/edit.html
    menu.Items.Add<CreateChildEntity, ActionNew>("Create new");
    
    // /app_plugins/myCustomSection/backoffice/CustomTree/delete.html
    menu.Items.Add<ActionDelete>("Delete"); 
    
    return menu;
    

    Second nodetype: (I dunno what to do)

    // This part works.
    Route = myCustomSection/Customtree/settings/1
    View= /app_plugins/myCustomSection/backoffice/CustomTree/settings.html
    
    // Menu (this part do no not work)       
    var menu = new MenuItemCollection();
    
    // How do i tell it to take from settings.html?
    menu.Items.Add<CreateChildEntity, ActionNew>("Create new");
    
    // How do i tell it to take from settings_delete.html?
    menu.Items.Add<ActionDelete>("Delete"); 
    
    return menu;
    

    My confusing point is how to set the settings nodetype Create and Delete route. i guess i need to make a settings_delete.html, but i dunno where i can tell it to take from that view and how to tell it to create from settings.html, when another nodetype already are using edit and delete.

    Maybe i have to make my own IAction, but i can't get it to work.

    public class SettingsCreateAction : IAction
    {
        public char Letter
        {
            get { return default(char); }
        }
    
        public bool ShowInNotifier
        {
            get { return false; }
        }
    
        public bool CanBePermissionAssigned
        {
            get { return false; }
        }
    
        public string Icon
        {
            get { return "icon-settings"; }
        }
    
        public string Alias
        {
            get { return "settings"; }
        }
    
        public string JsFunctionName
        {
            get { return ""; }
        }
    
        public string JsSource
        {
            get { return ""; }
        }
    
    }
    

    I hope it make sense :)

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Aug 27, 2017 @ 08:49
    Kevin Jump
    1

    Hi

    you can create menu items with an alias and name :

    var deleteItem= new MenuItem("setttingDelete", "Delete");
    menu.Items.add(deleteItem);
    

    so that would go to

    /app_plugins/...../CustomTree/settingsDelete.html
    

    you might need to set the icon and stuff this way, but you can access the menuitem properties, such as icon now - so you can do that.

  • Bo Jacobsen 608 posts 2406 karma points
    Aug 27, 2017 @ 14:40
    Bo Jacobsen
    0

    Thanks Kevin.

    That got me going :)

  • Daniel 9 posts 80 karma points
    Oct 18, 2017 @ 10:04
    Daniel
    0

    So, from what I got, a section tree is used for CRUD operations for an entity. However, there is no way to:

    • write a custom Angular UI route which allows you to have /{plugin}/{sectionAliasWhichDoesNotHaveATreeController}/{action}
    • add a tree controller to bypass this limit, but to remove it when this is rendered (the root node)
    • write a custom Angular UI route which allows you to have: /{plugin}/{sectionWhichHasATree}/{somethingElse}/{action}

    It's bad, since I've spent around 3 days in figure it out that this is a limitation and can not pass.

    I am not an expert in Umbraco, but can anyone tell me that I am wrong ?

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Oct 18, 2017 @ 10:44
    Kevin Jump
    0

    Hi

    As far as i know you can't do it with your own controllers :(

    Umbraco will look for the tree/section alias, and if it doesn't exist everything goes back into the umbraco/views folder (which I would avoid putting anything into as you will get upgrade nightmares).

    So you need to have everything in the same folder.

    In the past i have just prefixed the filenames with the entity so for example :

    /personEdit.html
    /personDelete.html
    /companyEdit.html
    /companyDelete/html
    

    and then the routes are like:

    /mysection/mytree/personEdit/1093
    /mysection/mytree/personDelete/1031
    /mysection/mytree/companyEdit/12
    /mysection/mytree/companyDelete/113
    

    it's not ideal - but i suppose the only other way to do it, is have a separate tree for each type which is good in terms of separation of code but this only works if the entities are not mixed in the structure of your tree.

  • Daniel 9 posts 80 karma points
    Oct 18, 2017 @ 13:36
    Daniel
    1

    Adding a section tree for each entity is ideal, in order to route properly. However, this is annoying because each TreeController will appear in the plugin tree.

    Even I want to exist a single entity named A, I couldn't find a method to erase root nodes (which they correspond to each Tree Controllers defined).

    Do you know if is there such a capacity ?

  • Hryhorii 11 posts 132 karma points
    Mar 09, 2018 @ 12:33
    Hryhorii
    0

    Hi I think I made how writed in this post, but still get request from umbraco/views

    My Controller

     [Tree("cutomSection", "customTree", "Tree Name")]
    [PluginController("cutomSection")]
    public class CategorySEOController : TreeController
    {
        protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
        {
            var nodes = new TreeNodeCollection();
    
            if (id == "-1") nodes.Add(CreateTreeNode("1", id, queryStrings, "Categories", "traycontent", false, "customSection/customTree/view"));
    
            return nodes;
        }
    
        protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
        {
            var menu = new MenuItemCollection();
            menu.Items.Add(new MenuItem("create", "Create"));
    
            return menu;
        }
    }
    

    html

    enter image description here

    Where is wrong?

  • Baha Al Fataftah 4 posts 75 karma points
    May 04, 2018 @ 13:20
    Baha Al Fataftah
    1

    add "/1" to the end of your custom route like this

    nodes.Add(CreateTreeNode("1", id, queryStrings, "Categories", "traycontent", false, "customSection/customTree/view/1"));
    
Please Sign in or register to post replies

Write your reply to:

Draft