Browse Source

Make all theme services support asynchronous.

Theme-Async
maliming 10 months ago
parent
commit
0de9860f5c
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 4
      docs/en/framework/ui/mvc-razor-pages/customization-user-interface.md
  2. 24
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/DefaultThemeManager.cs
  3. 26
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/DefaultThemeSelector.cs
  4. 4
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/ITheme.cs
  5. 8
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/IThemeManager.cs
  6. 8
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/IThemeSelector.cs
  7. 45
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/ThemeExtensions.cs
  8. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Areas/_ViewStart.cshtml
  9. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Account/_ViewStart.cshtml
  10. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/_ViewStart.cshtml
  11. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Views/_ViewStart.cshtml
  12. 20
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeManager.cs
  13. 26
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeSelector.cs
  14. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/ITheme.cs
  15. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/IThemeManager.cs
  16. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/IThemeSelector.cs
  17. 49
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/ThemeExtensions.cs
  18. 2
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/LoggedOut.cshtml
  19. 2
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml
  20. 2
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml
  21. 2
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/_Layout.cshtml
  22. 17
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/BasicTheme.cs
  23. 22
      modules/basic-theme/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/BasicTheme.cs
  24. 2
      modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/Default.cshtml
  25. 25
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Layouts/LayoutExtensions.cs
  26. 7
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml
  27. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/_ViewStart.cshtml
  28. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
  29. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml
  30. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Views/_ViewStart.cshtml

4
docs/en/framework/ui/mvc-razor-pages/customization-user-interface.md

@ -468,10 +468,10 @@ ABP uses the `ITheme` service to get the layout location by the layout name. You
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetLayout(StandardLayouts.Empty);
Layout = await ThemeManager.GetCurrentEmptyLayoutAsync();
}
````
This page will use the empty layout. You use `ThemeManager.CurrentTheme.GetEmptyLayout();` extension method as a shortcut.
This page will use the empty layout. You use `ThemeManager.GetCurrentEmptyLayoutAsync` extension method as a shortcut.
If you want to set the layout for all the pages under a specific folder, then write the code above in a `_ViewStart.cshtml` file under that folder.

24
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/DefaultThemeManager.cs

@ -1,16 +1,14 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
public class DefaultThemeManager : IThemeManager, IScopedDependency, IServiceProviderAccessor
{
{
public IServiceProvider ServiceProvider { get; }
public ITheme CurrentTheme => GetCurrentTheme();
private ITheme? _currentTheme;
protected IThemeSelector ThemeSelector { get; }
public DefaultThemeManager(
@ -21,14 +19,28 @@ public class DefaultThemeManager : IThemeManager, IScopedDependency, IServicePro
ThemeSelector = themeSelector;
}
[Obsolete("Use GetCurrentThemeAsync instead.")]
public ITheme CurrentTheme => GetCurrentTheme();
protected virtual ITheme GetCurrentTheme()
{
if (_currentTheme != null)
{
return _currentTheme;
}
_currentTheme = (ITheme)ServiceProvider.GetRequiredService(ThemeSelector.GetCurrentThemeInfo().ThemeType);
return CurrentTheme;
return _currentTheme;
}
public virtual async Task<ITheme> GetCurrentThemeAsync()
{
if (_currentTheme != null)
{
return _currentTheme;
}
_currentTheme = (ITheme)ServiceProvider.GetRequiredService((await ThemeSelector.GetCurrentThemeInfoAsync()).ThemeType);
return _currentTheme;
}
}

26
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/DefaultThemeSelector.cs

@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
@ -13,6 +15,7 @@ public class DefaultThemeSelector : IThemeSelector, ITransientDependency
Options = options.Value;
}
[Obsolete("Use GetCurrentThemeInfoAsync instead.")]
public virtual ThemeInfo GetCurrentThemeInfo()
{
if (!Options.Themes.Any())
@ -33,4 +36,25 @@ public class DefaultThemeSelector : IThemeSelector, ITransientDependency
return themeInfo;
}
public virtual Task<ThemeInfo> GetCurrentThemeInfoAsync()
{
if (!Options.Themes.Any())
{
throw new AbpException($"No theme registered! Use {nameof(AbpThemingOptions)} to register themes.");
}
if (Options.DefaultThemeName == null)
{
return Task.FromResult(Options.Themes.Values.First());
}
var themeInfo = Options.Themes.Values.FirstOrDefault(t => t.Name == Options.DefaultThemeName);
if (themeInfo == null)
{
throw new AbpException("Default theme is configured but it's not found in the registered themes: " + Options.DefaultThemeName);
}
return Task.FromResult(themeInfo);
}
}

4
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/ITheme.cs

@ -1,8 +1,12 @@
using System;
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
public interface ITheme
{
[Obsolete("Use GetLayoutAsync instead.")]
Type GetLayout(string name, bool fallbackToDefault = true);
Task<Type> GetLayoutAsync(string name, bool fallbackToDefault = true);
}

8
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/IThemeManager.cs

@ -1,6 +1,12 @@
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
using System;
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
public interface IThemeManager
{
[Obsolete("Use GetCurrentThemeAsync instead.")]
ITheme CurrentTheme { get; }
Task<ITheme> GetCurrentThemeAsync();
}

8
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/IThemeSelector.cs

@ -1,6 +1,12 @@
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
using System;
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
public interface IThemeSelector
{
[Obsolete("Use GetCurrentThemeInfoAsync instead.")]
ThemeInfo GetCurrentThemeInfo();
Task<ThemeInfo> GetCurrentThemeInfoAsync();
}

45
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Theming/ThemeExtensions.cs

@ -1,27 +1,72 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Components.Web.Theming.Layout;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
public static class ThemeExtensions
{
[Obsolete("Use GetApplicationLayoutAsync instead.")]
public static Type GetApplicationLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Application, fallbackToDefault);
}
[Obsolete("Use GetAccountLayoutAsync instead.")]
public static Type GetAccountLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Account, fallbackToDefault);
}
[Obsolete("Use GetPublicLayoutAsync instead.")]
public static Type GetPublicLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Public, fallbackToDefault);
}
[Obsolete("Use GetEmptyLayoutAsync instead.")]
public static Type GetEmptyLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Empty, fallbackToDefault);
}
public async static Task<Type> GetApplicationLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Application, fallbackToDefault);
}
public async static Task<Type> GetAccountLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Account, fallbackToDefault);
}
public async static Task<Type> GetPublicLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Public, fallbackToDefault);
}
public async static Task<Type> GetEmptyLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Empty, fallbackToDefault);
}
public async static Task<Type> GetCurrentApplicationLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Application, fallbackToDefault);
}
public async static Task<Type> GetCurrentAccountLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Account, fallbackToDefault);
}
public async static Task<Type> GetCurrentPublicLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Public, fallbackToDefault);
}
public async static Task<Type> GetCurrentEmptyLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Empty, fallbackToDefault);
}
}

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Areas/_ViewStart.cshtml

@ -1,5 +1,5 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
}
Layout = await ThemeManager.GetCurrentApplicationLayoutAsync();
}

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/Account/_ViewStart.cshtml

@ -1,5 +1,5 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
}
Layout = await ThemeManager.GetCurrentApplicationLayoutAsync();
}

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Pages/_ViewStart.cshtml

@ -1,5 +1,5 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
}
Layout = await ThemeManager.GetCurrentApplicationLayoutAsync();
}

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Views/_ViewStart.cshtml

@ -1,5 +1,5 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
}
Layout = await ThemeManager.GetCurrentApplicationLayoutAsync();
}

20
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeManager.cs

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
@ -10,8 +11,6 @@ public class DefaultThemeManager : IThemeManager, IScopedDependency, IServicePro
private const string CurrentThemeHttpContextKey = "__AbpCurrentTheme";
public IServiceProvider ServiceProvider { get; }
public ITheme CurrentTheme => GetCurrentTheme();
protected IThemeSelector ThemeSelector { get; }
protected IHttpContextAccessor HttpContextAccessor { get; }
@ -25,6 +24,10 @@ public class DefaultThemeManager : IThemeManager, IScopedDependency, IServicePro
ThemeSelector = themeSelector;
}
[Obsolete("Use GetCurrentThemeAsync instead.")]
public ITheme CurrentTheme => GetCurrentTheme();
[Obsolete("Use GetCurrentThemeInfoAsync instead.")]
protected virtual ITheme GetCurrentTheme()
{
var preSelectedTheme = HttpContextAccessor.HttpContext!.Items[CurrentThemeHttpContextKey] as ITheme;
@ -37,4 +40,17 @@ public class DefaultThemeManager : IThemeManager, IScopedDependency, IServicePro
return preSelectedTheme;
}
public virtual async Task<ITheme> GetCurrentThemeAsync()
{
var preSelectedTheme = HttpContextAccessor.HttpContext!.Items[CurrentThemeHttpContextKey] as ITheme;
if (preSelectedTheme == null)
{
preSelectedTheme = (ITheme)ServiceProvider.GetRequiredService((await ThemeSelector.GetCurrentThemeInfoAsync()).ThemeType);
HttpContextAccessor.HttpContext.Items[CurrentThemeHttpContextKey] = preSelectedTheme;
}
return preSelectedTheme;
}
}

26
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeSelector.cs

@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
@ -13,6 +15,7 @@ public class DefaultThemeSelector : IThemeSelector, ITransientDependency
Options = options.Value;
}
[Obsolete("Use GetCurrentThemeInfoAsync instead.")]
public virtual ThemeInfo GetCurrentThemeInfo()
{
if (!Options.Themes.Any())
@ -33,4 +36,25 @@ public class DefaultThemeSelector : IThemeSelector, ITransientDependency
return themeInfo;
}
public virtual Task<ThemeInfo> GetCurrentThemeInfoAsync()
{
if (!Options.Themes.Any())
{
throw new AbpException($"No theme registered! Use {nameof(AbpThemingOptions)} to register themes.");
}
if (Options.DefaultThemeName == null)
{
return Task.FromResult(Options.Themes.Values.First());
}
var themeInfo = Options.Themes.Values.FirstOrDefault(t => t.Name == Options.DefaultThemeName);
if (themeInfo == null)
{
throw new AbpException("Default theme is configured but it's not found in the registered themes: " + Options.DefaultThemeName);
}
return Task.FromResult(themeInfo);
}
}

8
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/ITheme.cs

@ -1,6 +1,12 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
using System;
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
public interface ITheme
{
[Obsolete("Use GetLayoutAsync instead.")]
string GetLayout(string name, bool fallbackToDefault = true);
Task<string> GetLayoutAsync(string name, bool fallbackToDefault = true);
}

8
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/IThemeManager.cs

@ -1,6 +1,12 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
using System;
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
public interface IThemeManager
{
[Obsolete("Use GetCurrentThemeAsync instead.")]
ITheme CurrentTheme { get; }
Task<ITheme> GetCurrentThemeAsync();
}

8
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/IThemeSelector.cs

@ -1,6 +1,12 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
using System;
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
public interface IThemeSelector
{
[Obsolete("Use GetCurrentThemeInfoAsync instead.")]
ThemeInfo GetCurrentThemeInfo();
Task<ThemeInfo> GetCurrentThemeInfoAsync();
}

49
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/ThemeExtensions.cs

@ -1,24 +1,71 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
using System;
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming;
public static class ThemeExtensions
{
[Obsolete("Use GetApplicationLayoutAsync instead.")]
public static string GetApplicationLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Application, fallbackToDefault);
}
[Obsolete("Use GetAccountLayoutAsync instead.")]
public static string GetAccountLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Account, fallbackToDefault);
}
[Obsolete("Use GetPublicLayoutAsync instead.")]
public static string GetPublicLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Public, fallbackToDefault);
}
[Obsolete("Use GetEmptyLayoutAsync instead.")]
public static string GetEmptyLayout(this ITheme theme, bool fallbackToDefault = true)
{
return theme.GetLayout(StandardLayouts.Empty, fallbackToDefault);
}
public async static Task<string> GetApplicationLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Application, fallbackToDefault);
}
public async static Task<string> GetAccountLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Account, fallbackToDefault);
}
public async static Task<string> GetPublicLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Public, fallbackToDefault);
}
public async static Task<string> GetEmptyLayoutAsync(this ITheme theme, bool fallbackToDefault = true)
{
return await theme.GetLayoutAsync(StandardLayouts.Empty, fallbackToDefault);
}
public async static Task<string> GetCurrentApplicationLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Application, fallbackToDefault);
}
public async static Task<string> GetCurrentAccountLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Account, fallbackToDefault);
}
public async static Task<string> GetCurrentPublicLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Public, fallbackToDefault);
}
public async static Task<string> GetCurrentEmptyLayoutAsync(this IThemeManager themeManager, bool fallbackToDefault = true)
{
return await (await themeManager.GetCurrentThemeAsync()).GetLayoutAsync(StandardLayouts.Empty, fallbackToDefault);
}
}

2
modules/account/src/Volo.Abp.Account.Web/Pages/Account/LoggedOut.cshtml

@ -7,7 +7,7 @@
@inject IThemeManager ThemeManager
@inject IHtmlLocalizer<AccountResource> L
@{
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
Layout = await ThemeManager.GetCurrentApplicationLayoutAsync();
}
@section scripts {
<abp-script-bundle name="@typeof(LoggedOutModel).FullName">

2
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml

@ -12,7 +12,7 @@
@inject Volo.Abp.Settings.ISettingProvider SettingProvider
@{
Layout = ThemeManager.CurrentTheme.GetAccountLayout();
Layout = await ThemeManager.GetCurrentAccountLayoutAsync();
}
@section scripts

2
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml

@ -7,7 +7,7 @@
@inject IHtmlLocalizer<AccountResource> L
@model ManageModel
@{
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
Layout = await ThemeManager.GetCurrentApplicationLayoutAsync();
}
@section scripts {
<abp-script-bundle name="@typeof(ManageModel).FullName"/>

2
modules/account/src/Volo.Abp.Account.Web/Pages/Account/_Layout.cshtml

@ -1,7 +1,7 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetAccountLayout();
Layout = await ThemeManager.GetCurrentAccountLayoutAsync();
}
<div class="abp-account-container">
@RenderBody()

17
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/BasicTheme.cs

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic;
using Volo.Abp.AspNetCore.Components.Web.Theming.Layout;
using Volo.Abp.AspNetCore.Components.Web.Theming.Theming;
@ -11,6 +12,7 @@ public class BasicTheme : ITheme, ITransientDependency
{
public const string Name = "Basic";
[Obsolete("Use GetLayoutAsync instead.")]
public virtual Type GetLayout(string name, bool fallbackToDefault = true)
{
switch (name)
@ -23,4 +25,17 @@ public class BasicTheme : ITheme, ITransientDependency
return fallbackToDefault ? typeof(MainLayout) : typeof(NullLayout);
}
}
}
public virtual Task<Type> GetLayoutAsync(string name, bool fallbackToDefault = true)
{
switch (name)
{
case StandardLayouts.Application:
case StandardLayouts.Account:
case StandardLayouts.Empty:
return Task.FromResult(typeof(MainLayout));
default:
return Task.FromResult(fallbackToDefault ? typeof(MainLayout) : typeof(NullLayout));
}
}
}

22
modules/basic-theme/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/BasicTheme.cs

@ -1,13 +1,16 @@
using Volo.Abp.AspNetCore.Mvc.UI.Theming;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Theming;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
[ThemeName(Name)]
public class BasicTheme : ITheme, ITransientDependency
public abstract class BasicTheme : ITheme, ITransientDependency
{
public const string Name = "Basic";
[Obsolete("Use GetLayoutAsync instead.")]
public virtual string GetLayout(string name, bool fallbackToDefault = true)
{
switch (name)
@ -22,4 +25,19 @@ public class BasicTheme : ITheme, ITransientDependency
return fallbackToDefault ? "~/Themes/Basic/Layouts/Application.cshtml" : null;
}
}
public virtual Task<string> GetLayoutAsync(string name, bool fallbackToDefault = true)
{
switch (name)
{
case StandardLayouts.Application:
return Task.FromResult("~/Themes/Basic/Layouts/Application.cshtml");
case StandardLayouts.Account:
return Task.FromResult("~/Themes/Basic/Layouts/Account.cshtml");
case StandardLayouts.Empty:
return Task.FromResult("~/Themes/Basic/Layouts/Empty.cshtml");
default:
return Task.FromResult(fallbackToDefault ? "~/Themes/Basic/Layouts/Application.cshtml" : null);
}
}
}

2
modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/Default.cshtml

@ -5,7 +5,7 @@
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetEmptyLayout();
Layout = await ThemeManager.GetCurrentEmptyLayoutAsync();
}
<div class="mt-3">@await Component.InvokeAsync(typeof(ContentFragmentViewComponent), Model)</div>

25
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Layouts/LayoutExtensions.cs

@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Theming;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Layouts;
public static class LayoutExtensions
{
private static readonly Dictionary<string, Func<ITheme, string>> LayoutFunctions = new()
public async static Task<string> GetLayoutByKeyAsync(this ITheme theme, string layoutKey)
{
[StandardLayouts.Account] = theme => theme.GetAccountLayout(),
[StandardLayouts.Public] = theme => theme.GetPublicLayout(),
[StandardLayouts.Empty] = theme => theme.GetEmptyLayout(),
};
public static string GetLayoutByKey(this ITheme theme, string layoutKey)
{
return !string.IsNullOrWhiteSpace(layoutKey) && LayoutFunctions.TryGetValue(layoutKey, out var layoutFunc)
? layoutFunc(theme)
: theme.GetApplicationLayout(); // Application layout is the default
return layoutKey switch
{
StandardLayouts.Application => await theme.GetApplicationLayoutAsync(),
StandardLayouts.Account => await theme.GetAccountLayoutAsync(),
StandardLayouts.Public => await theme.GetPublicLayoutAsync(),
StandardLayouts.Empty => await theme.GetEmptyLayoutAsync(),
_ => await theme.GetApplicationLayoutAsync()
};
}
}
}

7
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml

@ -6,14 +6,14 @@
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Layouts
@using Volo.CmsKit.Web.Pages.CmsKit.Components.Contents
@model Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Pages.IndexModel
@inject ITheme ThemeManager
@inject ITheme Theme
@{
Layout = ThemeManager.GetLayoutByKey(Model.ViewModel.LayoutName);
Layout = await Theme.GetLayoutByKeyAsync(Model.ViewModel.LayoutName);
}
@section styles{
<abp-style src="/Pages/Public/CmsKit/Pages/index.css" />
@if (!Model.ViewModel.Style.IsNullOrEmpty())
{
@ -42,4 +42,3 @@
}))
</abp-card-body>
</abp-card>

2
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/_ViewStart.cshtml

@ -1,5 +1,5 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetPublicLayout();
Layout = await ThemeManager.GetCurrentPublicLayoutAsync();
}

2
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml

@ -29,7 +29,7 @@
@model IndexModel
@{
ViewBag.FluidLayout = true;
Layout = ThemeManager.CurrentTheme.GetEmptyLayout();
Layout = await ThemeManager.GetCurrentEmptyLayoutAsync();
PageLayout.Content.Title = Model.DocumentPageTitle;
ViewBag.Description = Model.GetDescription();
ViewBag.CanonicalUrl = Model.IsLatestVersion ? null : Model.GetFullUrlOfTheLatestDocument(); //issue #12355

2
modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml

@ -9,7 +9,7 @@
@inject IPageLayout PageLayout
@model SearchModel
@{
Layout = ThemeManager.CurrentTheme.GetEmptyLayout();
Layout = await ThemeManager.GetCurrentEmptyLayoutAsync();
}
@section styles {
<style>

2
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Views/_ViewStart.cshtml

@ -1,5 +1,5 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
Layout = ThemeManager.CurrentTheme.GetAccountLayout();
Layout = await ThemeManager.GetCurrentAccountLayoutAsync();
}

Loading…
Cancel
Save