mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
CssThemeManager that injects Bootstrap css uri from settings
This commit is contained in:
parent
f869c06aee
commit
81afe397be
5 changed files with 74 additions and 24 deletions
|
@ -1,4 +1,5 @@
|
|||
using BTCPayServer.Models;
|
||||
using BTCPayServer.HostedServices;
|
||||
using BTCPayServer.Models;
|
||||
using BTCPayServer.Models.ServerViewModels;
|
||||
using BTCPayServer.Services;
|
||||
using BTCPayServer.Services.Mails;
|
||||
|
@ -21,11 +22,13 @@ namespace BTCPayServer.Controllers
|
|||
{
|
||||
private UserManager<ApplicationUser> _UserManager;
|
||||
SettingsRepository _SettingsRepository;
|
||||
private CssThemeManager _CssThemeManager;
|
||||
|
||||
public ServerController(UserManager<ApplicationUser> userManager, SettingsRepository settingsRepository)
|
||||
public ServerController(UserManager<ApplicationUser> userManager, SettingsRepository settingsRepository, CssThemeManager cssThemeManager)
|
||||
{
|
||||
_UserManager = userManager;
|
||||
_SettingsRepository = settingsRepository;
|
||||
_CssThemeManager = cssThemeManager;
|
||||
}
|
||||
|
||||
[Route("server/users")]
|
||||
|
@ -138,6 +141,9 @@ namespace BTCPayServer.Controllers
|
|||
public async Task<IActionResult> Policies(PoliciesSettings settings)
|
||||
{
|
||||
await _SettingsRepository.UpdateSetting(settings);
|
||||
// TODO: remove controller/class-level property and have only reference to
|
||||
// CssThemeManager here in this method
|
||||
_CssThemeManager.Update(settings.CustomBootstrapThemeCssUri);
|
||||
TempData["StatusMessage"] = "Policies upadated successfully";
|
||||
return View(settings);
|
||||
}
|
||||
|
|
44
BTCPayServer/HostedServices/CssThemeManager.cs
Normal file
44
BTCPayServer/HostedServices/CssThemeManager.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Logging;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using NBXplorer;
|
||||
using NBXplorer.Models;
|
||||
using System.Collections.Concurrent;
|
||||
using BTCPayServer.Events;
|
||||
using BTCPayServer.Services;
|
||||
|
||||
namespace BTCPayServer.HostedServices
|
||||
{
|
||||
public class CssThemeManager
|
||||
{
|
||||
public CssThemeManager(SettingsRepository settingsRepository)
|
||||
{
|
||||
Update(settingsRepository);
|
||||
}
|
||||
|
||||
private string _bootstrapThemeUri;
|
||||
public string BootstrapThemeUri
|
||||
{
|
||||
get { return _bootstrapThemeUri; }
|
||||
}
|
||||
|
||||
private async void Update(SettingsRepository settingsRepository)
|
||||
{
|
||||
var data = (await settingsRepository.GetSettingAsync<PoliciesSettings>()) ?? new PoliciesSettings();
|
||||
Update(data.CustomBootstrapThemeCssUri);
|
||||
}
|
||||
|
||||
public void Update(string newUri)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(newUri))
|
||||
_bootstrapThemeUri = "/vendor/bootstrap4/css/bootstrap.css";
|
||||
else
|
||||
_bootstrapThemeUri = newUri;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -136,6 +136,7 @@ namespace BTCPayServer.Hosting
|
|||
|
||||
services.TryAddSingleton<LanguageService>();
|
||||
services.TryAddSingleton<NBXplorerDashboard>();
|
||||
services.TryAddSingleton<CssThemeManager>();
|
||||
services.TryAddSingleton<StoreRepository>();
|
||||
services.TryAddSingleton<BTCPayWalletProvider>();
|
||||
services.TryAddSingleton<CurrencyNameTable>();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@inject RoleManager<IdentityRole> RoleManager
|
||||
@inject BTCPayServer.Services.BTCPayServerEnvironment env
|
||||
@inject BTCPayServer.HostedServices.NBXplorerDashboard dashboard
|
||||
@inject BTCPayServer.HostedServices.CssThemeManager themeManager
|
||||
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
@ -17,10 +18,9 @@
|
|||
<title>BTCPay Server</title>
|
||||
|
||||
@* CSS *@
|
||||
<link href="@themeManager.BootstrapThemeUri" rel="stylesheet" />
|
||||
<bundle name="wwwroot/bundles/main-bundle.min.css" />
|
||||
|
||||
|
||||
|
||||
@* JS *@
|
||||
<bundle name="wwwroot/bundles/main-bundle.min.js" />
|
||||
</head>
|
||||
|
@ -50,25 +50,25 @@
|
|||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarResponsive">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
@if(SignInManager.IsSignedIn(User))
|
||||
{
|
||||
@if(User.IsInRole(Roles.ServerAdmin))
|
||||
{
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Server" asp-action="ListUsers" class="nav-link js-scroll-trigger">Server settings</a></li>
|
||||
}
|
||||
<li class="nav-item"><a asp-area="" asp-controller="UserStores" asp-action="ListStores" class="nav-link js-scroll-trigger">Stores</a></li>
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Apps" asp-action="ListApps" class="nav-link js-scroll-trigger">Apps</a></li>
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Invoice" asp-action="ListInvoices" class="nav-link js-scroll-trigger">Invoices</a></li>
|
||||
<li class="nav-item">
|
||||
<a asp-area="" asp-controller="Manage" asp-action="Index" title="Manage" class="nav-link js-scroll-trigger">My settings</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a asp-area="" asp-controller="Account" asp- asp-action="Logout" title="Manage" class="nav-link js-scroll-trigger">Log out</a>
|
||||
</li>}
|
||||
else
|
||||
{
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="Register" class="nav-link js-scroll-trigger">Register</a></li>
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="Login" class="nav-link js-scroll-trigger">Log in</a></li>}
|
||||
@if (SignInManager.IsSignedIn(User))
|
||||
{
|
||||
@if (User.IsInRole(Roles.ServerAdmin))
|
||||
{
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Server" asp-action="ListUsers" class="nav-link js-scroll-trigger">Server settings</a></li>
|
||||
}
|
||||
<li class="nav-item"><a asp-area="" asp-controller="UserStores" asp-action="ListStores" class="nav-link js-scroll-trigger">Stores</a></li>
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Apps" asp-action="ListApps" class="nav-link js-scroll-trigger">Apps</a></li>
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Invoice" asp-action="ListInvoices" class="nav-link js-scroll-trigger">Invoices</a></li>
|
||||
<li class="nav-item">
|
||||
<a asp-area="" asp-controller="Manage" asp-action="Index" title="Manage" class="nav-link js-scroll-trigger">My settings</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a asp-area="" asp-controller="Account" asp- asp-action="Logout" title="Manage" class="nav-link js-scroll-trigger">Log out</a>
|
||||
</li>}
|
||||
else
|
||||
{
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="Register" class="nav-link js-scroll-trigger">Register</a></li>
|
||||
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="Login" class="nav-link js-scroll-trigger">Log in</a></li>}
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
{
|
||||
"outputFileName": "wwwroot/bundles/main-bundle.min.css",
|
||||
"inputFiles": [
|
||||
"wwwroot/vendor/bootstrap4/css/bootstrap.css",
|
||||
"wwwroot/vendor/magnific-popup/magnific-popup.css",
|
||||
"wwwroot/vendor/font-awesome/css/font-awesome.css",
|
||||
"wwwroot/main/**/*.css",
|
||||
|
|
Loading…
Add table
Reference in a new issue