|
|
|
@ -1,7 +1,5 @@
|
|
|
|
|
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;
|
|
|
|
@ -16,39 +14,39 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theming
|
|
|
|
|
|
|
|
|
|
protected ThemingOptions Options { get; }
|
|
|
|
|
|
|
|
|
|
protected Lazy<List<ITheme>> Themes { get; }
|
|
|
|
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
|
|
|
|
|
|
public DefaultThemeManager(
|
|
|
|
|
IOptions<ThemingOptions> options,
|
|
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
|
IHttpContextAccessor httpContextAccessor)
|
|
|
|
|
IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_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;
|
|
|
|
|
var themeInfo = GetCurrentThemeInfo();
|
|
|
|
|
return (ITheme) ServiceProvider.GetRequiredService(themeInfo.ThemeType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual List<ITheme> CreateThemeList()
|
|
|
|
|
protected virtual ThemeInfo GetCurrentThemeInfo()
|
|
|
|
|
{
|
|
|
|
|
return Options.Themes.Select(t => (ITheme) ServiceProvider.GetRequiredService(t)).ToList();
|
|
|
|
|
if (!Options.Themes.Any())
|
|
|
|
|
{
|
|
|
|
|
throw new AbpException($"No theme registered! Use {nameof(ThemingOptions)} to register themes.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Options.DefaultThemeName == null)
|
|
|
|
|
{
|
|
|
|
|
return 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 themeInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|