mirror of https://github.com/abpframework/abp.git
28 changed files with 788 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||
using Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme.Bundling; |
|||
using Volo.Abp.AspNetCore.Components.Server.Theming.MudBlazor; |
|||
using Volo.Abp.AspNetCore.Components.Server.Theming.MudBlazor.Bundling; |
|||
using Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme; |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Toolbars; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreComponentsWebMudBlazorBasicThemeModule), |
|||
typeof(AbpAspNetCoreComponentsServerThemingMudBlazorModule) |
|||
)] |
|||
public class AbpAspNetCoreComponentsServerMudBlazorBasicThemeModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpToolbarOptions>(options => |
|||
{ |
|||
options.Contributors.Add(new MudBlazorBasicThemeToolbarContributor()); |
|||
}); |
|||
|
|||
Configure<AbpBundlingOptions>(options => |
|||
{ |
|||
options |
|||
.StyleBundles |
|||
.Add(BlazorMudBlazorBasicThemeBundles.Styles.Global, bundle => |
|||
{ |
|||
bundle |
|||
.AddBaseBundles(BlazorServerStandardBundles.Styles.Global) |
|||
.AddContributors(typeof(BlazorServerMudBlazorBasicThemeStyleContributor)); |
|||
}); |
|||
|
|||
options |
|||
.ScriptBundles |
|||
.Add(BlazorMudBlazorBasicThemeBundles.Scripts.Global, bundle => |
|||
{ |
|||
bundle |
|||
.AddBaseBundles(BlazorServerStandardBundles.Scripts.Global) |
|||
.AddContributors(typeof(BlazorServerMudBlazorBasicThemeScriptContributor)); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme.Bundling; |
|||
|
|||
public static class BlazorMudBlazorBasicThemeBundles |
|||
{ |
|||
public static class Styles |
|||
{ |
|||
public static string Global = "Blazor.MudBlazorBasicTheme.Global"; |
|||
} |
|||
|
|||
public static class Scripts |
|||
{ |
|||
public static string Global = "Blazor.MudBlazorBasicTheme.Global"; |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme.Bundling; |
|||
|
|||
public class BlazorServerMudBlazorBasicThemeScriptContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
// Add any theme-specific scripts here if needed
|
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme.Bundling; |
|||
|
|||
public class BlazorServerMudBlazorBasicThemeStyleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddIfNotContains("/themes/basic/main.css"); |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Toolbars; |
|||
using Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme.Themes.Basic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme; |
|||
|
|||
public class MudBlazorBasicThemeToolbarContributor : IToolbarContributor |
|||
{ |
|||
public Task ConfigureToolbarAsync(IToolbarConfigurationContext context) |
|||
{ |
|||
if (context.Toolbar.Name == StandardToolbars.Main) |
|||
{ |
|||
context.Toolbar.Items.Add(new ToolbarItem(typeof(LoginDisplay))); |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,83 @@ |
|||
@using Volo.Abp.Localization |
|||
@using System.Globalization |
|||
@using System.Collections.Immutable |
|||
@using MudBlazor |
|||
@inject ILanguageProvider LanguageProvider |
|||
@inject IJSRuntime JsRuntime |
|||
@inject ICookieService CookieService |
|||
|
|||
@if (_otherLanguages != null && _otherLanguages.Any()) |
|||
{ |
|||
<MudMenu Icon="@Icons.Material.Filled.Language"> |
|||
<MudMenuItem Disabled="true">@_currentLanguage.DisplayName</MudMenuItem> |
|||
<MudDivider /> |
|||
@foreach (var language in _otherLanguages) |
|||
{ |
|||
<MudMenuItem OnClick="@(() => ChangeLanguageAsync(language))">@language.DisplayName</MudMenuItem> |
|||
} |
|||
</MudMenu> |
|||
} |
|||
|
|||
@code { |
|||
private IReadOnlyList<LanguageInfo>? _otherLanguages; |
|||
private LanguageInfo? _currentLanguage; |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
var selectedLanguageName = await JsRuntime.InvokeAsync<string>( |
|||
"localStorage.getItem", |
|||
"Abp.SelectedLanguage" |
|||
); |
|||
|
|||
var allLanguages = await LanguageProvider.GetLanguagesAsync(); |
|||
_otherLanguages = allLanguages; |
|||
|
|||
if (!_otherLanguages.Any()) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
if (!selectedLanguageName.IsNullOrWhiteSpace()) |
|||
{ |
|||
_currentLanguage = _otherLanguages.FirstOrDefault(l => l.UiCultureName == selectedLanguageName); |
|||
} |
|||
|
|||
if (_currentLanguage == null) |
|||
{ |
|||
_currentLanguage = _otherLanguages.FirstOrDefault(l => l.UiCultureName == CultureInfo.CurrentUICulture.Name); |
|||
} |
|||
|
|||
if (_currentLanguage == null) |
|||
{ |
|||
_currentLanguage = _otherLanguages.FirstOrDefault(); |
|||
} |
|||
|
|||
_otherLanguages = _otherLanguages.Where(l => l != _currentLanguage).ToImmutableList(); |
|||
} |
|||
|
|||
private async Task ChangeLanguageAsync(LanguageInfo language) |
|||
{ |
|||
await JsRuntime.InvokeVoidAsync( |
|||
"localStorage.setItem", |
|||
"Abp.SelectedLanguage", |
|||
language.UiCultureName |
|||
); |
|||
|
|||
await JsRuntime.InvokeVoidAsync( |
|||
"localStorage.setItem", |
|||
"Abp.IsRtl", |
|||
CultureInfo.GetCultureInfo(language.UiCultureName).TextInfo.IsRightToLeft |
|||
); |
|||
|
|||
await CookieService.SetAsync( |
|||
".AspNetCore.Culture", |
|||
$"c={language.CultureName}|uic={language.UiCultureName}", |
|||
new CookieOptions |
|||
{ |
|||
Path = "/" |
|||
} |
|||
); |
|||
|
|||
await JsRuntime.InvokeVoidAsync("location.reload"); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
@namespace Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme.Themes.Basic |
|||
@using Volo.Abp.Users |
|||
@using Volo.Abp.MultiTenancy |
|||
@using Microsoft.Extensions.Localization |
|||
@using global::Localization.Resources.AbpUi |
|||
@using MudBlazor |
|||
@inject ICurrentUser CurrentUser |
|||
@inject ICurrentTenant CurrentTenant |
|||
@inject IStringLocalizer<AbpUiResource> L |
|||
|
|||
<AuthorizeView> |
|||
<Authorized> |
|||
<MudMenu Icon="@Icons.Material.Filled.AccountCircle"> |
|||
@if (Menu != null) |
|||
{ |
|||
@foreach (var menuItem in Menu.Items) |
|||
{ |
|||
<MudMenuItem Href="@menuItem.Url?.TrimStart('/', '~')" Target="@menuItem.Target">@menuItem.DisplayName</MudMenuItem> |
|||
} |
|||
} |
|||
<MudDivider /> |
|||
<MudMenuItem OnClick="@Logout">@L["Logout"]</MudMenuItem> |
|||
</MudMenu> |
|||
</Authorized> |
|||
<NotAuthorized> |
|||
<MudButton Variant="Variant.Text" Href="Account/Login">@L["Login"]</MudButton> |
|||
</NotAuthorized> |
|||
</AuthorizeView> |
|||
|
|||
@code { |
|||
[Inject] protected NavigationManager Navigation { get; set; } = default!; |
|||
[Inject] protected IMenuManager MenuManager { get; set; } = default!; |
|||
|
|||
protected ApplicationMenu? Menu { get; set; } |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
Menu = await MenuManager.GetAsync(StandardMenus.User); |
|||
} |
|||
|
|||
protected void Logout() |
|||
{ |
|||
Navigation.NavigateTo("/Account/Logout", forceLoad: true); |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
@using Microsoft.AspNetCore.Components.Web |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor |
|||
@using MudBlazor |
|||
@using Volo.Abp.MudBlazorUI |
|||
@ -0,0 +1,19 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net10.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Components.Server.Theming.MudBlazor\Volo.Abp.AspNetCore.Components.Server.Theming.MudBlazor.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme\Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,24 @@ |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor; |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.Theming; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreComponentsWebThemingMudBlazorModule) |
|||
)] |
|||
public class AbpAspNetCoreComponentsWebMudBlazorBasicThemeModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpThemingOptions>(options => |
|||
{ |
|||
options.Themes.Add<MudBlazorBasicTheme>(); |
|||
|
|||
if (options.DefaultThemeName == null) |
|||
{ |
|||
options.DefaultThemeName = MudBlazorBasicTheme.Name; |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.Theming; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme; |
|||
|
|||
public class MudBlazorBasicTheme : ITheme |
|||
{ |
|||
public static string Name = "MudBlazorBasic"; |
|||
|
|||
public string GetLayout(string name, bool fallbackToDefault = true) |
|||
{ |
|||
switch (name) |
|||
{ |
|||
case StandardLayouts.Application: |
|||
return "~/Themes/Basic/MainLayout"; |
|||
case StandardLayouts.Account: |
|||
return "~/Themes/Basic/MainLayout"; |
|||
case StandardLayouts.Empty: |
|||
return "~/Themes/Basic/NullLayout"; |
|||
default: |
|||
return fallbackToDefault ? "~/Themes/Basic/MainLayout" : null; |
|||
} |
|||
} |
|||
|
|||
public string GetStyle(string name, bool fallbackToDefault = true) |
|||
{ |
|||
switch (name) |
|||
{ |
|||
case StandardStyles.Global: |
|||
return "~/themes/basic/main.css"; |
|||
default: |
|||
return fallbackToDefault ? "~/themes/basic/main.css" : null; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
@using Volo.Abp.Ui.Branding |
|||
@inject IBrandingProvider BrandingProvider |
|||
|
|||
<MudText Typo="Typo.h6" Class="ma-0">@BrandingProvider.AppName</MudText> |
|||
@ -0,0 +1,27 @@ |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Components |
|||
@using Volo.Abp.Users |
|||
@inject ICurrentUser CurrentUser |
|||
|
|||
@if (CurrentUser.IsAuthenticated) |
|||
{ |
|||
<MudMenu Icon="@Icons.Material.Filled.AccountCircle"> |
|||
<MudMenuItem Href="/Account/Manage">@L["MyAccount"]</MudMenuItem> |
|||
<MudDivider /> |
|||
<MudMenuItem OnClick="@Logout">@L["Logout"]</MudMenuItem> |
|||
</MudMenu> |
|||
} |
|||
else |
|||
{ |
|||
<MudButton Variant="Variant.Text" Href="/Account/Login">@L["Login"]</MudButton> |
|||
} |
|||
|
|||
@code { |
|||
[Inject] protected NavigationManager NavigationManager { get; set; } = default!; |
|||
[Inject] protected IAbpLazyServiceProvider LazyServiceProvider { get; set; } = default!; |
|||
|
|||
protected async Task Logout() |
|||
{ |
|||
// TODO: Implement logout logic |
|||
NavigationManager.NavigateTo("/Account/Logout", forceLoad: true); |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
@using Volo.Abp.Ui.LayoutHooks |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Components.LayoutHooks |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Components |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.Layout |
|||
@inherits LayoutComponentBase |
|||
|
|||
<MudThemeProvider /> |
|||
<MudPopoverProvider /> |
|||
<MudDialogProvider /> |
|||
<MudSnackbarProvider /> |
|||
|
|||
<MudLayout> |
|||
<MudAppBar Elevation="1"> |
|||
<MudIconButton Icon="@Icons.Material.Filled.Menu" |
|||
Color="Color.Inherit" |
|||
Edge="Edge.Start" |
|||
OnClick="@ToggleDrawer" /> |
|||
<Branding /> |
|||
<MudSpacer /> |
|||
<NavToolbar /> |
|||
</MudAppBar> |
|||
|
|||
<MudDrawer @bind-Open="@_drawerOpen" |
|||
Elevation="1" |
|||
Variant="@DrawerVariant.Mini"> |
|||
<NavMenu /> |
|||
</MudDrawer> |
|||
|
|||
<MudMainContent> |
|||
<MudContainer MaxWidth="MaxWidth.False" Class="pa-4"> |
|||
<PageAlert /> |
|||
<LayoutHook Name="@LayoutHooks.Body.First" Layout="@StandardLayouts.Application" /> |
|||
@Body |
|||
<LayoutHook Name="@LayoutHooks.Body.Last" Layout="@StandardLayouts.Application" /> |
|||
<DynamicLayoutComponent /> |
|||
<UiMessageAlert /> |
|||
<UiNotificationAlert /> |
|||
<UiPageProgress /> |
|||
</MudContainer> |
|||
</MudMainContent> |
|||
</MudLayout> |
|||
|
|||
@code { |
|||
private bool _drawerOpen = true; |
|||
|
|||
private void ToggleDrawer() |
|||
{ |
|||
_drawerOpen = !_drawerOpen; |
|||
} |
|||
} |
|||
|
|||
@implements IDisposable |
|||
@ -0,0 +1,33 @@ |
|||
@using Volo.Abp.UI.Navigation |
|||
@inject IMenuManager MenuManager |
|||
|
|||
<MudNavMenu> |
|||
@foreach (var menuItem in MenuItems.Items) |
|||
{ |
|||
@if (menuItem.Items.IsNullOrEmpty()) |
|||
{ |
|||
<MudNavLink Href="@menuItem.Url" Match="@(menuItem.Url != null ? NavLinkMatch.All : NavLinkMatch.Prefix)"> |
|||
@if (!string.IsNullOrEmpty(menuItem.Icon)) |
|||
{ |
|||
<MudIcon Icon="@menuItem.Icon" Class="me-2" /> |
|||
} |
|||
@menuItem.DisplayName |
|||
</MudNavLink> |
|||
} |
|||
else |
|||
{ |
|||
<MudNavGroup Title="@menuItem.DisplayName" Icon="@menuItem.Icon"> |
|||
@foreach (var childItem in menuItem.Items) |
|||
{ |
|||
<MudNavLink Href="@childItem.Url" Match="@(childItem.Url != null ? NavLinkMatch.All : NavLinkMatch.Prefix)"> |
|||
@if (!string.IsNullOrEmpty(childItem.Icon)) |
|||
{ |
|||
<MudIcon Icon="@childItem.Icon" Class="me-2" /> |
|||
} |
|||
@childItem.DisplayName |
|||
</MudNavLink> |
|||
} |
|||
</MudNavGroup> |
|||
} |
|||
} |
|||
</MudNavMenu> |
|||
@ -0,0 +1,14 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.UI.Navigation; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme.Themes.Basic; |
|||
|
|||
public partial class NavMenu |
|||
{ |
|||
protected ApplicationMenu MenuItems { get; set; } = new(); |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
MenuItems = await MenuManager.GetMainMenuAsync(); |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Toolbars |
|||
@using Volo.Abp.AspNetCore.Components.Web.Security |
|||
@using System.Collections.Generic |
|||
@using System |
|||
@using Microsoft.AspNetCore.Components |
|||
|
|||
@implements IDisposable |
|||
|
|||
@foreach (var render in ToolbarItemRenders) |
|||
{ |
|||
@render |
|||
} |
|||
|
|||
@code { |
|||
[Inject] |
|||
private IToolbarManager ToolbarManager { get; set; } = default!; |
|||
|
|||
[Inject] |
|||
protected ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; } = default!; |
|||
|
|||
private List<RenderFragment> ToolbarItemRenders { get; set; } = new List<RenderFragment>(); |
|||
|
|||
protected async override Task OnInitializedAsync() |
|||
{ |
|||
await GetToolbarItemRendersAsync(); |
|||
ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged; |
|||
} |
|||
|
|||
private async Task GetToolbarItemRendersAsync() |
|||
{ |
|||
var toolbar = await ToolbarManager.GetAsync(StandardToolbars.Main); |
|||
|
|||
ToolbarItemRenders.Clear(); |
|||
|
|||
var sequence = 0; |
|||
foreach (var item in toolbar.Items) |
|||
{ |
|||
ToolbarItemRenders.Add(builder => |
|||
{ |
|||
builder.OpenComponent(sequence++, item.ComponentType); |
|||
builder.CloseComponent(); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
private async void ApplicationConfigurationChanged() |
|||
{ |
|||
await GetToolbarItemRendersAsync(); |
|||
await InvokeAsync(StateHasChanged); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged; |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
@using Volo.Abp.Ui.LayoutHooks |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Components.LayoutHooks |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.Layout |
|||
@inherits LayoutComponentBase |
|||
|
|||
<MudThemeProvider /> |
|||
<MudPopoverProvider /> |
|||
<MudDialogProvider /> |
|||
<MudSnackbarProvider /> |
|||
|
|||
<MudLayout> |
|||
<MudMainContent> |
|||
<LayoutHook Name="@LayoutHooks.Body.First" Layout="@StandardLayouts.Empty" /> |
|||
@Body |
|||
<LayoutHook Name="@LayoutHooks.Body.Last" Layout="@StandardLayouts.Empty" /> |
|||
<DynamicLayoutComponent /> |
|||
<UiMessageAlert /> |
|||
<UiNotificationAlert /> |
|||
<UiPageProgress /> |
|||
</MudMainContent> |
|||
</MudLayout> |
|||
@ -0,0 +1,4 @@ |
|||
@using Microsoft.AspNetCore.Components.Web |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor |
|||
@using MudBlazor |
|||
@using Volo.Abp.MudBlazorUI |
|||
@ -0,0 +1,14 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net10.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor\Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,3 @@ |
|||
/* MudBlazor Basic Theme Styles */ |
|||
|
|||
/* Add any custom theme-specific styles here */ |
|||
@ -0,0 +1,40 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.AspNetCore.Components.Web; |
|||
using Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme; |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Routing; |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Toolbars; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly.Theming.MudBlazor; |
|||
using Volo.Abp.Http.Client.IdentityModel.WebAssembly; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MudBlazorBasicTheme; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreComponentsWebMudBlazorBasicThemeModule), |
|||
typeof(AbpAspNetCoreComponentsWebAssemblyThemingMudBlazorModule), |
|||
typeof(AbpHttpClientIdentityModelWebAssemblyModule) |
|||
)] |
|||
public class AbpAspNetCoreComponentsWebAssemblyMudBlazorBasicThemeModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpRouterOptions>(options => |
|||
{ |
|||
options.AdditionalAssemblies.Add(typeof(AbpAspNetCoreComponentsWebAssemblyMudBlazorBasicThemeModule).Assembly); |
|||
}); |
|||
|
|||
Configure<AbpToolbarOptions>(options => |
|||
{ |
|||
options.Contributors.Add(new MudBlazorBasicThemeToolbarContributor()); |
|||
}); |
|||
|
|||
if (context.Services.ExecutePreConfiguredActions<AbpAspNetCoreComponentsWebOptions>().IsBlazorWebApp) |
|||
{ |
|||
Configure<AuthenticationOptions>(options => |
|||
{ |
|||
options.LoginUrl = "Account/Login"; |
|||
options.LogoutUrl = "Account/Logout"; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MudBlazorBasicTheme; |
|||
|
|||
public class AuthenticationOptions |
|||
{ |
|||
public string LoginUrl { get; set; } = "Account/Login"; |
|||
|
|||
public string LogoutUrl { get; set; } = "Account/Logout"; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor.Toolbars; |
|||
using Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme.Themes.Basic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MudBlazorBasicTheme; |
|||
|
|||
public class MudBlazorBasicThemeToolbarContributor : IToolbarContributor |
|||
{ |
|||
public Task ConfigureToolbarAsync(IToolbarConfigurationContext context) |
|||
{ |
|||
if (context.Toolbar.Name == StandardToolbars.Main) |
|||
{ |
|||
context.Toolbar.Items.Add(new ToolbarItem(typeof(LoginDisplay))); |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
@using Volo.Abp.Localization |
|||
@using System.Globalization |
|||
@using System.Collections.Immutable |
|||
@using Volo.Abp.AspNetCore.Components.Web |
|||
@using MudBlazor |
|||
@inject ILanguageProvider LanguageProvider |
|||
@inject IJSRuntime JsRuntime |
|||
@inject ICookieService CookieService |
|||
|
|||
@if (_otherLanguages != null && _otherLanguages.Any()) |
|||
{ |
|||
<MudMenu Icon="@Icons.Material.Filled.Language"> |
|||
<MudMenuItem Disabled="true">@_currentLanguage.DisplayName</MudMenuItem> |
|||
<MudDivider /> |
|||
@foreach (var language in _otherLanguages) |
|||
{ |
|||
<MudMenuItem OnClick="@(() => ChangeLanguageAsync(language))">@language.DisplayName</MudMenuItem> |
|||
} |
|||
</MudMenu> |
|||
} |
|||
|
|||
@code { |
|||
private IReadOnlyList<LanguageInfo>? _otherLanguages; |
|||
private LanguageInfo? _currentLanguage; |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
var selectedLanguageName = await JsRuntime.InvokeAsync<string>( |
|||
"localStorage.getItem", |
|||
"Abp.SelectedLanguage" |
|||
); |
|||
|
|||
var allLanguages = await LanguageProvider.GetLanguagesAsync(); |
|||
_otherLanguages = allLanguages; |
|||
|
|||
if (!_otherLanguages.Any()) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
if (!selectedLanguageName.IsNullOrWhiteSpace()) |
|||
{ |
|||
_currentLanguage = _otherLanguages.FirstOrDefault(l => l.UiCultureName == selectedLanguageName); |
|||
} |
|||
|
|||
if (_currentLanguage == null) |
|||
{ |
|||
_currentLanguage = _otherLanguages.FirstOrDefault(l => l.UiCultureName == CultureInfo.CurrentUICulture.Name); |
|||
} |
|||
|
|||
if (_currentLanguage == null) |
|||
{ |
|||
_currentLanguage = _otherLanguages.FirstOrDefault(); |
|||
} |
|||
|
|||
_otherLanguages = _otherLanguages.Where(l => l != _currentLanguage).ToImmutableList(); |
|||
} |
|||
|
|||
private async Task ChangeLanguageAsync(LanguageInfo language) |
|||
{ |
|||
await JsRuntime.InvokeVoidAsync( |
|||
"localStorage.setItem", |
|||
"Abp.SelectedLanguage", |
|||
language.UiCultureName |
|||
); |
|||
|
|||
await JsRuntime.InvokeVoidAsync( |
|||
"localStorage.setItem", |
|||
"Abp.IsRtl", |
|||
CultureInfo.GetCultureInfo(language.UiCultureName).TextInfo.IsRightToLeft |
|||
); |
|||
|
|||
await CookieService.SetAsync( |
|||
".AspNetCore.Culture", |
|||
$"c={language.CultureName}|uic={language.UiCultureName}", |
|||
new CookieOptions |
|||
{ |
|||
Path = "/" |
|||
} |
|||
); |
|||
|
|||
await JsRuntime.InvokeVoidAsync("location.reload"); |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
@using Microsoft.Extensions.Localization |
|||
@using global::Localization.Resources.AbpUi |
|||
@using Microsoft.Extensions.Options |
|||
@using Volo.Abp.AspNetCore.Components.Web |
|||
@using Volo.Abp.AspNetCore.Components.WebAssembly.MudBlazorBasicTheme |
|||
@using MudBlazor |
|||
@inherits AbpComponentBase |
|||
@inject IJSRuntime JsRuntime |
|||
@inject NavigationManager Navigation |
|||
@inject IStringLocalizer<AbpUiResource> UiLocalizer |
|||
@inject IOptions<AuthenticationOptions> AuthenticationOptions |
|||
@inject IOptions<AbpAspNetCoreComponentsWebOptions> AbpAspNetCoreComponentsWebOptions |
|||
|
|||
<AuthorizeView> |
|||
<Authorized> |
|||
<MudMenu Icon="@Icons.Material.Filled.AccountCircle"> |
|||
@if (Menu != null) |
|||
{ |
|||
@foreach (var menuItem in Menu.Items) |
|||
{ |
|||
<MudMenuItem OnClick="@(() => NavigateToAsync(menuItem.Url, menuItem.Target))">@menuItem.DisplayName</MudMenuItem> |
|||
} |
|||
} |
|||
<MudDivider /> |
|||
<MudMenuItem OnClick="BeginSignOut">@UiLocalizer["Logout"]</MudMenuItem> |
|||
</MudMenu> |
|||
</Authorized> |
|||
<NotAuthorized> |
|||
<MudButton Variant="Variant.Text" Href="@AuthenticationOptions.Value.LoginUrl">@UiLocalizer["Login"]</MudButton> |
|||
</NotAuthorized> |
|||
</AuthorizeView> |
|||
|
|||
@code { |
|||
[Inject] protected IMenuManager MenuManager { get; set; } = default!; |
|||
[Inject] protected ApplicationConfigurationChangedService ApplicationConfigurationChangedService { get; set; } = default!; |
|||
|
|||
protected ApplicationMenu? Menu { get; set; } |
|||
|
|||
protected async override Task OnInitializedAsync() |
|||
{ |
|||
Menu = await MenuManager.GetAsync(StandardMenus.User); |
|||
ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged; |
|||
} |
|||
|
|||
private async void ApplicationConfigurationChanged() |
|||
{ |
|||
Menu = await MenuManager.GetAsync(StandardMenus.User); |
|||
await InvokeAsync(StateHasChanged); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
ApplicationConfigurationChangedService.Changed -= ApplicationConfigurationChanged; |
|||
} |
|||
|
|||
private async Task NavigateToAsync(string? uri, string? target = null) |
|||
{ |
|||
if (target == "_blank") |
|||
{ |
|||
await JsRuntime.InvokeVoidAsync("open", uri, target); |
|||
} |
|||
else |
|||
{ |
|||
Navigation.NavigateTo(uri); |
|||
} |
|||
} |
|||
|
|||
private void BeginSignOut() |
|||
{ |
|||
if (AbpAspNetCoreComponentsWebOptions.Value.IsBlazorWebApp) |
|||
{ |
|||
Navigation.NavigateTo(AuthenticationOptions.Value.LogoutUrl, forceLoad: true); |
|||
} |
|||
else |
|||
{ |
|||
Navigation.NavigateToLogout(AuthenticationOptions.Value.LogoutUrl); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
@using Microsoft.AspNetCore.Components.Web |
|||
@using Volo.Abp.AspNetCore.Components.Web.Theming.MudBlazor |
|||
@using MudBlazor |
|||
@using Volo.Abp.MudBlazorUI |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net10.0</TargetFramework> |
|||
<PackageId>Volo.Abp.AspNetCore.Components.WebAssembly.MudBlazorBasicTheme</PackageId> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme\Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Components.WebAssembly.Theming.MudBlazor\Volo.Abp.AspNetCore.Components.WebAssembly.Theming.MudBlazor.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Http.Client.IdentityModel.WebAssembly\Volo.Abp.Http.Client.IdentityModel.WebAssembly.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
Loading…
Reference in new issue