Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 430 posts 1023 karma points
    Sep 02, 2017 @ 11:12
    Ayo Adesina
    0

    How to orgainise Anguar Views for Custom Tree Nodes and Menu Actions

    I have a pretty complex custom tree and I am in the process of adding alll the menus and views so the Umbraco user can edit data in my custom db. When creating the menus for each node in my tree I needed to work out how to tell Umbraco which view to use when creating a new item in the tree.

    I found this solution (here: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/71957-edit-page-for-custom-section-menu-item) which works:

    MenuItem mi = new MenuItem( "productcategories-edit", "New product category" );
     mi.Icon = "icon icon-add";
     menu.Items.Add( mi );
    

    productcategories-edit.html being the name of the view umbraco will look for.

    But one thing I don't understand is - From a few other examples I have seen, this is how people add a Create action....

            var menu = new MenuItemCollection();
            if (id == Constants.System.Root.ToInvariantString())
            {
                 menu.Items.Add<ActionNew>("Create");
                 return menu;
            }
    

    In this example we have got this 'ActionNew' object the VS tool tip says 'This action is invoked when upon the creation of a new document'

    But adding menu Items in this manner does not allow you to change the name of the view that umbraco looks for. So what exactly is this ActionNew object for?

    In my case, I am not creating a document in Umbraco - but inside a custom db.

    Should I still be using ActionNew some how? and if so how would I change the name of the view Umbraco looks for. (I have a complex tree with many nodes, I need to be able to create mulitiple views with diffrent names)

    It looks like umbraco has a convension for finding views just like Robert Foster explained here: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/71957-edit-page-for-custom-section-menu-item, but from what I can see so far there is no real way to organise your views in a logical folder structure, every thing needs to be in one directory.

    So you end up with files like EditCompany.html EditStudent.html then CreateStudent.html and CreateCompany.html

    I would to prefer to have a folder called Company then have Edit.html Create.html

    I find it strange that this seems like its not possible, if anyone can explain all of this, I will be internaly greatful.

    Ayo

  • Ayo Adesina 430 posts 1023 karma points
    Sep 02, 2017 @ 12:40
    Ayo Adesina
    0

    I have worked it out when creating menu items you can specify the location of a view.

    MenuItem mi = new MenuItem("brand-edit/test/test2", "Create");
                    menu.Items.Add(mi);
    

    That will translate to:

    /App_Plugins/App-Name-Here/backoffice/tree-name/brand-edit/test/test2.html
    

    This is what I want. (being able to put my views anywhere)

    However this dosn't work when creating the nodes them selfs when calling CreateTreeNode()

    pathToView = FormDataCollectionExtensions.GetValue<string>(queryStrings, "application") + "/treename/viewName/" +  Id.ToString();
    
    CreateTreeNode(..., ...., pathToView)
    

    If you try to add an extra folder to that path, umbraco never finds the view.

    I must be missing something....

  • Bo Jacobsen 597 posts 2395 karma points
    Sep 02, 2017 @ 21:12
    Bo Jacobsen
    0

    Hi Ayo.

    Instead of treeName try setting the TreeAlias.

    var treeNode = CreateTreeNode("id", "parentId", queryStrings, "Title", "Icon", false, "appAlias/TreeAlias/ViewName/id");
    
Please Sign in or register to post replies

Write your reply to:

Draft