Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AdminNavigationProvider to cleanup AdminMenu #16674

Merged
merged 10 commits into from
Sep 6, 2024
15 changes: 4 additions & 11 deletions src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OrchardCore.Admin;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
Expand All @@ -15,18 +15,13 @@ public sealed class AdminMenu : INavigationProvider

internal readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer)
public AdminMenu(IStringLocalizer<AdminMenu> stringLocalizer)
{
S = localizer;
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Settings"], settings => settings
Expand All @@ -38,7 +33,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
)
);

return ValueTask.CompletedTask;
}
}
20 changes: 8 additions & 12 deletions src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@

namespace OrchardCore.AdminMenu;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
private readonly AdminMenuNavigationProvidersCoordinator _adminMenuNavigationProviderCoordinator;

internal readonly IStringLocalizer S;

public AdminMenu(AdminMenuNavigationProvidersCoordinator adminMenuNavigationProviderCoordinator,
IStringLocalizer<AdminMenu> localizer)
public AdminMenu(
AdminMenuNavigationProvidersCoordinator adminMenuNavigationProviderCoordinator,
IStringLocalizer<AdminMenu> stringLocalizer)
{
_adminMenuNavigationProviderCoordinator = adminMenuNavigationProviderCoordinator;
S = localizer;
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override ValueTask BuildAsync(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

// Configuration and settings menus for the AdminMenu module
// Configuration and settings menus for the AdminMenu module.
builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Admin Menus"], S["Admin Menus"].PrefixPosition(), adminMenu => adminMenu
Expand All @@ -34,7 +30,7 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
);

// This is the entry point for the adminMenu: dynamically generated custom admin menus
// This is the entry point for the adminMenu: dynamically generated custom admin menus.
return _adminMenuNavigationProviderCoordinator.BuildNavigationAsync(NavigationConstants.AdminMenuId, builder);
}
}
15 changes: 4 additions & 11 deletions src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@

namespace OrchardCore.Apis.GraphQL;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
internal readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer)
public AdminMenu(IStringLocalizer<AdminMenu> stringLocalizer)
{
S = localizer;
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["GraphiQL"], S["GraphiQL"].PrefixPosition(), graphiQL => graphiQL
Expand All @@ -27,7 +22,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
.LocalNav()
)
);

return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OrchardCore.AuditTrail.Navigation;

public sealed class AuditTrailAdminMenu : INavigationProvider
public sealed class AuditTrailAdminMenu : AdminNavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
Expand All @@ -20,13 +20,8 @@ public AuditTrailAdminMenu(IStringLocalizer<AuditTrailAdminMenu> stringLocalizer
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Audit Trail"], NavigationConstants.AdminMenuAuditTrailPosition, configuration => configuration
.AddClass("audittrail")
Expand All @@ -35,7 +30,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
.Permission(AuditTrailPermissions.ViewAuditTrail)
.LocalNav()
);

return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OrchardCore.AuditTrail.Navigation;

public sealed class AuditTrailSettingsAdminMenu : INavigationProvider
public sealed class AuditTrailSettingsAdminMenu : AdminNavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
Expand All @@ -20,13 +20,8 @@ public AuditTrailSettingsAdminMenu(IStringLocalizer<AuditTrailSettingsAdminMenu>
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Settings"], settings => settings
Expand All @@ -39,7 +34,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
)
);

return ValueTask.CompletedTask;
}
}
16 changes: 6 additions & 10 deletions src/OrchardCore.Modules/OrchardCore.BackgroundTasks/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@

namespace OrchardCore.BackgroundTasks;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
internal readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer) => S = localizer;

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
public AdminMenu(IStringLocalizer<AdminMenu> stringLocalizer)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}
S = stringLocalizer;
}

protected override void Build(NavigationBuilder builder)
{
builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Tasks"], S["Tasks"].PrefixPosition(), tasks => tasks
Expand All @@ -26,7 +24,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
)
);

return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OrchardCore.ContentLocalization;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
private static readonly RouteValueDictionary _providersRouteValues = new()
{
Expand All @@ -21,18 +21,13 @@ public sealed class AdminMenu : INavigationProvider

internal readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer)
public AdminMenu(IStringLocalizer<AdminMenu> stringLocalizer)
{
S = localizer;
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Settings"], settings => settings
Expand All @@ -54,7 +49,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
)
);

return ValueTask.CompletedTask;
}
}
15 changes: 4 additions & 11 deletions src/OrchardCore.Modules/OrchardCore.ContentTypes/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@

namespace OrchardCore.ContentTypes;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
private static readonly string _adminControllerName = typeof(AdminController).ControllerName();

internal readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> localizer)
public AdminMenu(IStringLocalizer<AdminMenu> stringLocalizer)
{
S = localizer;
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Content"], content => content
.Add(S["Content Definition"], S["Content Definition"].PrefixPosition("9"), contentDefinition => contentDefinition
Expand All @@ -38,7 +33,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
)
);

return ValueTask.CompletedTask;
}
}
13 changes: 4 additions & 9 deletions src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace OrchardCore.Contents;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
Expand Down Expand Up @@ -45,24 +45,19 @@ public AdminMenu(
LinkGenerator linkGenerator,
IAuthorizationService authorizationService,
ISiteService siteService,
IStringLocalizer<AdminMenu> localizer)
IStringLocalizer<AdminMenu> stringLocalizer)
{
_contentDefinitionManager = contentDefinitionManager;
_contentManager = contentManager;
_httpContextAccessor = httpContextAccessor;
_linkGenerator = linkGenerator;
_authorizationService = authorizationService;
_siteService = siteService;
S = localizer;
S = stringLocalizer;
}

public async ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override async ValueTask BuildAsync(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return;
}

var context = _httpContextAccessor.HttpContext;

var contentTypeDefinitions = await _contentDefinitionManager.ListTypeDefinitionsAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OrchardCore.Contents.Deployment.ExportContentToDeploymentTarget;

public sealed class ExportContentToDeploymentTargetAdminMenu : INavigationProvider
public sealed class ExportContentToDeploymentTargetAdminMenu : AdminNavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
{
Expand All @@ -14,18 +14,13 @@ public sealed class ExportContentToDeploymentTargetAdminMenu : INavigationProvid

internal readonly IStringLocalizer S;

public ExportContentToDeploymentTargetAdminMenu(IStringLocalizer<AdminMenu> localizer)
public ExportContentToDeploymentTargetAdminMenu(IStringLocalizer<AdminMenu> stringLocalizer)
{
S = localizer;
S = stringLocalizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Import/Export"], S["Import/Export"].PrefixPosition(), import => import
Expand All @@ -38,7 +33,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
)
);

return ValueTask.CompletedTask;
}
}
11 changes: 2 additions & 9 deletions src/OrchardCore.Modules/OrchardCore.Cors/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OrchardCore.Cors;

public sealed class AdminMenu : INavigationProvider
public sealed class AdminMenu : AdminNavigationProvider
{
internal readonly IStringLocalizer S;

Expand All @@ -12,13 +12,8 @@ public AdminMenu(IStringLocalizer<AdminMenu> localizer)
S = localizer;
}

public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
protected override void Build(NavigationBuilder builder)
{
if (!NavigationHelper.IsAdminMenu(name))
{
return ValueTask.CompletedTask;
}

builder
.Add(S["Configuration"], configuration => configuration
.Add(S["Settings"], settings => settings
Expand All @@ -31,7 +26,5 @@ public ValueTask BuildNavigationAsync(string name, NavigationBuilder builder)
)
)
);

return ValueTask.CompletedTask;
}
}
Loading