Updating idents, code formatting

This commit is contained in:
rockstardev
2020-01-23 20:19:24 -06:00
parent f99058a9fa
commit a83edce4dc
6 changed files with 70 additions and 59 deletions

View File

@@ -22,8 +22,8 @@ namespace BTCPayServer.Controllers
return String.Empty; return String.Empty;
} }
} }
[HttpGet] [HttpGet]
[Route("{appId}/settings/crowdfund")] [Route("{appId}/settings/crowdfund")]
public async Task<IActionResult> UpdateCrowdfund(string appId) public async Task<IActionResult> UpdateCrowdfund(string appId)
@@ -61,8 +61,8 @@ namespace BTCPayServer.Controllers
SearchTerm = app.TagAllInvoices ? $"storeid:{app.StoreDataId}" : $"orderid:{AppService.GetCrowdfundOrderId(appId)}", SearchTerm = app.TagAllInvoices ? $"storeid:{app.StoreDataId}" : $"orderid:{AppService.GetCrowdfundOrderId(appId)}",
DisplayPerksRanking = settings.DisplayPerksRanking, DisplayPerksRanking = settings.DisplayPerksRanking,
SortPerksByPopularity = settings.SortPerksByPopularity, SortPerksByPopularity = settings.SortPerksByPopularity,
Sounds = string.Join(Environment.NewLine, settings.Sounds), Sounds = string.Join(Environment.NewLine, settings.Sounds),
AnimationColors = string.Join(Environment.NewLine, settings.AnimationColors) AnimationColors = string.Join(Environment.NewLine, settings.AnimationColors)
}; };
return View(vm); return View(vm);
} }
@@ -70,9 +70,9 @@ namespace BTCPayServer.Controllers
[Route("{appId}/settings/crowdfund")] [Route("{appId}/settings/crowdfund")]
public async Task<IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm, string command) public async Task<IActionResult> 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"); ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency");
try try
{ {
_AppService.Parse(vm.PerksTemplate, vm.TargetCurrency).ToString(); _AppService.Parse(vm.PerksTemplate, vm.TargetCurrency).ToString();
@@ -98,14 +98,14 @@ namespace BTCPayServer.Controllers
} }
var parsedSounds = vm.Sounds.Split( var parsedSounds = vm.Sounds.Split(
new[] {"\r\n", "\r", "\n"}, new[] { "\r\n", "\r", "\n" },
StringSplitOptions.None StringSplitOptions.None
).Select(s => s.Trim()).ToArray(); ).Select(s => s.Trim()).ToArray();
if (vm.SoundsEnabled && !parsedSounds.Any()) if (vm.SoundsEnabled && !parsedSounds.Any())
{ {
ModelState.AddModelError(nameof(vm.Sounds), "You must have at least one sound if you enable sounds"); ModelState.AddModelError(nameof(vm.Sounds), "You must have at least one sound if you enable sounds");
} }
var parsedAnimationColors = vm.AnimationColors.Split( var parsedAnimationColors = vm.AnimationColors.Split(
new[] { "\r\n", "\r", "\n" }, new[] { "\r\n", "\r", "\n" },
StringSplitOptions.None 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"); ModelState.AddModelError(nameof(vm.AnimationColors), "You must have at least one animation color if you enable animations");
} }
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return View(vm); return View(vm);
} }
var app = await GetOwnedApp(appId, AppType.Crowdfund); var app = await GetOwnedApp(appId, AppType.Crowdfund);
if (app == null) if (app == null)
return NotFound(); return NotFound();

View File

@@ -79,9 +79,9 @@ namespace BTCPayServer.Controllers
public string CustomCSSLink { get; set; } public string CustomCSSLink { get; set; }
public string EmbeddedCSS { get; set; } public string EmbeddedCSS { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string NotificationEmail { get; set; } public string NotificationEmail { get; set; }
public string NotificationUrl { get; set; } public string NotificationUrl { get; set; }
@@ -96,7 +96,7 @@ namespace BTCPayServer.Controllers
if (app == null) if (app == null)
return NotFound(); return NotFound();
var settings = app.GetSettings<PointOfSaleSettings>(); var settings = app.GetSettings<PointOfSaleSettings>();
var vm = new UpdatePointOfSaleViewModel() var vm = new UpdatePointOfSaleViewModel()
{ {
NotificationEmailWarning = !await IsEmailConfigured(app.StoreDataId), NotificationEmailWarning = !await IsEmailConfigured(app.StoreDataId),
@@ -119,7 +119,7 @@ namespace BTCPayServer.Controllers
NotificationEmail = settings.NotificationEmail, NotificationEmail = settings.NotificationEmail,
NotificationUrl = settings.NotificationUrl, NotificationUrl = settings.NotificationUrl,
SearchTerm = $"storeid:{app.StoreDataId}", 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) if (HttpContext?.Request != null)
{ {
@@ -197,8 +197,8 @@ namespace BTCPayServer.Controllers
NotificationEmail = vm.NotificationEmail, NotificationEmail = vm.NotificationEmail,
Description = vm.Description, Description = vm.Description,
EmbeddedCSS = vm.EmbeddedCSS, 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); await _AppService.UpdateOrCreateApp(app);
TempData[WellKnownTempData.SuccessMessage] = "App updated"; TempData[WellKnownTempData.SuccessMessage] = "App updated";
@@ -211,8 +211,8 @@ namespace BTCPayServer.Controllers
if (string.IsNullOrEmpty(list)) if (string.IsNullOrEmpty(list))
{ {
return Array.Empty<int>(); return Array.Empty<int>();
} }
else else
{ {
// Remove all characters except numeric and comma // Remove all characters except numeric and comma
Regex charsToDestroy = new Regex(@"[^\d|\" + separator + "]"); Regex charsToDestroy = new Regex(@"[^\d|\" + separator + "]");

View File

@@ -10,16 +10,20 @@ namespace BTCPayServer.Models.AppViewModels
public class UpdateCrowdfundViewModel public class UpdateCrowdfundViewModel
{ {
public string StoreId { get; set; } 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")] [Display(Name = "Featured Image")]
public string MainImageUrl { get; set; } public string MainImageUrl { get; set; }
[Display(Name = "Callback Notification Url")] [Display(Name = "Callback Notification Url")]
[Uri] [Uri]
public string NotificationUrl { get; set; } public string NotificationUrl { get; set; }
[Display(Name = "Invoice IPN Notification")] [Display(Name = "Invoice IPN Notification")]
@@ -59,7 +63,8 @@ namespace BTCPayServer.Models.AppViewModels
public IEnumerable<string> ResetEveryValues = Enum.GetNames(typeof(CrowdfundResetEvery)); public IEnumerable<string> 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; public int ResetEveryAmount { get; set; } = 1;
@@ -78,7 +83,7 @@ namespace BTCPayServer.Models.AppViewModels
public string EmbeddedCSS { get; set; } public string EmbeddedCSS { get; set; }
[Display(Name = "Count all invoices created on the store as part of the crowdfunding goal")] [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 AppId { get; set; }
public string SearchTerm { 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")] [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.")] [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; } public bool NotificationEmailWarning { get; set; }
// NOTE: Improve validation if needed
public bool ModelWithMinimumData
{
get { return Description != null && Title != null && TargetCurrency != null; }
}
} }
} }

View File

@@ -263,13 +263,12 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<label>Price</label>* <label>Price</label>*
<input <input class="js-product-price form-control mb-2"
class="js-product-price form-control mb-2" inputmode="numeric"
inputmode="numeric" pattern="\d*"
pattern="\d*" step="any"
step="any" type="number"
type="number" value="{price}" />
value="{price}" />
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<label>Custom price</label> <label>Custom price</label>
@@ -293,7 +292,7 @@
<div class="form-row"> <div class="form-row">
<div class="col"> <div class="col">
<label>Inventory (leave blank to not use inventory feature)</label> <label>Inventory (leave blank to not use inventory feature)</label>
<input type="number" step="1" class="js-product-inventory form-control mb-2" value="{inventory}"/> <input type="number" step="1" class="js-product-inventory form-control mb-2" value="{inventory}" />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -261,12 +261,11 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<label>Price</label>* <label>Price</label>*
<input <input class="js-product-price form-control mb-2"
class="js-product-price form-control mb-2" inputmode="numeric"
inputmode="numeric" pattern="\d*"
pattern="\d*" type="number"
type="number" value="{price}" />
value="{price}" />
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<label>Custom price</label> <label>Custom price</label>
@@ -290,7 +289,7 @@
<div class="form-row"> <div class="form-row">
<div class="col"> <div class="col">
<label>Inventory (leave blank to not use inventory feature)</label> <label>Inventory (leave blank to not use inventory feature)</label>
<input type="number" step="1" class="js-product-inventory form-control mb-2" value="{inventory}"/> <input type="number" step="1" class="js-product-inventory form-control mb-2" value="{inventory}" />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -33,27 +33,27 @@
<bundle name="wwwroot/bundles/crowdfund-bundle.min.css"></bundle> <bundle name="wwwroot/bundles/crowdfund-bundle.min.css"></bundle>
@if (!string.IsNullOrEmpty(Model.EmbeddedCSS)) @if (!string.IsNullOrEmpty(Model.EmbeddedCSS))
{ {
@Safe.Raw($"<style>{Model.EmbeddedCSS}</style>"); @Safe.Raw($"<style>{Model.EmbeddedCSS}</style>");
} }
</head> </head>
<body> <body>
@if (Context.Request.Query.ContainsKey("simple")) @if (Context.Request.Query.ContainsKey("simple"))
{
@await Html.PartialAsync("/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml", Model)
}
else
{
<noscript>
@await Html.PartialAsync("/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml", Model)
</noscript>
if (Model.AnimationsEnabled)
{ {
<canvas id="fireworks"></canvas> @await Html.PartialAsync("/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml", Model)
}
else
{
<noscript>
@await Html.PartialAsync("/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml", Model)
</noscript>
if (Model.AnimationsEnabled)
{
<canvas id="fireworks"></canvas>
}
@await Html.PartialAsync("/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml", Model)
} }
@await Html.PartialAsync("/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml", Model)
}
</body> </body>
</html> </html>