Admin Dashboard: new menu item, how to apply admin theme

Topics: Administration
May 22, 2015 at 1:30 AM
I don't fully understand what is happening here.

I have created a half dozen menus, this is my first time!
    public class AdminMenu : INavigationProvider
    {

        public void GetNavigation(NavigationBuilder builder)
        {
            builder.AddImageSet("settings")
                .Add(T("Naxos Users"), "99",
                    menu => menu.Add(T("General"), "0", item => item.Action("Index", "Admin", new { area = "Naxos.Users", groupInfoId = "Index" })
                        ), new[] { "collapsed" });

            childMenu[] childMenus = new childMenu[]
            {
                new childMenu { name="Schools",             action="Index", controller= "Admin", options = new { area="Naxos.Users", param = "Value"}},
                new childMenu { name="Roles",               action="Index", controller= "RolesAdmin", options = new { area="Naxos.Users", param = "Value"}},
                new childMenu { name="Restriction Types",   action="Index", controller= "Admin", options = new { area="Naxos.Users", param = "Value"}},
                new childMenu { name="Audit Trail",         action="Index", controller= "Admin", options = new { area="Naxos.Users", param = "Value"}},
                new childMenu { name="Activity",            action="Index", controller= "Admin", options = new { area="Naxos.Users", param = "Value"}}
            };

            int i = 1;
            foreach (childMenu info in childMenus)
            {
                builder.Add(T("Naxos Users"),
                            menu =>
                                    menu.Add(T(info.name),
                                                i++.ToString(),
                                                item => item.Action(info.action, info.controller, info.options)

                                            )
                            );
            }
        }
The Admin Controller
   [ValidateInput(false)]
    public class AdminController : Controller
    {
        private readonly IOrchardServices _orchardServices;

        public ILogger Logger { get; set; }

        public Localizer T { get; set; }

        public AdminController(IOrchardServices orchardServices
            )
        {
            _orchardServices = orchardServices;
            Logger = NullLogger.Instance;
        }

        public ActionResult Index()
        {
            return View("Admin/NotImplimented");
        }
    }
The RolesAdminController
    [ValidateInput(false)]
    public class RolesAdminController : Controller
    {
        private readonly IOrchardServices _orchardServices;

        public ILogger Logger { get; set; }

        public Localizer T { get; set; }

        public RolesAdminController(IOrchardServices orchardServices
            )
        {
            _orchardServices = orchardServices;
            Logger = NullLogger.Instance;
        }

        public ActionResult Index()
        {
            return View("Admin/Roles/Index");
        }
    }
Yes, we decided to split out some roles into our own handler for front end user permissions.


The menu items that point to the Admin Controller show the view inside the right side of the Dashboard,

While the RolesAdmin shows an unskinned/templated page

Image

Image
May 22, 2015 at 9:44 AM
Edited May 22, 2015 at 9:46 AM
When you name a controller "AdminController", Orchard automatically will apply the Admin theme.
When you give a controller any other name, but you still want to have the Admin theme applied, you can use the [Admin] attribute above the controller to apply the Admin theme:
[Admin]
public class RolesAdminController : Controller
May 22, 2015 at 9:12 PM
Ah! Thanks.

I was looking at Tags and I do not see the attribute. I easily learned it was Orchard naming convention magic making the theme apply for the Admin controller but for some reason i thought it was associated to naming to where the CSHTML's were.