Copied to clipboard

Flag this post as spam?

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


  • David Armitage 505 posts 2073 karma points
    Aug 21, 2017 @ 11:16
    David Armitage
    0

    Umbraco Hardcoded Tree Context Menu Items

    Hi Guys,

    I am rendering custom menu items in the application started event. I am not entirely happy with the speed they load. There is a bit of a lag when right clicking on the nodes or clicking on the action buttons.

    I just wondered if there was some way I can hard code these. Possibly in config files so they load faster.

    private void ContentTreeController_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
            {
                var treeAlias = sender.TreeAlias;
                var queryString = e.QueryStrings["id"];
    
                if (e.NodeId != "-1")
                {
                    var contentService = ApplicationContext.Current.Services.ContentService;
    
                    int nodeId;
                    if (int.TryParse(e.NodeId, out nodeId))
                    {
                        var content = contentService.GetById(nodeId);
    
                        if (content != null)
                        {
                            var nodeTypeAlias = content.ContentType.Alias;
    
                            if (nodeTypeAlias == "emailAlertsFolder")
                            {
                                var sendJobAlerts = new MenuItem("sendJobAlerts", "Send Job Alerts");
                                sendJobAlerts.AdditionalData.Add("actionView", "/App_Plugins/BackendExtensions/views/SendJobAlerts.html");
                                sendJobAlerts.Icon = "right-double-arrow color-red";
                                e.Menu.Items.Insert(e.Menu.Items.Count, sendJobAlerts);
    
                                var sendHotCandidateAlerts = new MenuItem("sendHotCandidateAlerts", "Send Hot Candidate Alerts");
                                sendHotCandidateAlerts.AdditionalData.Add("actionView", "/App_Plugins/BackendExtensions/views/SendHotCandidateAlerts.html");
                                sendHotCandidateAlerts.Icon = "right-double-arrow color-red";
                                e.Menu.Items.Insert(e.Menu.Items.Count, sendHotCandidateAlerts);
    
                                var sendBlogAlerts = new MenuItem("sendBlogAlerts", "Send Blog Alerts");
                                sendBlogAlerts.AdditionalData.Add("actionView", "/App_Plugins/BackendExtensions/views/SendBlogAlerts.html");
                                sendBlogAlerts.Icon = "right-double-arrow color-red";
                                e.Menu.Items.Insert(e.Menu.Items.Count, sendBlogAlerts);
                            }
    
                            if (nodeTypeAlias == "jobsListFolder")
                            {
                                var archiveExpiredJobs = new MenuItem("archiveExpiredJobs", "Archive Expired Jobs");
                                archiveExpiredJobs.AdditionalData.Add("actionView", "/App_Plugins/BackendExtensions/views/ArchiveExpiredJobs.html");
                                archiveExpiredJobs.Icon = "re-post color-red";
                                e.Menu.Items.Insert(e.Menu.Items.Count, archiveExpiredJobs);
                            };
                        }
                    }
    
                }
    
            }
    

    If anyone could tell me how the replicate the following in config that would be awesome.

    Kind Regards

    David

  • David Armitage 505 posts 2073 karma points
    Aug 22, 2017 @ 07:37
    David Armitage
    0

    Hi,

    I optimized the code slightly. Not sure what was going on there. Must have copied and pasted from some old code :(

    Anyway this seems to work faster. No need to mess around with the contentService. Simply checking the hard coded Id is sufficient in this case.

    private void ContentTreeController_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
            {
                if (e.NodeId == "1285")
                {
                    var archiveExpiredJobs = new MenuItem("archiveExpiredJobs", "Archive Expired Jobs");
                    archiveExpiredJobs.AdditionalData.Add("actionView", "/App_Plugins/BackendExtensions/views/ArchiveExpiredJobs.html");
                    archiveExpiredJobs.Icon = "re-post color-red";
                    e.Menu.Items.Insert(e.Menu.Items.Count, archiveExpiredJobs);
                }
            }
    

    I would be still interested in hearing if anyone knows how to hardcode a context menu tree structure.

    Kind Regards

    David

Please Sign in or register to post replies

Write your reply to:

Draft