mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
POS: Set ViewType via optional URL parameter
Falls back to the DefaultView defined in the POS settings. POS: Fix POST-Route
This commit is contained in:
@@ -381,8 +381,17 @@ namespace BTCPayServer.Tests
|
||||
s.Driver.FindElement(By.Id("DefaultView")).SendKeys("Cart" + Keys.Enter);
|
||||
s.Driver.FindElement(By.Id("SaveSettings")).ForceClick();
|
||||
s.Driver.FindElement(By.Id("ViewApp")).ForceClick();
|
||||
s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last());
|
||||
|
||||
var posBaseUrl = s.Driver.Url;
|
||||
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");
|
||||
|
||||
s.Driver.Url = posBaseUrl + "/static";
|
||||
Assert.False(s.Driver.PageSource.Contains("Cart"), "Static PoS not showing correct view");
|
||||
|
||||
s.Driver.Url = posBaseUrl + "/cart";
|
||||
Assert.True(s.Driver.PageSource.Contains("Cart"), "Cart PoS not showing correct view");
|
||||
|
||||
s.Driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,14 +41,16 @@ namespace BTCPayServer.Controllers
|
||||
private readonly UserManager<ApplicationUser> _UserManager;
|
||||
|
||||
[HttpGet]
|
||||
[Route("/apps/{appId}/pos")]
|
||||
[Route("/apps/{appId}/pos/{viewType?}")]
|
||||
[XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)]
|
||||
public async Task<IActionResult> ViewPointOfSale(string appId)
|
||||
public async Task<IActionResult> ViewPointOfSale(string appId, PosViewType viewType = PosViewType.Unspecified)
|
||||
{
|
||||
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));
|
||||
@@ -57,7 +59,7 @@ namespace BTCPayServer.Controllers
|
||||
{
|
||||
Title = settings.Title,
|
||||
Step = step.ToString(CultureInfo.InvariantCulture),
|
||||
DefaultView = settings.DefaultView,
|
||||
ViewType = viewType,
|
||||
ShowCustomAmount = settings.ShowCustomAmount,
|
||||
ShowDiscount = settings.ShowDiscount,
|
||||
EnableTips = settings.EnableTips,
|
||||
@@ -85,7 +87,7 @@ namespace BTCPayServer.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("/apps/{appId}/pos")]
|
||||
[Route("/apps/{appId}/pos/{viewType?}")]
|
||||
[XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
[EnableCors(CorsPolicies.All)]
|
||||
|
||||
@@ -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) as ViewResult;
|
||||
var res = await controller.ViewPointOfSale(appId, PosViewType.Unspecified) as ViewResult;
|
||||
if (res != null)
|
||||
{
|
||||
res.ViewName = "/Views/AppsPublic/ViewPointOfSale.cshtml";
|
||||
|
||||
@@ -33,9 +33,9 @@ namespace BTCPayServer.Models.AppViewModels
|
||||
|
||||
public CurrencyInfoData CurrencyInfo { get; set; }
|
||||
|
||||
public PosViewType DefaultView { get; set; }
|
||||
public PosViewType ViewType { get; set; }
|
||||
|
||||
public bool IsCartView { get { return DefaultView == PosViewType.Cart; } }
|
||||
public bool IsCartView { get { return ViewType == PosViewType.Cart; } }
|
||||
public bool ShowCustomAmount { get; set; }
|
||||
public bool ShowDiscount { get; set; }
|
||||
public bool EnableTips { get; set; }
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BTCPayServer.Services.Apps
|
||||
{
|
||||
public enum AppType
|
||||
@@ -13,7 +8,8 @@ namespace BTCPayServer.Services.Apps
|
||||
|
||||
public enum PosViewType
|
||||
{
|
||||
Static,
|
||||
Cart
|
||||
Unspecified = -1,
|
||||
Static = 0,
|
||||
Cart = 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>()" class="form-control"></select>
|
||||
<select asp-for="DefaultView" asp-items="@Html.GetEnumSelectList<PosViewType>().Where(type => Convert.ToInt32(type.Value) >= 0)" class="form-control"></select>
|
||||
<span asp-validation-for="DefaultView" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
|
||||
Reference in New Issue
Block a user