Copied to clipboard

Flag this post as spam?

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


  • Rickard Liljeberg 23 posts 114 karma points
    Feb 29, 2016 @ 21:55
    Rickard Liljeberg
    0

    Routing for TreeController Actions

    I am developing my own section/application which contains a tree.

    My tree rendering looks like following

    protected override TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
            {
    
                var nodes = new TreeNodeCollection();
    
                //check if we're rendering the root node's children
                if (id == Constants.System.Root.ToInvariantString())
                {
    
    
                    nodes.Add(CreateTreeNode(
                        "event",
                        "-1",
                        queryStrings,
                        Umbraco.GetDictionaryValue("Events"),
                        "icon-slideshow",
                        false,
                        "EventPlanner/EventPlannerTree/EventsMain/0"));
    
                    nodes.Add(CreateTreeNode(
                        "occasion",
                        "-1",
                        queryStrings,
                        Umbraco.GetDictionaryValue("Event occasions"),
                        "icon-calendar-alt",
                        false,  
                        "EventPlanner/EventPlannerTree/EventOccasionsMain/0"));
    
    
                     //...a few more removed for brevity
    
    
                }
                else
                {
                    //...Second level removed for brevity
    
                }
    
                return nodes;
            }
    

    Now this works like a charm, it prints the menu and if you click on the "Events" you go to the page EventsMain and if you click "Event occasions" you go to EventOccasionsMain page. This part works flawless.

    But now onto the Menu/actions. Here is my code:

        protected override MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
        {
            var menu = new MenuItemCollection();
    
            if (id == Constants.System.Root.ToInvariantString())
            {
                //Root node can do nothing as we have fixed first level nodes
            }
            else if(id == "occasion" || id == "leader" || id == "location")  //The ones you can create children of
            {
    
                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 == "event")
            {
                //Event has to be clicked, no actions in the tree
            }
            else
            {
                //The rest are items that can be deleted
                menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
    
            }
            return menu;
        }
    

    Now like it should be occasion, leader and location (above leader and location was removed for brevity) they get create to create children. In the menu for these "Create" comes out in the fold out menu.

    But the problem is, they all go to the same page. They go to urls like so

    /umbraco#/EventPlanner/EventPlannerTree/edit/occasion?create

    and

    /umbraco#/EventPlanner/EventPlannerTree/edit/location?create

    Both of these urls means it tries to load the edit.html and send with the parameters which will be set to "occasion" and "create" alternatively "location" and "create".

    Now I can with angular and directives make this work from one and the same edit.html.... but I find that less than perfect.

    I would like one editOccasion, another editLocation and so on... so depending on which node you clicked create on I want to route them differently. How can this be accomplished?

  • Rickard Liljeberg 23 posts 114 karma points
    Mar 10, 2016 @ 14:56
    Rickard Liljeberg
    0

    Not that it is a solution to the question per say. But my solution was to have them all go to the same edit page.

    Then I would on that page only have

    <edit-location></edit-location>
    <edit-leader></edit-leader>
    

    And so on. Those are Angular directives. In the directive I would check the ID sent in. i.e. "leader" or "location" and then only render the correct one.

    Not great but it works.

Please Sign in or register to post replies

Write your reply to:

Draft