Refactor nav pages, add page to see users of the server

This commit is contained in:
NicolasDorier 2017-09-16 01:15:17 +09:00
parent 6240abbb7b
commit eb9f669224
26 changed files with 176 additions and 63 deletions

View file

@ -0,0 +1,34 @@
using BTCPayServer.Models;
using BTCPayServer.Models.ServerViewModels;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BTCPayServer.Controllers
{
public class ServerController : Controller
{
private UserManager<ApplicationUser> _UserManager;
public ServerController(UserManager<ApplicationUser> userManager)
{
_UserManager = userManager;
}
[Route("server/users")]
public IActionResult ListUsers()
{
var users = new UsersViewModel();
users.Users
= _UserManager.Users.Select(u => new UsersViewModel.UserViewModel()
{
Name = u.UserName,
Email = u.Email
}).ToList();
return View(users);
}
}
}

View file

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BTCPayServer.Models.ServerViewModels
{
public class UsersViewModel
{
public class UserViewModel
{
public string Name
{
get; set;
}
public string Email
{
get; set;
}
}
public string StatusMessage
{
get; set;
}
public List<UserViewModel> Users
{
get; set;
} = new List<UserViewModel>();
}
}

View file

@ -12,8 +12,10 @@
</p>
<p>
Disabling 2FA does not change the keys used in authenticator apps. If you wish to change the key
used in an authenticator app you should <a asp-action="ResetAuthenticatorWarning">reset your
authenticator keys.</a>
used in an authenticator app you should <a asp-action="ResetAuthenticatorWarning">
reset your
authenticator keys.
</a>
</p>
</div>

View file

@ -1,30 +0,0 @@
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
<section>
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Manage your account</h2>
<hr class="primary">
</div>
</div>
<div>
<div class="row">
<div class="col-md-3">
@await Html.PartialAsync("_ManageNav")
</div>
<div class="col-md-9">
@RenderBody()
</div>
</div>
</div>
</div>
</section>
@section Scripts {
@RenderSection("Scripts", required: false)
}

View file

@ -0,0 +1,4 @@
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewBag.MainTitle = "Manage your account";
}

View file

@ -0,0 +1,28 @@
@model UsersViewModel
@{
ViewData["Title"] = "Users";
ViewData.AddActivePage(ServerNavPages.Users);
}
<h4>@ViewData["Title"]</h4>
@Html.Partial("_StatusMessage", Model.StatusMessage)
<table class="table">
<thead class="thead-inverse">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@foreach(var user in Model.Users)
{
<tr>
<td>@user.Name</td>
<td>@user.Email</td>
</tr>
}
</tbody>
</table>

View file

@ -0,0 +1,30 @@
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 static string ActivePageKey => "ActivePage";
public static string Index => "Index";
public static string Users => "Users";
public static string UsersNavClass(ViewContext viewContext) => PageNavClass(viewContext, Users);
public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);
public static string PageNavClass(ViewContext viewContext, string page)
{
var activePage = viewContext.ViewData["ActivePage"] as string;
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null;
}
public static void AddActivePage(this ViewDataDictionary viewData, string activePage) => viewData[ActivePageKey] = activePage;
}
}

View file

@ -0,0 +1,6 @@
@using BTCPayServer.Views.Server
<ul class="nav nav-pills nav-stacked">
<li class="@ServerNavPages.UsersNavClass(ViewContext)"><a asp-action="Users">Users</a></li>
</ul>

View file

@ -0,0 +1,2 @@
@using BTCPayServer.Views.Server
@using BTCPayServer.Models.ServerViewModels

View file

@ -0,0 +1,4 @@
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewBag.MainTitle = "Server settings";
}

View file

@ -53,7 +53,7 @@
{
@if(User.IsInRole(Roles.ServerAdmin))
{
<li class="nav-item"><a asp-area="" asp-controller="Server" asp-action="Settings" 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="Stores" asp-action="ListStores" class="nav-link js-scroll-trigger">Stores</a></li>
<li class="nav-item"><a asp-area="" asp-controller="Invoice" asp-action="ListInvoices" class="nav-link js-scroll-trigger">Invoices</a></li>

View file

@ -7,7 +7,7 @@
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Manage your store</h2>
<h2 class="section-heading">@ViewData["MainTitle"]</h2>
<hr class="primary">
</div>
</div>
@ -15,7 +15,7 @@
<div>
<div class="row">
<div class="col-md-3">
@await Html.PartialAsync("_StoreNav")
@await Html.PartialAsync("_Nav")
</div>
<div class="col-md-9">
@RenderBody()

View file

@ -1,6 +1,5 @@
@model BTCPayServer.Models.StoreViewModels.CreateStoreViewModel
@{
Layout = "/Views/Shared/_Layout.cshtml";
ViewData["Title"] = "Create a new store";
}
<section>

View file

@ -1,5 +1,6 @@
@model CreateTokenViewModel
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewData["Title"] = "Create a new token";
ViewData.AddActivePage(StoreNavPages.Tokens);
}

View file

@ -1,6 +1,5 @@
@model StoresViewModel
@{
Layout = "/Views/Shared/_Layout.cshtml";
ViewData["Title"] = "Stores";
}

View file

@ -1,5 +1,6 @@
@model TokensViewModel
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewData["Title"] = "Access Tokens";
ViewData.AddActivePage(StoreNavPages.Tokens);
}

View file

@ -1,6 +1,5 @@
@model PairingModel
@{
Layout = "/Views/Shared/_Layout.cshtml";
ViewData["Title"] = "Pairing permission";
}

View file

@ -1,5 +1,6 @@
@model StoreViewModel
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewData["Title"] = "Profile";
ViewData.AddActivePage(BTCPayServer.Views.Stores.StoreNavPages.Index);
}

View file

@ -1,8 +1,5 @@
@using BTCPayServer.Views.Stores
@inject SignInManager<ApplicationUser> SignInManager
@{
var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any();
}
<ul class="nav nav-pills nav-stacked">
<li class="@StoreNavPages.IndexNavClass(ViewContext)"><a asp-action="UpdateStore">Information</a></li>

View file

@ -0,0 +1,3 @@
@{
ViewBag.MainTitle = "Manage store";
}