From c16dfb2dcb31dd8b3aff55dde4ec13c69ab61921 Mon Sep 17 00:00:00 2001 From: d11n Date: Thu, 2 Nov 2023 19:58:03 +0100 Subject: [PATCH] POS and Crowdfund: Improve item editor (#5418) * POS and Crowdfund: Improve item editor Makes it work the same way as the form editor: Drag and drop for reordering and inline editing without modal. * Upload component --- BTCPayServer.Tests/BTCPayServer.Tests.csproj | 2 +- BTCPayServer.Tests/SeleniumTests.cs | 7 +- BTCPayServer/Controllers/UIAppsController.cs | 6 +- .../Crowdfund/Public/ViewCrowdfund.cshtml | 1 - .../Shared/Crowdfund/UpdateCrowdfund.cshtml | 35 +- .../PointOfSale/UpdatePointOfSale.cshtml | 133 +---- .../Views/Shared/TemplateEditor.cshtml | 496 ++++++------------ BTCPayServer/Views/UIForms/Modify.cshtml | 162 +++--- .../ViewPaymentRequest.cshtml | 1 - BTCPayServer/wwwroot/crowdfund/admin.js | 26 + .../wwwroot/crowdfund/helpers/math.js | 21 - BTCPayServer/wwwroot/js/form-editor.js | 1 - BTCPayServer/wwwroot/js/template-editor.js | 283 ++++++++++ BTCPayServer/wwwroot/main/editor.css | 65 +++ BTCPayServer/wwwroot/main/site.js | 22 + BTCPayServer/wwwroot/main/template-editor.css | 15 - .../wwwroot/payment-request/helpers/math.js | 17 - BTCPayServer/wwwroot/pos/admin.js | 53 ++ 18 files changed, 702 insertions(+), 644 deletions(-) create mode 100644 BTCPayServer/wwwroot/crowdfund/admin.js delete mode 100644 BTCPayServer/wwwroot/crowdfund/helpers/math.js create mode 100644 BTCPayServer/wwwroot/js/template-editor.js create mode 100644 BTCPayServer/wwwroot/main/editor.css delete mode 100644 BTCPayServer/wwwroot/main/template-editor.css delete mode 100644 BTCPayServer/wwwroot/payment-request/helpers/math.js create mode 100644 BTCPayServer/wwwroot/pos/admin.js diff --git a/BTCPayServer.Tests/BTCPayServer.Tests.csproj b/BTCPayServer.Tests/BTCPayServer.Tests.csproj index 5b18fd4a2..c8fbe1850 100644 --- a/BTCPayServer.Tests/BTCPayServer.Tests.csproj +++ b/BTCPayServer.Tests/BTCPayServer.Tests.csproj @@ -23,7 +23,7 @@ - + all diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index a986f45f0..0400aab31 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -983,13 +983,12 @@ namespace BTCPayServer.Tests Assert.Contains("App successfully created", s.FindAlertMessage().Text); s.Driver.FindElement(By.CssSelector("label[for='DefaultView_Cart']")).Click(); - s.Driver.FindElement(By.CssSelector(".template-item:nth-of-type(1) .btn-primary")).Click(); + s.Driver.FindElement(By.CssSelector(".template-item:nth-of-type(1)")).Click(); s.Driver.FindElement(By.Id("BuyButtonText")).SendKeys("Take my money"); s.Driver.FindElement(By.Id("EditorCategories-ts-control")).SendKeys("Drinks"); - s.Driver.FindElement(By.Id("SaveItemChanges")).Click(); - s.Driver.FindElement(By.Id("ToggleRawEditor")).Click(); + s.Driver.FindElement(By.Id("ApplyItemChanges")).Click(); - var template = s.Driver.FindElement(By.Id("Template")).GetAttribute("value"); + var template = s.Driver.FindElement(By.Id("TemplateConfig")).GetAttribute("value"); Assert.Contains("\"buyButtonText\": \"Take my money\"", template); Assert.Matches("\"categories\": \\[\n\\s+\"Drinks\"\n\\s+\\]", template); diff --git a/BTCPayServer/Controllers/UIAppsController.cs b/BTCPayServer/Controllers/UIAppsController.cs index e11778381..ef95076f4 100644 --- a/BTCPayServer/Controllers/UIAppsController.cs +++ b/BTCPayServer/Controllers/UIAppsController.cs @@ -228,13 +228,17 @@ namespace BTCPayServer.Controllers if (app is null || userId is null) return NotFound(); + if (!file.FileName.IsValidFileName()) + { + return Json(new { error = "Invalid file name" }); + } if (!file.ContentType.StartsWith("image/", StringComparison.InvariantCulture)) { return Json(new { error = "The file needs to be an image" }); } if (file.Length > 500_000) { - return Json(new { error = "The image file size should be less than 0.5MB" }); + return Json(new { error = "The file size should be less than 0.5MB" }); } var formFile = await file.Bufferize(); if (!FileTypeDetector.IsPicture(formFile.Buffer, formFile.FileName)) diff --git a/BTCPayServer/Views/Shared/Crowdfund/Public/ViewCrowdfund.cshtml b/BTCPayServer/Views/Shared/Crowdfund/Public/ViewCrowdfund.cshtml index 8393a8c89..eead921c1 100644 --- a/BTCPayServer/Views/Shared/Crowdfund/Public/ViewCrowdfund.cshtml +++ b/BTCPayServer/Views/Shared/Crowdfund/Public/ViewCrowdfund.cshtml @@ -394,7 +394,6 @@ - diff --git a/BTCPayServer/Views/Shared/Crowdfund/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Shared/Crowdfund/UpdateCrowdfund.cshtml index ab5ee672a..3ecbc64f7 100644 --- a/BTCPayServer/Views/Shared/Crowdfund/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Shared/Crowdfund/UpdateCrowdfund.cshtml @@ -13,16 +13,13 @@ @section PageHeadContent { - - + } @section PageFootContent { - + }
@@ -351,31 +348,3 @@ - diff --git a/BTCPayServer/Views/Shared/PointOfSale/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Shared/PointOfSale/UpdatePointOfSale.cshtml index 158804374..9ac00dbaf 100644 --- a/BTCPayServer/Views/Shared/PointOfSale/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Shared/PointOfSale/UpdatePointOfSale.cshtml @@ -12,6 +12,17 @@ var checkoutFormOptions = await FormDataService.GetSelect(Model.StoreId, Model.FormId); } +@section PageHeadContent { + + +} + +@section PageFootContent { + + + +} + - -@section PageHeadContent { - - - -} - -@section PageFootContent { - - - - - - -} diff --git a/BTCPayServer/Views/Shared/TemplateEditor.cshtml b/BTCPayServer/Views/Shared/TemplateEditor.cshtml index fb7fba31c..edcb01783 100644 --- a/BTCPayServer/Views/Shared/TemplateEditor.cshtml +++ b/BTCPayServer/Views/Shared/TemplateEditor.cshtml @@ -1,353 +1,171 @@ @model (string templateId, string template, string title, string currency) -
-