Copied to clipboard

Flag this post as spam?

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


  • Darren Hunter 134 posts 226 karma points
    Sep 18, 2024 @ 13:02
    Darren Hunter
    0

    Section

    Hi,

    I am trying to add a new section and have 2 issues

    1: When I set the following in code, it keeps loading the setting menu, when I click on the new section.

    Code:

    protected override ActionResult

    var root = rootResult.Value;
    
    if (root != null) {
    
        root.RoutePath = string.Format("{0}/{1}/{2}", Constants.Applications.Settings, "housinginformation", "overview");
    
        // set the icon
        root.Icon = "icon-hearts";
        // could be set to false for a custom tree with a single node.
        root.HasChildren = false;
        //url for menu
        //root.MenuUrl = null;
    }
    
    return root;
    

    }

    But if I set root.RoutePath =null, then the menu loads as normal.

    2: How do I remove the 3 dots at the end of the menu items as I do not beed a Add, Del, Edit menu options.

    Here is the code for the full controller.

    using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Actions; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models.Trees; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Trees; using Umbraco.Cms.Web.BackOffice.Trees; using Umbraco.Cms.Web.Common.Attributes; using Umbraco.Cms.Web.Common.ModelBinders; using Umbraco.Extensions;

    namespace UmbracoCMS.App_Code.HousingInformation { [Tree("housinginformation", "housinginformation", IsSingleNodeTree = true, TreeTitle = "Blocks", TreeGroup = "housinginformationGroup", SortOrder = 0)] [PluginController("HousingInformation")] public class HousingInformationTreeController : TreeController { private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;

        public HousingInformationTreeController(ILocalizedTextService localizedTextService,
        UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
        IMenuItemCollectionFactory menuItemCollectionFactory,
        IEventAggregator eventAggregator)
        : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
        {
            _menuItemCollectionFactory = menuItemCollectionFactory ?? throw new ArgumentNullException(nameof(menuItemCollectionFactory));
        }
        protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
        {
            var nodes = new TreeNodeCollection();
    
            // check if we're rendering the root node's children
            if (id == Constants.System.Root.ToInvariantString())
            {
                var node1 = CreateTreeNode("1", "-1", queryStrings, "Block Information", "icon-presentation", false,"housinginformation/housinginformation/blocks");
                var node2 = CreateTreeNode("2", "-1", queryStrings, "Block Schedual", "icon-presentation", false,"housinginformation/housinginformation/schedule");
    
                nodes.Add(node1);
                nodes.Add(node2);
            }
    
            return nodes;
        }
    
        protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
        {
            // create a Menu Item Collection to return so people can interact with the nodes in your tree
            var menu = _menuItemCollectionFactory.Create();
    
            //if (id == Constants.System.Root.ToInvariantString())
            //{
            //    // root actions, perhaps users can create new items in this tree, or perhaps it's not a content tree, it might be a read only tree, or each node item might represent something entirely different...
            //    // add your menu item actions or custom ActionMenuItems
            //    menu.Items.Add(new CreateChildEntity(LocalizedTextService));
            //    // add refresh menu item (note no dialog)
            //    menu.Items.Add(new RefreshNode(LocalizedTextService, true));
            //}
            //else
            //{
            //    // add a delete action to each individual item
            //    menu.Items.Add<ActionDelete>(LocalizedTextService, true, opensDialog: true);
            //}
    
    
            return  menu; // null;
        }
    
        protected override ActionResult<TreeNode?> CreateRootNode(FormCollection queryStrings)
        {
            var rootResult = base.CreateRootNode(queryStrings);
            if (!(rootResult.Result is null))
            {
                return rootResult;
            }
    
            var root = rootResult.Value;
    
            if (root != null) {
    
                root.RoutePath = string.Format("{0}/{1}/{2}", Constants.Applications.Settings, "housinginformation", "overview");
    
                // set the icon
                root.Icon = "icon-hearts";
                // could be set to false for a custom tree with a single node.
                root.HasChildren = false;
                //url for menu
                //root.MenuUrl = null;
            }
    
            return root;
        }
    
    
    }
    

    }

    Thanks Darren

Please Sign in or register to post replies

Write your reply to:

Draft