Refactoring pills navigation

This commit is contained in:
lepipele 2018-04-19 11:40:12 -05:00
parent 97b59be9bf
commit 8075273ec8
8 changed files with 25 additions and 43 deletions

View File

@ -15,11 +15,5 @@ namespace BTCPayServer.Services
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool LockSubscription { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public string BootstrapCssUri { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public string CreativeStartCssUri { get; set; }
}
}

View File

@ -1,7 +1,6 @@
@model EmailsViewModel
@{
ViewData["Title"] = ServerNavPages.Emails;
ViewData.AddActivePage(ServerNavPages.Emails);
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Emails);
}

View File

@ -1,7 +1,6 @@
@model UsersViewModel
@{
ViewData["Title"] = "Users";
ViewData.AddActivePage(ServerNavPages.Users);
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Users);
}

View File

@ -1,7 +1,6 @@
@model BTCPayServer.Services.PoliciesSettings
@{
ViewData["Title"] = ServerNavPages.Policies;
ViewData.AddActivePage(ServerNavPages.Policies);
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Policies);
}

View File

@ -1,7 +1,6 @@
@model RatesViewModel
@{
ViewData["Title"] = ServerNavPages.Rates;
ViewData.AddActivePage(ServerNavPages.Rates);
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Rates);
}

View File

@ -9,30 +9,22 @@ namespace BTCPayServer.Views.Server
{
public static class ServerNavPages
{
public static string ActivePageKey => "ActivePage";
public static string Index => "Index";
public static string Users => "Users";
public static string Rates => "Rates";
public static string Emails => "Email server";
public static string Policies => "Policies";
public static string Hangfire => "Hangfire";
public static string UsersNavClass(ViewContext viewContext) => PageNavClass(viewContext, Users);
public static string EmailsNavClass(ViewContext viewContext) => PageNavClass(viewContext, Emails);
public static string RatesNavClass(ViewContext viewContext) => PageNavClass(viewContext, Rates);
public static string PoliciesNavClass(ViewContext viewContext) => PageNavClass(viewContext, Policies);
public static string HangfireNavClass(ViewContext viewContext) => PageNavClass(viewContext, Hangfire);
public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);
public static string PageNavClass(ViewContext viewContext, string page)
public enum Pages
{
var activePage = viewContext.ViewData["ActivePage"] as string;
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null;
Index, Users, Rates, Emails, Policies, Theme, Hangfire
}
public static void AddActivePage(this ViewDataDictionary viewData, string activePage) => viewData[ActivePageKey] = activePage;
public const string ACTIVE_PAGE_KEY = "ActivePage";
public static void SetActivePageAndTitle(this ViewDataDictionary viewData, Pages activePage, string titleOverride = null)
{
viewData["Title"] = titleOverride ?? 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;
}
}
}

View File

@ -1,7 +1,6 @@
@model UserViewModel
@{
ViewData["Title"] = Model.Email;
ViewData.AddActivePage(ServerNavPages.Users);
ViewData.SetActivePageAndTitle(ServerNavPages.Pages.Users, Model.Email);
}

View File

@ -1,10 +1,11 @@
@using BTCPayServer.Views.Server
<div class="nav flex-column nav-pills">
<a class="nav-link @ServerNavPages.UsersNavClass(ViewContext)" asp-action="Users">Users</a>
<a class="nav-link @ServerNavPages.RatesNavClass(ViewContext)" asp-action="Rates">Rates</a>
<a class="nav-link @ServerNavPages.EmailsNavClass(ViewContext)" asp-action="Emails">Email server</a>
<a class="nav-link @ServerNavPages.PoliciesNavClass(ViewContext)" asp-action="Policies">Policies</a>
<a class="nav-link @ServerNavPages.HangfireNavClass(ViewContext)" href="~/hangfire" target="_blank">Hangfire</a>
<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>