mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 21:32:27 +01:00
Abstracting navigation so it can use any enums
This commit is contained in:
parent
0934bebf7b
commit
76cd9a7b25
@ -1,6 +1,6 @@
|
||||
@model EmailsViewModel
|
||||
@{
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Emails);
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Emails);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
@model UsersViewModel
|
||||
@{
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Users);
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Users);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
@model BTCPayServer.Services.PoliciesSettings
|
||||
@{
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Policies);
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Policies);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
@model RatesViewModel
|
||||
@{
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Rates);
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Rates);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
namespace BTCPayServer.Views.Server
|
||||
{
|
||||
public static class ServerNavPages
|
||||
{
|
||||
public enum Pages
|
||||
{
|
||||
Index, Users, Rates, Emails, Policies, Theme, Hangfire
|
||||
}
|
||||
|
||||
public const string ACTIVE_PAGE_KEY = "ActivePage";
|
||||
public static void SetActivePageAndTitle(this ViewDataDictionary viewData, Pages activePage)
|
||||
{
|
||||
viewData["Title"] = activePage.ToString();
|
||||
viewData[ACTIVE_PAGE_KEY] = activePage;
|
||||
}
|
||||
|
||||
public static string IsActivePage(this ViewDataDictionary viewData, Pages page)
|
||||
{
|
||||
var activePage = viewData[ACTIVE_PAGE_KEY] as Pages?;
|
||||
return activePage == page ? "active" : null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
@model BTCPayServer.Services.ThemeSettings
|
||||
@{
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Theme);
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Theme);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
@model UserViewModel
|
||||
@{
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Users);
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Users);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
@using BTCPayServer.Views.Server
|
||||
|
||||
<div class="nav flex-column nav-pills">
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Pages.Users)" asp-action="Users">Users</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Pages.Rates)" asp-action="Rates">Rates</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Pages.Emails)" asp-action="Emails">Email server</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Pages.Policies)" asp-action="Policies">Policies</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Pages.Theme)" asp-action="Theme">Theme</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Pages.Hangfire)" href="~/hangfire" target="_blank">Hangfire</a>
|
||||
<div class="nav flex-column nav-pills">
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Users)" asp-action="Users">Users</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Rates)" asp-action="Rates">Rates</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Emails)" asp-action="Emails">Email server</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Policies)" asp-action="Policies">Policies</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Theme)" asp-action="Theme">Theme</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(ServerNavPages.Hangfire)" href="~/hangfire" target="_blank">Hangfire</a>
|
||||
</div>
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
@using BTCPayServer.Views.Server
|
||||
@using BTCPayServer.Models.ServerViewModels
|
||||
@using BTCPayServer.Models.ServerViewModels
|
||||
|
31
BTCPayServer/Views/ViewsRazor.cs
Normal file
31
BTCPayServer/Views/ViewsRazor.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
namespace BTCPayServer.Views
|
||||
{
|
||||
public static class ViewsRazor
|
||||
{
|
||||
public const string ACTIVE_PAGE_KEY = "ActivePage";
|
||||
public static void SetActivePageAndTitle<T>(this ViewDataDictionary viewData, T activePage)
|
||||
where T : IConvertible
|
||||
{
|
||||
viewData["Title"] = activePage.ToString();
|
||||
viewData[ACTIVE_PAGE_KEY] = activePage;
|
||||
}
|
||||
|
||||
public static string IsActivePage<T>(this ViewDataDictionary viewData, T page)
|
||||
where T : IConvertible
|
||||
{
|
||||
var activePage = (T)viewData[ACTIVE_PAGE_KEY];
|
||||
return page.Equals(activePage) ? "active" : null;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ServerNavPages
|
||||
{
|
||||
Index, Users, Rates, Emails, Policies, Theme, Hangfire
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using BTCPayServer
|
||||
@using BTCPayServer.Views
|
||||
@using BTCPayServer.Models
|
||||
@using BTCPayServer.Models.AccountViewModels
|
||||
@using BTCPayServer.Models.InvoicingModels
|
||||
|
Loading…
Reference in New Issue
Block a user