Skip to content

Commit

Permalink
Cleanup Admin Menu (#15199)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored and hishamco committed Feb 1, 2024
1 parent 76f82a6 commit 444e8bd
Show file tree
Hide file tree
Showing 64 changed files with 850 additions and 459 deletions.
17 changes: 12 additions & 5 deletions src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.Admin.Drivers;
using OrchardCore.Navigation;
Expand All @@ -8,6 +8,12 @@ namespace OrchardCore.Admin
{
public class AdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
{ "area", "OrchardCore.Settings" },
{ "groupId", AdminSiteSettingsDisplayDriver.GroupId },
};

protected readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer)
Expand All @@ -17,7 +23,7 @@ public AdminMenu(IStringLocalizer<AdminMenu> localizer)

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return Task.CompletedTask;
}
Expand All @@ -26,12 +32,13 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Add(S["Configuration"], configuration => configuration
.Add(S["Settings"], settings => settings
.Add(S["Admin"], S["Admin"].PrefixPosition(), admin => admin
.AddClass("admin").Id("admin")
.Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = AdminSiteSettingsDisplayDriver.GroupId })
.AddClass("admin").Id("admin")
.Action("Index", "Admin", _routeValues)
.Permission(PermissionsAdminSettings.ManageAdminSettings)
.LocalNav()
)
));
)
);

return Task.CompletedTask;
}
Expand Down
3 changes: 2 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Layout;
using OrchardCore.DisplayManagement.Shapes;
using OrchardCore.Navigation;

namespace OrchardCore.Admin
{
Expand Down Expand Up @@ -57,7 +58,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, R
var menuShape = await _shapeFactory.CreateAsync("Navigation",
Arguments.From(new
{
MenuName = "admin",
MenuName = NavigationConstants.AdminId,
filterContext.RouteData,
}));

Expand Down
15 changes: 8 additions & 7 deletions src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using OrchardCore.AdminMenu.Services;
Expand All @@ -20,21 +19,23 @@ public AdminMenu(AdminMenuNavigationProvidersCoordinator adminMenuNavigationProv

public async Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return;
}

// Configuration and settings menus for the AdminMenu module
builder.Add(S["Configuration"], configuration => configuration
.Add(S["Admin Menus"], S["Admin Menus"].PrefixPosition(), admt => admt
builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Admin Menus"], S["Admin Menus"].PrefixPosition(), adminMenu => adminMenu
.Permission(Permissions.ManageAdminMenu)
.Action("List", "Menu", new { area = "OrchardCore.AdminMenu" })
.Action("List", "Menu", "OrchardCore.AdminMenu")
.LocalNav()
));
)
);

// This is the entry point for the adminMenu: dynamically generated custom admin menus
await _adminMenuNavigationProvider.BuildNavigationAsync("adminMenu", builder);
await _adminMenuNavigationProvider.BuildNavigationAsync(NavigationConstants.AdminMenuId, builder);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -39,12 +38,13 @@ public AdminMenuNavigationProvidersCoordinator(
// todo: use a public constant for the string
public async Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "adminMenu", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(NavigationConstants.AdminMenuId, name))
{
return;
}

var trees = (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu.Where(m => m.Enabled && m.MenuItems.Count > 0);
var trees = (await _adminMenuService.GetAdminMenuListAsync())
.AdminMenu.Where(m => m.Enabled && m.MenuItems.Count > 0);

foreach (var tree in trees)
{
Expand Down
7 changes: 3 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/AdminMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using OrchardCore.Navigation;
Expand All @@ -16,15 +15,15 @@ public AdminMenu(IStringLocalizer<AdminMenu> localizer)

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return Task.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["GraphiQL"], S["GraphiQL"].PrefixPosition(), deployment => deployment
.Action("Index", "Admin", new { area = "OrchardCore.Apis.GraphQL" })
.Add(S["GraphiQL"], S["GraphiQL"].PrefixPosition(), graphiQL => graphiQL
.Action("Index", "Admin", "OrchardCore.Apis.GraphQL")
.Permission(Permissions.ExecuteGraphQL)
.LocalNav()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.AuditTrail.Controllers;
using OrchardCore.Navigation;
Expand All @@ -8,6 +8,12 @@ namespace OrchardCore.AuditTrail.Navigation
{
public class AuditTrailAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
{ "area", "OrchardCore.AuditTrail" },
{ "correlationId", string.Empty },
};

protected readonly IStringLocalizer S;

public AuditTrailAdminMenu(IStringLocalizer<AuditTrailAdminMenu> stringLocalizer)
Expand All @@ -17,17 +23,19 @@ public AuditTrailAdminMenu(IStringLocalizer<AuditTrailAdminMenu> stringLocalizer

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return Task.CompletedTask;
}

builder
.Add(S["Audit Trail"], NavigationConstants.AdminMenuAuditTrailPosition, configuration => configuration
.AddClass("audittrail").Id("audittrail")
.Action(nameof(AdminController.Index), "Admin", new { area = "OrchardCore.AuditTrail", correlationId = "" })
.AddClass("audittrail")
.Id("audittrail")
.Action(nameof(AdminController.Index), "Admin", _routeValues)
.Permission(AuditTrailPermissions.ViewAuditTrail)
.LocalNav());
.LocalNav()
);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.AuditTrail.Settings;
using OrchardCore.Navigation;
Expand All @@ -8,6 +8,12 @@ namespace OrchardCore.AuditTrail.Navigation
{
public class AuditTrailSettingsAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
{ "area", "OrchardCore.Settings" },
{ "groupId", AuditTrailSettingsGroup.Id },
};

protected readonly IStringLocalizer S;

public AuditTrailSettingsAdminMenu(IStringLocalizer<AuditTrailSettingsAdminMenu> stringLocalizer)
Expand All @@ -17,19 +23,23 @@ public AuditTrailSettingsAdminMenu(IStringLocalizer<AuditTrailSettingsAdminMenu>

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return Task.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Settings"], settings => settings
.Add(S["Audit Trail"], S["Audit Trail"].PrefixPosition(), settings => settings
.AddClass("audittrail").Id("audittrailSettings")
.Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = AuditTrailSettingsGroup.Id })
.Add(S["Audit Trail"], S["Audit Trail"].PrefixPosition(), auditTrail => auditTrail
.AddClass("audittrail")
.Id("audittrailSettings")
.Action("Index", "Admin", _routeValues)
.Permission(AuditTrailPermissions.ManageAuditTrailSettings)
.LocalNav())));
.LocalNav()
)
)
);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using OrchardCore.Navigation;
Expand All @@ -13,7 +12,7 @@ public class AdminMenu : INavigationProvider

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return Task.CompletedTask;
}
Expand All @@ -22,7 +21,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Add(S["Configuration"], configuration => configuration
.Add(S["Tasks"], S["Tasks"].PrefixPosition(), tasks => tasks
.Add(S["Background Tasks"], S["Background Tasks"].PrefixPosition(), backgroundTasks => backgroundTasks
.Action("Index", "BackgroundTask", new { area = "OrchardCore.BackgroundTasks" })
.Action("Index", "BackgroundTask", "OrchardCore.BackgroundTasks")
.Permission(Permissions.ManageBackgroundTasks)
.LocalNav()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.ContentLocalization.Drivers;
using OrchardCore.Modules;
Expand All @@ -10,6 +10,18 @@ namespace OrchardCore.ContentLocalization
[Feature("OrchardCore.ContentLocalization.ContentCulturePicker")]
public class AdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _providersRouteValues = new()
{
{ "area", "OrchardCore.Settings" },
{ "groupId", ContentRequestCultureProviderSettingsDriver.GroupId },
};

private static readonly RouteValueDictionary _pickerRouteValues = new()
{
{ "area", "OrchardCore.Settings" },
{ "groupId", ContentCulturePickerSettingsDriver.GroupId },
};

protected readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer)
Expand All @@ -19,7 +31,7 @@ public AdminMenu(IStringLocalizer<AdminMenu> localizer)

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return Task.CompletedTask;
}
Expand All @@ -28,15 +40,17 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Add(S["Configuration"], configuration => configuration
.Add(S["Settings"], settings => settings
.Add(S["Localization"], localization => localization
.Add(S["Content Request Culture Provider"], S["Content Request Culture Provider"].PrefixPosition(), registration => registration
.AddClass("contentrequestcultureprovider").Id("contentrequestcultureprovider")
.Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = ContentRequestCultureProviderSettingsDriver.GroupId })
.Add(S["Content Request Culture Provider"], S["Content Request Culture Provider"].PrefixPosition(), provider => provider
.AddClass("contentrequestcultureprovider")
.Id("contentrequestcultureprovider")
.Action("Index", "Admin", _providersRouteValues)
.Permission(Permissions.ManageContentCulturePicker)
.LocalNav()
)
.Add(S["Content Culture Picker"], S["Content Culture Picker"].PrefixPosition(), registration => registration
.AddClass("contentculturepicker").Id("contentculturepicker")
.Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = ContentCulturePickerSettingsDriver.GroupId })
.Add(S["Content Culture Picker"], S["Content Culture Picker"].PrefixPosition(), picker => picker
.AddClass("contentculturepicker")
.Id("contentculturepicker")
.Action("Index", "Admin", _pickerRouteValues)
.Permission(Permissions.ManageContentCulturePicker)
.LocalNav()
)
Expand Down
33 changes: 18 additions & 15 deletions src/OrchardCore.Modules/OrchardCore.ContentTypes/AdminMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using OrchardCore.ContentTypes.Controllers;
Expand All @@ -9,6 +8,8 @@ namespace OrchardCore.ContentTypes
{
public class AdminMenu : INavigationProvider
{
private static readonly string _adminControllerName = typeof(AdminController).ControllerName();

protected readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer)
Expand All @@ -18,24 +19,26 @@ public AdminMenu(IStringLocalizer<AdminMenu> localizer)

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!NavigationHelper.IsAdminMenu(name))
{
return Task.CompletedTask;
}

var adminControllerName = typeof(AdminController).ControllerName();

builder.Add(S["Content"], content => content
.Add(S["Content Definition"], S["Content Definition"].PrefixPosition("9"), contentDefinition => contentDefinition
.Add(S["Content Types"], S["Content Types"].PrefixPosition("1"), contentTypes => contentTypes
.Action(nameof(AdminController.List), adminControllerName, new { area = "OrchardCore.ContentTypes" })
.Permission(Permissions.ViewContentTypes)
.LocalNav())
.Add(S["Content Parts"], S["Content Parts"].PrefixPosition("2"), contentParts => contentParts
.Action(nameof(AdminController.ListParts), adminControllerName, new { area = "OrchardCore.ContentTypes" })
.Permission(Permissions.ViewContentTypes)
.LocalNav())
));
builder
.Add(S["Content"], content => content
.Add(S["Content Definition"], S["Content Definition"].PrefixPosition("9"), contentDefinition => contentDefinition
.Add(S["Content Types"], S["Content Types"].PrefixPosition("1"), contentTypes => contentTypes
.Action(nameof(AdminController.List), _adminControllerName, "OrchardCore.ContentTypes")
.Permission(Permissions.ViewContentTypes)
.LocalNav()
)
.Add(S["Content Parts"], S["Content Parts"].PrefixPosition("2"), contentParts => contentParts
.Action(nameof(AdminController.ListParts), _adminControllerName, "OrchardCore.ContentTypes")
.Permission(Permissions.ViewContentTypes)
.LocalNav()
)
)
);

return Task.CompletedTask;
}
Expand Down
Loading

0 comments on commit 444e8bd

Please sign in to comment.