mirror of https://github.com/abpframework/abp.git
11 changed files with 134 additions and 8 deletions
@ -0,0 +1,15 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Theming; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic |
|||
{ |
|||
public class BasicTheme : ITheme, ITransientDependency |
|||
{ |
|||
public string DefaultLayout => "~/Views/Shared/_AppLayout.cshtml"; |
|||
|
|||
public string GetLayoutOrNull(string name) |
|||
{ |
|||
return DefaultLayout; |
|||
} |
|||
} |
|||
} |
|||
@ -1,3 +1,6 @@ |
|||
@{ |
|||
Layout = "~/Views/Shared/_AppLayout.cshtml"; |
|||
} |
|||
@using Volo.Abp.AspNetCore.Mvc.UI.Theming |
|||
@inject IThemeManager ThemeManager |
|||
@{ |
|||
//TODO: Move this to a lower layer... to Shared? |
|||
Layout = ThemeManager.CurrentTheme.DefaultLayout; |
|||
} |
|||
@ -1,9 +1,12 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Theming; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars |
|||
{ |
|||
public interface IToolbarConfigurationContext : IServiceProviderAccessor |
|||
{ |
|||
ITheme Theme { get; } |
|||
|
|||
Toolbar Toolbar { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
|||
{ |
|||
public class DefaultThemeManager : IThemeManager, ITransientDependency, IServiceProviderAccessor |
|||
{ |
|||
public IServiceProvider ServiceProvider { get; } |
|||
|
|||
public ITheme CurrentTheme => GetCurrentTheme(); |
|||
|
|||
protected ThemingOptions Options { get; } |
|||
|
|||
protected Lazy<List<ITheme>> Themes { get; } |
|||
|
|||
private readonly IHttpContextAccessor _httpContextAccessor; |
|||
|
|||
public DefaultThemeManager( |
|||
IOptions<ThemingOptions> options, |
|||
IServiceProvider serviceProvider, |
|||
IHttpContextAccessor httpContextAccessor) |
|||
{ |
|||
_httpContextAccessor = httpContextAccessor; |
|||
ServiceProvider = serviceProvider; |
|||
Options = options.Value; |
|||
Themes = new Lazy<List<ITheme>>(CreateThemeList, true); |
|||
} |
|||
|
|||
protected virtual ITheme GetCurrentTheme() |
|||
{ |
|||
return Themes.Value.First(); |
|||
////TODO: Temporary code!
|
|||
|
|||
//var currentTheme = _httpContextAccessor.HttpContext.Items["_AbpCurrentTheme"] as ITheme;
|
|||
//if (currentTheme != null)
|
|||
//{
|
|||
// return currentTheme;
|
|||
//}
|
|||
|
|||
//_httpContextAccessor.HttpContext.Items["_AbpCurrentTheme"] = currentTheme = RandomHelper.GetRandomOf(Themes.Value.ToArray());
|
|||
//return currentTheme;
|
|||
} |
|||
|
|||
protected virtual List<ITheme> CreateThemeList() |
|||
{ |
|||
return Options.Themes.Select(t => (ITheme) ServiceProvider.GetRequiredService(t)).ToList(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
|||
{ |
|||
public interface ITheme |
|||
{ |
|||
string DefaultLayout { get; } |
|||
|
|||
string GetLayoutOrNull(string name); |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
|||
{ |
|||
public interface IThemeManager |
|||
{ |
|||
ITheme CurrentTheme { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
|||
{ |
|||
public class ThemingOptions |
|||
{ |
|||
public TypeList<ITheme> Themes { get; } |
|||
|
|||
public ThemingOptions() |
|||
{ |
|||
Themes = new TypeList<ITheme>(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue