mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
CssThemeManager that injects Bootstrap css uri from settings
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using BTCPayServer.Models;
|
using BTCPayServer.HostedServices;
|
||||||
|
using BTCPayServer.Models;
|
||||||
using BTCPayServer.Models.ServerViewModels;
|
using BTCPayServer.Models.ServerViewModels;
|
||||||
using BTCPayServer.Services;
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.Services.Mails;
|
using BTCPayServer.Services.Mails;
|
||||||
@@ -21,11 +22,13 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
private UserManager<ApplicationUser> _UserManager;
|
private UserManager<ApplicationUser> _UserManager;
|
||||||
SettingsRepository _SettingsRepository;
|
SettingsRepository _SettingsRepository;
|
||||||
|
private CssThemeManager _CssThemeManager;
|
||||||
|
|
||||||
public ServerController(UserManager<ApplicationUser> userManager, SettingsRepository settingsRepository)
|
public ServerController(UserManager<ApplicationUser> userManager, SettingsRepository settingsRepository, CssThemeManager cssThemeManager)
|
||||||
{
|
{
|
||||||
_UserManager = userManager;
|
_UserManager = userManager;
|
||||||
_SettingsRepository = settingsRepository;
|
_SettingsRepository = settingsRepository;
|
||||||
|
_CssThemeManager = cssThemeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("server/users")]
|
[Route("server/users")]
|
||||||
@@ -138,6 +141,9 @@ namespace BTCPayServer.Controllers
|
|||||||
public async Task<IActionResult> Policies(PoliciesSettings settings)
|
public async Task<IActionResult> Policies(PoliciesSettings settings)
|
||||||
{
|
{
|
||||||
await _SettingsRepository.UpdateSetting(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";
|
TempData["StatusMessage"] = "Policies upadated successfully";
|
||||||
return View(settings);
|
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<LanguageService>();
|
||||||
services.TryAddSingleton<NBXplorerDashboard>();
|
services.TryAddSingleton<NBXplorerDashboard>();
|
||||||
|
services.TryAddSingleton<CssThemeManager>();
|
||||||
services.TryAddSingleton<StoreRepository>();
|
services.TryAddSingleton<StoreRepository>();
|
||||||
services.TryAddSingleton<BTCPayWalletProvider>();
|
services.TryAddSingleton<BTCPayWalletProvider>();
|
||||||
services.TryAddSingleton<CurrencyNameTable>();
|
services.TryAddSingleton<CurrencyNameTable>();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
@inject RoleManager<IdentityRole> RoleManager
|
@inject RoleManager<IdentityRole> RoleManager
|
||||||
@inject BTCPayServer.Services.BTCPayServerEnvironment env
|
@inject BTCPayServer.Services.BTCPayServerEnvironment env
|
||||||
@inject BTCPayServer.HostedServices.NBXplorerDashboard dashboard
|
@inject BTCPayServer.HostedServices.NBXplorerDashboard dashboard
|
||||||
|
@inject BTCPayServer.HostedServices.CssThemeManager themeManager
|
||||||
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
|
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -17,10 +18,9 @@
|
|||||||
<title>BTCPay Server</title>
|
<title>BTCPay Server</title>
|
||||||
|
|
||||||
@* CSS *@
|
@* CSS *@
|
||||||
|
<link href="@themeManager.BootstrapThemeUri" rel="stylesheet" />
|
||||||
<bundle name="wwwroot/bundles/main-bundle.min.css" />
|
<bundle name="wwwroot/bundles/main-bundle.min.css" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@* JS *@
|
@* JS *@
|
||||||
<bundle name="wwwroot/bundles/main-bundle.min.js" />
|
<bundle name="wwwroot/bundles/main-bundle.min.js" />
|
||||||
</head>
|
</head>
|
||||||
@@ -50,12 +50,12 @@
|
|||||||
</button>
|
</button>
|
||||||
<div class="collapse navbar-collapse" id="navbarResponsive">
|
<div class="collapse navbar-collapse" id="navbarResponsive">
|
||||||
<ul class="navbar-nav ml-auto">
|
<ul class="navbar-nav ml-auto">
|
||||||
@if(SignInManager.IsSignedIn(User))
|
@if (SignInManager.IsSignedIn(User))
|
||||||
|
{
|
||||||
|
@if (User.IsInRole(Roles.ServerAdmin))
|
||||||
{
|
{
|
||||||
@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="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="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="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="Invoice" asp-action="ListInvoices" class="nav-link js-scroll-trigger">Invoices</a></li>
|
||||||
@@ -65,8 +65,8 @@
|
|||||||
<li class="nav-item">
|
<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>
|
<a asp-area="" asp-controller="Account" asp- asp-action="Logout" title="Manage" class="nav-link js-scroll-trigger">Log out</a>
|
||||||
</li>}
|
</li>}
|
||||||
else
|
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="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>}
|
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="Login" class="nav-link js-scroll-trigger">Log in</a></li>}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
{
|
{
|
||||||
"outputFileName": "wwwroot/bundles/main-bundle.min.css",
|
"outputFileName": "wwwroot/bundles/main-bundle.min.css",
|
||||||
"inputFiles": [
|
"inputFiles": [
|
||||||
"wwwroot/vendor/bootstrap4/css/bootstrap.css",
|
|
||||||
"wwwroot/vendor/magnific-popup/magnific-popup.css",
|
"wwwroot/vendor/magnific-popup/magnific-popup.css",
|
||||||
"wwwroot/vendor/font-awesome/css/font-awesome.css",
|
"wwwroot/vendor/font-awesome/css/font-awesome.css",
|
||||||
"wwwroot/main/**/*.css",
|
"wwwroot/main/**/*.css",
|
||||||
|
|||||||
Reference in New Issue
Block a user