mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-21 22:11:48 +01:00
POS: Updates from code review
Thanks @kukks
This commit is contained in:
parent
197b46880c
commit
58f56eac90
8 changed files with 31 additions and 19 deletions
|
@ -382,7 +382,7 @@ namespace BTCPayServer.Tests
|
|||
s.Driver.FindElement(By.Id("SaveSettings")).ForceClick();
|
||||
s.Driver.FindElement(By.Id("ViewApp")).ForceClick();
|
||||
|
||||
var posBaseUrl = s.Driver.Url;
|
||||
var posBaseUrl = s.Driver.Url.Replace("/Cart", "");
|
||||
Assert.True(s.Driver.PageSource.Contains("Tea shop"), "Unable to create PoS");
|
||||
Assert.True(s.Driver.PageSource.Contains("Cart"), "PoS not showing correct default view");
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ namespace BTCPayServer.Controllers
|
|||
public string Title { get; set; }
|
||||
public string Currency { get; set; }
|
||||
public string Template { get; set; }
|
||||
public bool EnableShoppingCart { get; set; }
|
||||
public PosViewType DefaultView { get; set; }
|
||||
public bool ShowCustomAmount { get; set; }
|
||||
public bool ShowDiscount { get; set; }
|
||||
|
@ -92,6 +93,8 @@ namespace BTCPayServer.Controllers
|
|||
if (app == null)
|
||||
return NotFound();
|
||||
var settings = app.GetSettings<PointOfSaleSettings>();
|
||||
settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView;
|
||||
settings.EnableShoppingCart = false;
|
||||
|
||||
var vm = new UpdatePointOfSaleViewModel()
|
||||
{
|
||||
|
@ -191,7 +194,6 @@ namespace BTCPayServer.Controllers
|
|||
Description = vm.Description,
|
||||
EmbeddedCSS = vm.EmbeddedCSS,
|
||||
RedirectAutomatically = string.IsNullOrEmpty(vm.RedirectAutomatically) ? (bool?)null : bool.Parse(vm.RedirectAutomatically)
|
||||
|
||||
});
|
||||
await _AppService.UpdateOrCreateApp(app);
|
||||
TempData[WellKnownTempData.SuccessMessage] = "App updated";
|
||||
|
|
|
@ -38,20 +38,31 @@ namespace BTCPayServer.Controllers
|
|||
private readonly AppService _AppService;
|
||||
private readonly BTCPayServerOptions _BtcPayServerOptions;
|
||||
private readonly InvoiceController _InvoiceController;
|
||||
private readonly UserManager<ApplicationUser> _UserManager;
|
||||
|
||||
private readonly UserManager<ApplicationUser> _UserManager;
|
||||
|
||||
[HttpGet]
|
||||
[Route("/apps/{appId}/pos/{viewType?}")]
|
||||
[Route("/apps/{appId}/pos")]
|
||||
[XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)]
|
||||
public async Task<IActionResult> ViewPointOfSale(string appId, PosViewType viewType = PosViewType.Unspecified)
|
||||
public async Task<IActionResult> ViewPointOfSale(string appId)
|
||||
{
|
||||
var app = await _AppService.GetApp(appId, AppType.PointOfSale);
|
||||
if (app == null)
|
||||
return NotFound();
|
||||
var settings = app.GetSettings<PointOfSaleSettings>();
|
||||
PosViewType viewType = settings.DefaultView;
|
||||
|
||||
return RedirectToAction(nameof(ViewPointOfSale), new { appId, viewType });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("/apps/{appId}/pos/{viewType}")]
|
||||
[XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)]
|
||||
public async Task<IActionResult> ViewPointOfSale(string appId, PosViewType viewType)
|
||||
{
|
||||
var app = await _AppService.GetApp(appId, AppType.PointOfSale);
|
||||
if (app == null)
|
||||
return NotFound();
|
||||
var settings = app.GetSettings<PointOfSaleSettings>();
|
||||
if (viewType == PosViewType.Unspecified)
|
||||
viewType = settings.DefaultView;
|
||||
|
||||
var numberFormatInfo = _AppService.Currencies.GetNumberFormatInfo(settings.Currency) ?? _AppService.Currencies.GetNumberFormatInfo("USD");
|
||||
double step = Math.Pow(10, -(numberFormatInfo.CurrencyDecimalDigits));
|
||||
|
||||
|
@ -87,11 +98,12 @@ namespace BTCPayServer.Controllers
|
|||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("/apps/{appId}/pos/{viewType?}")]
|
||||
[Route("/apps/{appId}/pos/{viewType}")]
|
||||
[XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
[EnableCors(CorsPolicies.All)]
|
||||
public async Task<IActionResult> ViewPointOfSale(string appId,
|
||||
PosViewType viewType,
|
||||
[ModelBinder(typeof(InvariantDecimalModelBinder))] decimal amount,
|
||||
string email,
|
||||
string orderId,
|
||||
|
@ -110,7 +122,7 @@ namespace BTCPayServer.Controllers
|
|||
var settings = app.GetSettings<PointOfSaleSettings>();
|
||||
if (string.IsNullOrEmpty(choiceKey) && !settings.ShowCustomAmount && settings.DefaultView != PosViewType.Cart)
|
||||
{
|
||||
return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId });
|
||||
return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId, viewType = viewType });
|
||||
}
|
||||
string title = null;
|
||||
var price = 0.0m;
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace BTCPayServer.Controllers
|
|||
var controller = (AppsPublicController)serviceProvider.GetService(typeof(AppsPublicController));
|
||||
controller.Url = Url;
|
||||
controller.ControllerContext = ControllerContext;
|
||||
var res = await controller.ViewPointOfSale(appId, PosViewType.Unspecified) as ViewResult;
|
||||
var res = await controller.ViewPointOfSale(appId) as ViewResult;
|
||||
if (res != null)
|
||||
{
|
||||
res.ViewName = "/Views/AppsPublic/ViewPointOfSale.cshtml";
|
||||
|
|
|
@ -34,8 +34,6 @@ namespace BTCPayServer.Models.AppViewModels
|
|||
public CurrencyInfoData CurrencyInfo { get; set; }
|
||||
|
||||
public PosViewType ViewType { get; set; }
|
||||
|
||||
public bool IsCartView { get { return ViewType == PosViewType.Cart; } }
|
||||
public bool ShowCustomAmount { get; set; }
|
||||
public bool ShowDiscount { get; set; }
|
||||
public bool EnableTips { get; set; }
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace BTCPayServer.Services.Apps
|
|||
|
||||
public enum PosViewType
|
||||
{
|
||||
Unspecified = -1,
|
||||
Static = 0,
|
||||
Cart = 1
|
||||
Static,
|
||||
Cart
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<div class="form-group">
|
||||
<div class="form-group">
|
||||
<label asp-for="DefaultView" class="control-label"></label>*
|
||||
<select asp-for="DefaultView" asp-items="@Html.GetEnumSelectList<PosViewType>().Where(type => Convert.ToInt32(type.Value) >= 0)" class="form-control"></select>
|
||||
<select asp-for="DefaultView" asp-items="@Html.GetEnumSelectList<PosViewType>()" class="form-control"></select>
|
||||
<span asp-validation-for="DefaultView" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
@addTagHelper *, BundlerMinifier.TagHelpers
|
||||
@inject BTCPayServer.HostedServices.CssThemeManager themeManager
|
||||
|
||||
@using BTCPayServer.Services.Apps
|
||||
@model BTCPayServer.Models.AppViewModels.ViewPointOfSaleViewModel
|
||||
@{
|
||||
ViewData["Title"] = Model.Title;
|
||||
|
@ -27,7 +28,7 @@
|
|||
}
|
||||
<link href="~/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" asp-append-version="true" />
|
||||
|
||||
@if (Model.IsCartView)
|
||||
@if (Model.ViewType == PosViewType.Cart)
|
||||
{
|
||||
<link rel="stylesheet" href="~/cart/css/style.css" asp-append-version="true">
|
||||
<script type="text/javascript">
|
||||
|
|
Loading…
Add table
Reference in a new issue