From 1436420a93b2a093d0c9458690458b117ee18194 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Thu, 23 Jan 2020 19:51:57 -0600 Subject: [PATCH 1/7] Providing link to view app in new window co-authored-by: radWorx --- BTCPayServer/Views/Apps/ListApps.cshtml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Views/Apps/ListApps.cshtml b/BTCPayServer/Views/Apps/ListApps.cshtml index 0fc64c60e..39997f9eb 100644 --- a/BTCPayServer/Views/Apps/ListApps.cshtml +++ b/BTCPayServer/Views/Apps/ListApps.cshtml @@ -56,9 +56,13 @@ @if (app.IsOwner) { - Settings - + Settings + - } - View - + View + + - Remove From 4ae173bb69f868a38f751203db73e9eb27e32e80 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Thu, 23 Jan 2020 20:01:49 -0600 Subject: [PATCH 2/7] Providing open in new window split button when updating POS app co-authored-by: radWorx --- BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index 0e412913b..0f83d14e0 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -146,9 +146,17 @@
From a907143d81d8310b600a367bc68b50aa01d8244f Mon Sep 17 00:00:00 2001 From: rockstardev Date: Thu, 23 Jan 2020 20:17:29 -0600 Subject: [PATCH 3/7] Providing open in new window split button when updating crowdfund Unifying styles on POS and Crowdfund settings co-authored-by: radWorx --- BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml | 16 ++++++++++++---- BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index f6ffa765c..8b27fe0de 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -216,12 +216,20 @@
- Invoices - @if ((Model.Description != null) && (Model.Title != null) && (Model.TargetCurrency != null)) +
+ Invoices + +
+ @if (Model.ModelWithMinimumData) { - +
+ View App + +
} - Back to the app list + Back to the app list
diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index 0f83d14e0..dcd2281aa 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -152,8 +152,8 @@ target="viewinvoices_@Model.Id">
Back to the app list From f99058a9fad8a0b4b54089bf538fb5dcc7f0bd24 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Thu, 23 Jan 2020 20:18:33 -0600 Subject: [PATCH 4/7] Adding code comment for review --- BTCPayServer/Controllers/AppsController.Crowdfund.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BTCPayServer/Controllers/AppsController.Crowdfund.cs b/BTCPayServer/Controllers/AppsController.Crowdfund.cs index b742b85d9..29b4f0bcc 100644 --- a/BTCPayServer/Controllers/AppsController.Crowdfund.cs +++ b/BTCPayServer/Controllers/AppsController.Crowdfund.cs @@ -170,6 +170,8 @@ namespace BTCPayServer.Controllers TempData[WellKnownTempData.SuccessMessage] = "App updated"; return RedirectToAction(nameof(UpdateCrowdfund), new { appId }); } + // TODO: Check with Kukks if we can remove this tricky logic of redirecting to viewapp + // I've already switched do button directly linking to AppPublic ViewCrowdfund action else if (command == "viewapp") { return RedirectToAction(nameof(AppsPublicController.ViewCrowdfund), "AppsPublic", new { appId }); From a83edce4dc09331fd1c7d9038e7562b876f19098 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Thu, 23 Jan 2020 20:19:24 -0600 Subject: [PATCH 5/7] Updating idents, code formatting --- .../Controllers/AppsController.Crowdfund.cs | 22 ++++++------- .../Controllers/AppsController.PointOfSale.cs | 16 ++++----- .../AppViewModels/UpdateCrowdfundViewModel.cs | 33 +++++++++++++------ .../Views/Apps/UpdateCrowdfund.cshtml | 15 ++++----- .../Views/Apps/UpdatePointOfSale.cshtml | 13 ++++---- .../Views/AppsPublic/ViewCrowdfund.cshtml | 30 ++++++++--------- 6 files changed, 70 insertions(+), 59 deletions(-) diff --git a/BTCPayServer/Controllers/AppsController.Crowdfund.cs b/BTCPayServer/Controllers/AppsController.Crowdfund.cs index 29b4f0bcc..503e37c91 100644 --- a/BTCPayServer/Controllers/AppsController.Crowdfund.cs +++ b/BTCPayServer/Controllers/AppsController.Crowdfund.cs @@ -22,8 +22,8 @@ namespace BTCPayServer.Controllers return String.Empty; } } - - + + [HttpGet] [Route("{appId}/settings/crowdfund")] public async Task UpdateCrowdfund(string appId) @@ -61,8 +61,8 @@ namespace BTCPayServer.Controllers SearchTerm = app.TagAllInvoices ? $"storeid:{app.StoreDataId}" : $"orderid:{AppService.GetCrowdfundOrderId(appId)}", DisplayPerksRanking = settings.DisplayPerksRanking, SortPerksByPopularity = settings.SortPerksByPopularity, - Sounds = string.Join(Environment.NewLine, settings.Sounds), - AnimationColors = string.Join(Environment.NewLine, settings.AnimationColors) + Sounds = string.Join(Environment.NewLine, settings.Sounds), + AnimationColors = string.Join(Environment.NewLine, settings.AnimationColors) }; return View(vm); } @@ -70,9 +70,9 @@ namespace BTCPayServer.Controllers [Route("{appId}/settings/crowdfund")] public async Task UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm, string command) { - if (!string.IsNullOrEmpty( vm.TargetCurrency) && _currencies.GetCurrencyData(vm.TargetCurrency, false) == null) + if (!string.IsNullOrEmpty(vm.TargetCurrency) && _currencies.GetCurrencyData(vm.TargetCurrency, false) == null) ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency"); - + try { _AppService.Parse(vm.PerksTemplate, vm.TargetCurrency).ToString(); @@ -98,14 +98,14 @@ namespace BTCPayServer.Controllers } var parsedSounds = vm.Sounds.Split( - new[] {"\r\n", "\r", "\n"}, + new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ).Select(s => s.Trim()).ToArray(); if (vm.SoundsEnabled && !parsedSounds.Any()) { ModelState.AddModelError(nameof(vm.Sounds), "You must have at least one sound if you enable sounds"); } - + var parsedAnimationColors = vm.AnimationColors.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None @@ -114,13 +114,13 @@ namespace BTCPayServer.Controllers { ModelState.AddModelError(nameof(vm.AnimationColors), "You must have at least one animation color if you enable animations"); } - + if (!ModelState.IsValid) { return View(vm); } - - + + var app = await GetOwnedApp(appId, AppType.Crowdfund); if (app == null) return NotFound(); diff --git a/BTCPayServer/Controllers/AppsController.PointOfSale.cs b/BTCPayServer/Controllers/AppsController.PointOfSale.cs index 51032b52f..53c6eadff 100644 --- a/BTCPayServer/Controllers/AppsController.PointOfSale.cs +++ b/BTCPayServer/Controllers/AppsController.PointOfSale.cs @@ -79,9 +79,9 @@ namespace BTCPayServer.Controllers public string CustomCSSLink { get; set; } - + public string EmbeddedCSS { get; set; } - + public string Description { get; set; } public string NotificationEmail { get; set; } public string NotificationUrl { get; set; } @@ -96,7 +96,7 @@ namespace BTCPayServer.Controllers if (app == null) return NotFound(); var settings = app.GetSettings(); - + var vm = new UpdatePointOfSaleViewModel() { NotificationEmailWarning = !await IsEmailConfigured(app.StoreDataId), @@ -119,7 +119,7 @@ namespace BTCPayServer.Controllers NotificationEmail = settings.NotificationEmail, NotificationUrl = settings.NotificationUrl, SearchTerm = $"storeid:{app.StoreDataId}", - RedirectAutomatically = settings.RedirectAutomatically.HasValue? settings.RedirectAutomatically.Value? "true": "false" : "" + RedirectAutomatically = settings.RedirectAutomatically.HasValue ? settings.RedirectAutomatically.Value ? "true" : "false" : "" }; if (HttpContext?.Request != null) { @@ -197,8 +197,8 @@ namespace BTCPayServer.Controllers NotificationEmail = vm.NotificationEmail, Description = vm.Description, EmbeddedCSS = vm.EmbeddedCSS, - RedirectAutomatically = string.IsNullOrEmpty(vm.RedirectAutomatically)? (bool?) null: bool.Parse(vm.RedirectAutomatically) - + RedirectAutomatically = string.IsNullOrEmpty(vm.RedirectAutomatically) ? (bool?)null : bool.Parse(vm.RedirectAutomatically) + }); await _AppService.UpdateOrCreateApp(app); TempData[WellKnownTempData.SuccessMessage] = "App updated"; @@ -211,8 +211,8 @@ namespace BTCPayServer.Controllers if (string.IsNullOrEmpty(list)) { return Array.Empty(); - } - else + } + else { // Remove all characters except numeric and comma Regex charsToDestroy = new Regex(@"[^\d|\" + separator + "]"); diff --git a/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs b/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs index f3fe5ae50..7cf676689 100644 --- a/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs +++ b/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs @@ -10,16 +10,20 @@ namespace BTCPayServer.Models.AppViewModels public class UpdateCrowdfundViewModel { public string StoreId { get; set; } - [Required] [MaxLength(30)] public string Title { get; set; } + [Required] + [MaxLength(30)] + public string Title { get; set; } - [MaxLength(50)] public string Tagline { get; set; } + [MaxLength(50)] + public string Tagline { get; set; } + + [Required] + public string Description { get; set; } - [Required] public string Description { get; set; } - [Display(Name = "Featured Image")] public string MainImageUrl { get; set; } - - [Display(Name = "Callback Notification Url")] + + [Display(Name = "Callback Notification Url")] [Uri] public string NotificationUrl { get; set; } [Display(Name = "Invoice IPN Notification")] @@ -59,7 +63,8 @@ namespace BTCPayServer.Models.AppViewModels public IEnumerable ResetEveryValues = Enum.GetNames(typeof(CrowdfundResetEvery)); - [Display(Name = "Reset goal every")] public string ResetEvery { get; set; } = nameof(CrowdfundResetEvery.Never); + [Display(Name = "Reset goal every")] + public string ResetEvery { get; set; } = nameof(CrowdfundResetEvery.Never); public int ResetEveryAmount { get; set; } = 1; @@ -78,7 +83,7 @@ namespace BTCPayServer.Models.AppViewModels public string EmbeddedCSS { get; set; } [Display(Name = "Count all invoices created on the store as part of the crowdfunding goal")] - public bool UseAllStoreInvoices { get; set; } + public bool UseAllStoreInvoices { get; set; } public string AppId { get; set; } public string SearchTerm { get; set; } @@ -90,10 +95,18 @@ namespace BTCPayServer.Models.AppViewModels [Display(Name = "Sounds to play when a payment is made. One sound per line")] - public string Sounds{ get; set; } + public string Sounds { get; set; } [Display(Name = "Colors to rotate between with animation when a payment is made. First color is the default background. One color per line. Can be any valid css color value.")] - public string AnimationColors{ get; set; } + public string AnimationColors { get; set; } public bool NotificationEmailWarning { get; set; } + + + // NOTE: Improve validation if needed + public bool ModelWithMinimumData + { + get { return Description != null && Title != null && TargetCurrency != null; } + } + } } diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index 8b27fe0de..d4f416aa2 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -263,13 +263,12 @@
* - +
@@ -293,7 +292,7 @@
- +
diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index dcd2281aa..4649a1cc9 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -261,12 +261,11 @@
* - +
@@ -290,7 +289,7 @@
- +
diff --git a/BTCPayServer/Views/AppsPublic/ViewCrowdfund.cshtml b/BTCPayServer/Views/AppsPublic/ViewCrowdfund.cshtml index 98fada78c..9ab010371 100644 --- a/BTCPayServer/Views/AppsPublic/ViewCrowdfund.cshtml +++ b/BTCPayServer/Views/AppsPublic/ViewCrowdfund.cshtml @@ -33,27 +33,27 @@ @if (!string.IsNullOrEmpty(Model.EmbeddedCSS)) { - @Safe.Raw($""); + @Safe.Raw($""); } -@if (Context.Request.Query.ContainsKey("simple")) -{ - @await Html.PartialAsync("/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml", Model) -} -else -{ - - - if (Model.AnimationsEnabled) + @if (Context.Request.Query.ContainsKey("simple")) { - + @await Html.PartialAsync("/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml", Model) + } + else + { + + + if (Model.AnimationsEnabled) + { + + } + @await Html.PartialAsync("/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml", Model) } - @await Html.PartialAsync("/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml", Model) -} From c7c0db612a468188acbe1bd01b5b077def4cd379 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Thu, 23 Jan 2020 20:39:11 -0600 Subject: [PATCH 6/7] Restoring IDs Selenium depends on for tests --- BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml | 2 +- BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index d4f416aa2..b9ed7b0ec 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -224,7 +224,7 @@ @if (Model.ModelWithMinimumData) { diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index 4649a1cc9..ea66a04f5 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -152,7 +152,7 @@ target="viewinvoices_@Model.Id"> From 652b958d4f20287da969d693687dd35a46e0fd3c Mon Sep 17 00:00:00 2001 From: rockstardev Date: Fri, 24 Jan 2020 15:11:34 -0600 Subject: [PATCH 7/7] Removing viewapp command now that we directly redirect in cshtml --- .../Controllers/AppsController.Crowdfund.cs | 26 ++++++------------- .../Views/Apps/UpdateCrowdfund.cshtml | 2 +- .../Views/Apps/UpdatePointOfSale.cshtml | 2 +- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/BTCPayServer/Controllers/AppsController.Crowdfund.cs b/BTCPayServer/Controllers/AppsController.Crowdfund.cs index 503e37c91..98d40b0a6 100644 --- a/BTCPayServer/Controllers/AppsController.Crowdfund.cs +++ b/BTCPayServer/Controllers/AppsController.Crowdfund.cs @@ -157,26 +157,16 @@ namespace BTCPayServer.Controllers app.TagAllInvoices = vm.UseAllStoreInvoices; app.SetSettings(newSettings); - if (command == "save") - { - await _AppService.UpdateOrCreateApp(app); + await _AppService.UpdateOrCreateApp(app); - _EventAggregator.Publish(new AppUpdated() - { - AppId = appId, - StoreId = app.StoreDataId, - Settings = newSettings - }); - TempData[WellKnownTempData.SuccessMessage] = "App updated"; - return RedirectToAction(nameof(UpdateCrowdfund), new { appId }); - } - // TODO: Check with Kukks if we can remove this tricky logic of redirecting to viewapp - // I've already switched do button directly linking to AppPublic ViewCrowdfund action - else if (command == "viewapp") + _EventAggregator.Publish(new AppUpdated() { - return RedirectToAction(nameof(AppsPublicController.ViewCrowdfund), "AppsPublic", new { appId }); - } - return NotFound(); + AppId = appId, + StoreId = app.StoreDataId, + Settings = newSettings + }); + TempData[WellKnownTempData.SuccessMessage] = "App updated"; + return RedirectToAction(nameof(UpdateCrowdfund), new { appId }); } } } diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index b9ed7b0ec..12a5091af 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -215,7 +215,7 @@
- +