Remove stores list (#3300)

This commit is contained in:
d11n 2022-01-14 03:59:27 +01:00 committed by GitHub
parent 223c71ce8b
commit 51db1593d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 175 deletions

View File

@ -24,10 +24,6 @@
<li><a asp-controller="UserStores" asp-action="CreateStore" class="dropdown-item" id="StoreSelectorCreate">Create Store</a></li>
</ul>
</div>
<noscript>
<span class="h5 mb-0 me-2">@Model.CurrentDisplayName</span>
<a asp-controller="UserStores" asp-action="ListStores">Stores</a>
</noscript>
}
else
{

View File

@ -857,7 +857,7 @@ namespace BTCPayServer.Controllers
if (!stores.Any())
{
TempData[WellKnownTempData.ErrorMessage] = "You need to create at least one store before creating a transaction";
return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores");
return RedirectToAction(nameof(HomeController.Index), "Home");
}
if (model?.StoreId != null)

View File

@ -701,7 +701,7 @@ namespace BTCPayServer.Controllers
{
await _Repo.DeleteStore(CurrentStore.Id);
TempData[WellKnownTempData.SuccessMessage] = "Store successfully deleted.";
return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores");
return RedirectToAction(nameof(HomeController.Index), "Home");
}
private IEnumerable<AvailableRateProvider> GetSupportedExchanges()
@ -873,7 +873,7 @@ namespace BTCPayServer.Controllers
if (!model.Stores.Any())
{
TempData[WellKnownTempData.ErrorMessage] = "You need to be owner of at least one store before pairing";
return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores");
return RedirectToAction(nameof(HomeController.Index), "Home");
}
return View(model);
}
@ -932,7 +932,7 @@ namespace BTCPayServer.Controllers
if (pairing == null)
{
TempData[WellKnownTempData.ErrorMessage] = "Unknown pairing code";
return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores");
return RedirectToAction(nameof(HomeController.Index), "Home");
}
else
{

View File

@ -78,60 +78,7 @@ namespace BTCPayServer.Controllers
return NotFound();
await _repo.RemoveStore(storeId, userId);
TempData[WellKnownTempData.SuccessMessage] = "Store removed successfully";
return RedirectToAction(nameof(ListStores));
}
[HttpGet]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyStoreSettingsUnscoped)]
public async Task<IActionResult> ListStores(
string sortOrder = null,
string sortOrderColumn = null
)
{
StoresViewModel result = new StoresViewModel();
var stores = await _repo.GetStoresByUserId(GetUserId());
if (sortOrder != null && sortOrderColumn != null)
{
stores = stores.OrderByDescending(store =>
{
switch (sortOrderColumn)
{
case nameof(store.StoreName):
return store.StoreName;
case nameof(store.StoreWebsite):
return store.StoreWebsite;
default:
return store.Id;
}
}).ToArray();
switch (sortOrder)
{
case "desc":
ViewData[$"{sortOrderColumn}SortOrder"] = "asc";
break;
case "asc":
stores = stores.Reverse().ToArray();
ViewData[$"{sortOrderColumn}SortOrder"] = "desc";
break;
}
}
for (int i = 0; i < stores.Length; i++)
{
var store = stores[i];
var blob = store.GetStoreBlob();
result.Stores.Add(new StoresViewModel.StoreViewModel()
{
Id = store.Id,
Name = store.StoreName,
WebSite = store.StoreWebsite,
IsOwner = store.Role == StoreRoles.Owner,
HintWalletWarning = blob.Hints.Wallet && blob.Hints.Lightning
});
}
return View(result);
return RedirectToAction(nameof(HomeController.Index), "Home");
}
private string GetUserId() => _userManager.GetUserId(User);

View File

@ -1,18 +0,0 @@
using System.Collections.Generic;
namespace BTCPayServer.Models.StoreViewModels
{
public class StoresViewModel
{
public List<StoreViewModel> Stores { get; set; } = new List<StoreViewModel>();
public class StoreViewModel
{
public string Id { get; set; }
public string Name { get; set; }
public string WebSite { get; set; }
public bool IsOwner { get; set; }
public bool HintWalletWarning { get; set; }
}
}
}

View File

@ -30,6 +30,8 @@
</style>
}
<partial name="_StatusMessage" />
<h2>Welcome to your BTCPay Server</h2>
@if (Model.HasStore)

View File

@ -1,95 +0,0 @@
@model StoresViewModel
@{
ViewData.SetActivePage(StoreNavPages.Index, "Stores");
var storeNameSortOrder = (string)ViewData["StoreNameSortOrder"];
var storeWebsiteSortOrder = (string)ViewData["StoreWebsiteSortOrder"];
var sortByDesc = "Sort by descending...";
var sortByAsc = "Sort by ascending...";
}
<partial name="_StatusMessage" />
<div class="d-sm-flex align-items-center justify-content-between mb-2">
<h2 class="mb-0">@ViewData["Title"]</h2>
<a asp-action="CreateStore" class="btn btn-primary mt-3 mt-sm-0" role="button" id="CreateStore"><span class="fa fa-plus"></span> Create a new store</a>
</div>
<div class="row">
<div class="col-lg-12">
@if (Model.Stores.Any())
{
<table class="table table-hover">
<thead>
<tr>
<th>
<a asp-action="ListStores"
asp-route-sortOrder="@(storeNameSortOrder ?? "asc")"
asp-route-sortOrderColumn="StoreName"
class="text-nowrap"
title="@(storeNameSortOrder == "desc" ? sortByDesc : sortByAsc)">
Name
<span class="fa @(storeNameSortOrder == "asc" ? "fa-sort-alpha-desc" : storeNameSortOrder == "desc" ? "fa-sort-alpha-asc" : "fa-sort")" />
</a>
</th>
<th>
<a asp-action="ListStores"
asp-route-sortOrder="@(storeWebsiteSortOrder ?? "asc")"
asp-route-sortOrderColumn="StoreWebsite"
class="text-nowrap"
title="@(storeWebsiteSortOrder == "desc" ? sortByDesc : sortByAsc)">
Website
<span class="fa @(storeWebsiteSortOrder == "asc" ? "fa-sort-alpha-desc" : storeWebsiteSortOrder == "desc" ? "fa-sort-alpha-asc" : "fa-sort")" />
</a>
</th>
<th style="text-align:right">Actions</th>
</tr>
</thead>
<tbody>
@foreach (var store in Model.Stores)
{
<tr id="store-@store.Id">
<td>
@if (store.IsOwner)
{
<a asp-action="PaymentMethods" asp-controller="Stores" asp-route-storeId="@store.Id">@store.Name</a>
}
else
{
@store.Name
}
@if (store.HintWalletWarning)
{
<span class="fa fa-warning text-warning" title="Wallet not setup for this store" id="warninghint_@store.Id"></span>
}
</td>
<td>
@if (!string.IsNullOrEmpty(store.WebSite))
{
<a href="@store.WebSite" rel="noreferrer noopener">@store.WebSite</a>
}
</td>
<td style="text-align:right">
<a asp-action="ListInvoices" asp-controller="Invoice" asp-route-storeId="@store.Id">Invoices</a><span> - </span>
<a asp-action="PullPayments" asp-controller="StorePullPayments" asp-route-storeId="@store.Id">Pull Payments</a>
@if (store.IsOwner)
{
<span> - </span>
<a asp-action="PaymentMethods" asp-controller="Stores" asp-route-storeId="@store.Id" id="update-store-@store.Id">Settings</a><span> - </span>
<a asp-action="DeleteStore" asp-controller="Stores" asp-route-storeId="@store.Id" data-bs-toggle="modal" data-bs-target="#ConfirmModal" data-description="The store <strong>@store.Name</strong> will be permanently deleted. This action will also delete all invoices, apps and data associated with the store." data-confirm-input="DELETE">Delete</a>
}
</td>
</tr>
}
</tbody>
</table>
}
else
{
<p class="text-secondary mt-3">
There are no stores yet.
</p>
}
</div>
</div>
<partial name="_Confirm" model="@(new ConfirmModel("Delete store", "The store will be permanently deleted. This action will also delete all invoices, apps and data associated with the store.", "Delete"))" />