From b7ec22ee893f6b149a8e875deb910ddea13c2341 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 26 May 2020 17:38:30 +0200 Subject: [PATCH] POS: Set ViewType via optional URL parameter Falls back to the DefaultView defined in the POS settings. POS: Fix POST-Route --- BTCPayServer.Tests/SeleniumTests.cs | 11 ++++++++++- BTCPayServer/Controllers/AppsPublicController.cs | 10 ++++++---- BTCPayServer/Controllers/HomeController.cs | 2 +- .../Models/AppViewModels/ViewPointOfSaleViewModel.cs | 4 ++-- BTCPayServer/Services/Apps/AppType.cs | 10 +++------- BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index db6486a8f..65e3fa90a 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -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(); } } diff --git a/BTCPayServer/Controllers/AppsPublicController.cs b/BTCPayServer/Controllers/AppsPublicController.cs index 0f260f6cf..c476231e2 100644 --- a/BTCPayServer/Controllers/AppsPublicController.cs +++ b/BTCPayServer/Controllers/AppsPublicController.cs @@ -41,14 +41,16 @@ namespace BTCPayServer.Controllers private readonly UserManager _UserManager; [HttpGet] - [Route("/apps/{appId}/pos")] + [Route("/apps/{appId}/pos/{viewType?}")] [XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)] - public async Task ViewPointOfSale(string appId) + public async Task ViewPointOfSale(string appId, PosViewType viewType = PosViewType.Unspecified) { var app = await _AppService.GetApp(appId, AppType.PointOfSale); if (app == null) return NotFound(); var settings = app.GetSettings(); + 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)] diff --git a/BTCPayServer/Controllers/HomeController.cs b/BTCPayServer/Controllers/HomeController.cs index e6dbde397..acf5af3cd 100644 --- a/BTCPayServer/Controllers/HomeController.cs +++ b/BTCPayServer/Controllers/HomeController.cs @@ -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"; diff --git a/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs b/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs index fd2bb6618..b2dd1d7b3 100644 --- a/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs +++ b/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs @@ -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; } diff --git a/BTCPayServer/Services/Apps/AppType.cs b/BTCPayServer/Services/Apps/AppType.cs index 2dd49021d..a1df057cf 100644 --- a/BTCPayServer/Services/Apps/AppType.cs +++ b/BTCPayServer/Services/Apps/AppType.cs @@ -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 } } diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index ca8bf9e01..28b4482ea 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -38,7 +38,7 @@
* - +