mirror of https://github.com/abpframework/abp.git
23 changed files with 350 additions and 23 deletions
@ -0,0 +1,28 @@ |
|||||
|
@using Microsoft.Extensions.Options |
||||
|
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Routing |
||||
|
@using MudBlazor |
||||
|
@inject IOptions<AbpRouterOptions> RouterOptions |
||||
|
<CascadingAuthenticationState> |
||||
|
<Router AppAssembly="RouterOptions.Value.AppAssembly" |
||||
|
AdditionalAssemblies="RouterOptions.Value.AdditionalAssemblies"> |
||||
|
<Found Context="routeData"> |
||||
|
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> |
||||
|
<NotAuthorized> |
||||
|
@if (!context.User.Identity.IsAuthenticated) |
||||
|
{ |
||||
|
<RedirectToLogin /> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
<MudText>You are not authorized to access this resource.</MudText> |
||||
|
} |
||||
|
</NotAuthorized> |
||||
|
</AuthorizeRouteView> |
||||
|
</Found> |
||||
|
<NotFound> |
||||
|
<LayoutView Layout="@typeof(MainLayout)"> |
||||
|
<MudText>Sorry, there's nothing at this address.</MudText> |
||||
|
</LayoutView> |
||||
|
</NotFound> |
||||
|
</Router> |
||||
|
</CascadingAuthenticationState> |
||||
@ -0,0 +1,15 @@ |
|||||
|
@using Microsoft.Extensions.Options |
||||
|
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Routing |
||||
|
@using MudBlazor |
||||
|
@inject IOptions<AbpRouterOptions> RouterOptions |
||||
|
<Router AppAssembly="RouterOptions.Value.AppAssembly" |
||||
|
AdditionalAssemblies="RouterOptions.Value.AdditionalAssemblies"> |
||||
|
<Found Context="routeData"> |
||||
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> |
||||
|
</Found> |
||||
|
<NotFound> |
||||
|
<LayoutView Layout="@typeof(MainLayout)"> |
||||
|
<MudText>Sorry, there's nothing at this address.</MudText> |
||||
|
</LayoutView> |
||||
|
</NotFound> |
||||
|
</Router> |
||||
@ -1,4 +1,5 @@ |
|||||
@using Volo.Abp.Ui.Branding |
@using Volo.Abp.Ui.Branding |
||||
|
@using MudBlazor |
||||
@inject IBrandingProvider BrandingProvider |
@inject IBrandingProvider BrandingProvider |
||||
|
|
||||
<MudText Typo="Typo.h6" Class="ma-0">@BrandingProvider.AppName</MudText> |
<MudText Typo="Typo.h6" Class="ma-0">@BrandingProvider.AppName</MudText> |
||||
|
|||||
@ -0,0 +1,77 @@ |
|||||
|
@using Volo.Abp.UI.Navigation |
||||
|
@using MudBlazor |
||||
|
@using Microsoft.AspNetCore.Components |
||||
|
@using Microsoft.AspNetCore.Components.Routing |
||||
|
@using System |
||||
|
@{ |
||||
|
var customComponentType = MenuItem.GetComponentTypeOrDefault(); |
||||
|
} |
||||
|
|
||||
|
@if (customComponentType != null && typeof(ComponentBase).IsAssignableFrom(customComponentType)) |
||||
|
{ |
||||
|
<DynamicComponent Type="@customComponentType" /> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
<MudNavGroup Title="@MenuItem.DisplayName" Icon="@GetIcon(MenuItem.Icon)"> |
||||
|
@foreach (var item in MenuItem.Items) |
||||
|
{ |
||||
|
@if (item.Items.Any()) |
||||
|
{ |
||||
|
<SecondLevelNavMenuItem MenuItem="item" /> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
<MudNavLink Href="@(item.Url?.TrimStart('/', '~') ?? "#")" Match="@(item.Url != null ? NavLinkMatch.All : NavLinkMatch.Prefix)"> |
||||
|
@if (!string.IsNullOrEmpty(item.Icon)) |
||||
|
{ |
||||
|
<MudIcon Icon="@GetIcon(item.Icon)" Class="me-2" /> |
||||
|
} |
||||
|
@item.DisplayName |
||||
|
</MudNavLink> |
||||
|
} |
||||
|
} |
||||
|
</MudNavGroup> |
||||
|
} |
||||
|
|
||||
|
@code { |
||||
|
[Parameter] |
||||
|
public ApplicationMenuItem MenuItem { get; set; } = default!; |
||||
|
|
||||
|
[Inject] |
||||
|
private NavigationManager NavigationManager { get; set; } = default!; |
||||
|
|
||||
|
protected override void OnInitialized() |
||||
|
{ |
||||
|
NavigationManager.LocationChanged += OnLocationChanged; |
||||
|
} |
||||
|
|
||||
|
protected virtual void OnLocationChanged(object? sender, LocationChangedEventArgs e) |
||||
|
{ |
||||
|
// Menu will close automatically on navigation |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
NavigationManager.LocationChanged -= OnLocationChanged; |
||||
|
} |
||||
|
|
||||
|
private string? GetIcon(string? icon) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(icon)) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Convert FontAwesome icons to Material icons if needed |
||||
|
if (icon.StartsWith("fa")) |
||||
|
{ |
||||
|
// Map common FontAwesome icons to Material icons |
||||
|
return icon.Replace("fa-", "").Replace("-", "_"); |
||||
|
} |
||||
|
|
||||
|
return icon; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@implements IDisposable |
||||
@ -0,0 +1,9 @@ |
|||||
|
@inject NavigationManager Navigation |
||||
|
@using System |
||||
|
|
||||
|
@code { |
||||
|
protected override void OnInitialized() |
||||
|
{ |
||||
|
Navigation.NavigateTo($"account/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}", true); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
@using Volo.Abp.UI.Navigation |
||||
|
@using MudBlazor |
||||
|
@using Microsoft.AspNetCore.Components |
||||
|
@using Microsoft.AspNetCore.Components.Routing |
||||
|
@using System |
||||
|
@{ |
||||
|
var customComponentType = MenuItem.GetComponentTypeOrDefault(); |
||||
|
} |
||||
|
|
||||
|
@if (customComponentType != null && typeof(ComponentBase).IsAssignableFrom(customComponentType)) |
||||
|
{ |
||||
|
<DynamicComponent Type="@customComponentType" /> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
<MudNavGroup Title="@MenuItem.DisplayName" Icon="@GetIcon(MenuItem.Icon)"> |
||||
|
@foreach (var item in MenuItem.Items) |
||||
|
{ |
||||
|
<MudNavLink Href="@(item.Url?.TrimStart('/', '~') ?? "#")" Match="@(item.Url != null ? NavLinkMatch.All : NavLinkMatch.Prefix)"> |
||||
|
@if (!string.IsNullOrEmpty(item.Icon)) |
||||
|
{ |
||||
|
<MudIcon Icon="@GetIcon(item.Icon)" Class="me-2" /> |
||||
|
} |
||||
|
@item.DisplayName |
||||
|
</MudNavLink> |
||||
|
} |
||||
|
</MudNavGroup> |
||||
|
} |
||||
|
|
||||
|
@code { |
||||
|
[Parameter] |
||||
|
public ApplicationMenuItem MenuItem { get; set; } = default!; |
||||
|
|
||||
|
[Inject] |
||||
|
private NavigationManager NavigationManager { get; set; } = default!; |
||||
|
|
||||
|
protected override void OnInitialized() |
||||
|
{ |
||||
|
NavigationManager.LocationChanged += OnLocationChanged; |
||||
|
} |
||||
|
|
||||
|
protected virtual void OnLocationChanged(object? sender, LocationChangedEventArgs e) |
||||
|
{ |
||||
|
// Menu will close automatically on navigation |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
NavigationManager.LocationChanged -= OnLocationChanged; |
||||
|
} |
||||
|
|
||||
|
private string? GetIcon(string? icon) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(icon)) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Convert FontAwesome icons to Material icons if needed |
||||
|
if (icon.StartsWith("fa")) |
||||
|
{ |
||||
|
// Map common FontAwesome icons to Material icons |
||||
|
return icon.Replace("fa-", "").Replace("-", "_"); |
||||
|
} |
||||
|
|
||||
|
return icon; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@implements IDisposable |
||||
@ -0,0 +1,22 @@ |
|||||
|
using Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Bundling; |
||||
|
using Volo.Abp.AspNetCore.Components.WebAssembly.Theming.MudBlazor; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using BlazorWebAssemblyStandardBundles = Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Bundling.BlazorWebAssemblyStandardBundles; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MudBlazorBasicTheme.Bundling; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpAspNetCoreComponentsWebAssemblyThemingMudBlazorModule) |
||||
|
)] |
||||
|
public class AbpAspNetCoreComponentsWebAssemblyMudBlazorBasicThemeBundlingModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpBundlingOptions>(options => |
||||
|
{ |
||||
|
var globalStyles = options.StyleBundles.Get(BlazorWebAssemblyStandardBundles.Styles.Global); |
||||
|
globalStyles.AddContributors(typeof(WebAssemblyMudBlazorBasicThemeBundleStyleContributor)); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net10.0</TargetFramework> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Components.WebAssembly.Theming.MudBlazor\Volo.Abp.AspNetCore.Components.WebAssembly.Theming.MudBlazor.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MudBlazorBasicTheme.Bundling; |
||||
|
|
||||
|
public class WebAssemblyMudBlazorBasicThemeBundleStyleContributor : BundleContributor |
||||
|
{ |
||||
|
public override void ConfigureBundle(BundleConfigurationContext context) |
||||
|
{ |
||||
|
context.Files.AddIfNotContains("_content/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/themes/basic/main.css"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
@page "/authentication/{action}" |
||||
|
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication |
||||
|
@using Volo.Abp.AspNetCore.Components.Web.Security |
||||
|
<RemoteAuthenticatorView Action="@Action" OnLogInSucceeded="OnLogInSucceeded" OnLogOutSucceeded="OnLogOutSucceeded" /> |
||||
|
@inject WebAssemblyCachedApplicationConfigurationClient WebAssemblyCachedApplicationConfigurationClient |
||||
|
@code{ |
||||
|
[Parameter] public string? Action { get; set; } |
||||
|
|
||||
|
private async Task OnLogInSucceeded(RemoteAuthenticationState state) |
||||
|
{ |
||||
|
await WebAssemblyCachedApplicationConfigurationClient.InitializeAsync(); |
||||
|
} |
||||
|
|
||||
|
private async Task OnLogOutSucceeded(RemoteAuthenticationState state) |
||||
|
{ |
||||
|
await WebAssemblyCachedApplicationConfigurationClient.InitializeAsync(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
@inject NavigationManager Navigation |
||||
|
@using Volo.Abp.DependencyInjection |
||||
|
@using Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme.Themes.Basic |
||||
|
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication |
||||
|
@using Microsoft.Extensions.Options |
||||
|
@using Volo.Abp.AspNetCore.Components.Web |
||||
|
@inherits RedirectToLogin |
||||
|
@attribute [ExposeServices(typeof(RedirectToLogin))] |
||||
|
@attribute [Dependency(ReplaceServices = true)] |
||||
|
@inject IOptions<AuthenticationOptions> AuthenticationOptions |
||||
|
@inject IOptions<AbpAspNetCoreComponentsWebOptions> AbpAspNetCoreComponentsWebOptions |
||||
|
|
||||
|
@code { |
||||
|
protected override void OnInitialized() |
||||
|
{ |
||||
|
if (AbpAspNetCoreComponentsWebOptions.Value.IsBlazorWebApp) |
||||
|
{ |
||||
|
Navigation.NavigateTo(AuthenticationOptions.Value.LoginUrl, forceLoad: true); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
Navigation.NavigateToLogin(AuthenticationOptions.Value.LoginUrl); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue