From 59fc371cd50b72a875efbcab27874b856c87f904 Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 8 Jan 2019 15:10:05 +0100 Subject: [PATCH] perk count + img fixer --- .../Controllers/AppsPublicController.cs | 33 ++++++++++++++++++- .../Crowdfund/CrowdfundHubStreamer.cs | 8 +++++ .../AppViewModels/ViewCrowdfundViewModel.cs | 5 +-- .../Crowdfund/ContributeForm.cshtml | 6 ++++ .../Crowdfund/MinimalCrowdfund.cshtml | 12 +++---- .../AppsPublic/Crowdfund/VueCrowdfund.cshtml | 7 ++-- BTCPayServer/wwwroot/crowdfund/app.js | 18 ++++++++-- 7 files changed, 75 insertions(+), 14 deletions(-) diff --git a/BTCPayServer/Controllers/AppsPublicController.cs b/BTCPayServer/Controllers/AppsPublicController.cs index b68bab381..4d97d60fe 100644 --- a/BTCPayServer/Controllers/AppsPublicController.cs +++ b/BTCPayServer/Controllers/AppsPublicController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -284,11 +285,41 @@ namespace BTCPayServer.Controllers _HtmlSanitizer = new HtmlSanitizer(); - + _HtmlSanitizer.RemovingAtRule += (sender, args) => + { + Debug.WriteLine(""); + + }; + _HtmlSanitizer.RemovingTag += (sender, args) => + { + Debug.WriteLine(""); + if (args.Tag.TagName.Equals("img", StringComparison.InvariantCultureIgnoreCase)) + { + if (!args.Tag.ClassList.Contains("img-fluid")) + { + args.Tag.ClassList.Add("img-fluid"); + } + + args.Cancel = true; + } + }; + + _HtmlSanitizer.RemovingAttribute += (sender, args) => + { + if (args.Tag.TagName.Equals("img",StringComparison.InvariantCultureIgnoreCase) && + args.Attribute.Name.Equals( "src", StringComparison.InvariantCultureIgnoreCase) && + args.Reason == RemoveReason.NotAllowedUrlValue) + { + args.Cancel = true; + } + Debug.WriteLine(""); + + }; _HtmlSanitizer.RemovingStyle += (sender, args) => { args.Cancel = true; }; _HtmlSanitizer.AllowedAttributes.Add("class"); _HtmlSanitizer.AllowedTags.Add("iframe"); + _HtmlSanitizer.AllowedTags.Remove("img"); _HtmlSanitizer.AllowedAttributes.Add("webkitallowfullscreen"); _HtmlSanitizer.AllowedAttributes.Add("allowfullscreen"); } diff --git a/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs b/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs index eb3c3820b..807e29eff 100644 --- a/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs +++ b/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs @@ -287,6 +287,13 @@ namespace BTCPayServer.Hubs settings.TargetCurrency, rateRules); + + + var perkCount = invoices + .Where(entity => !string.IsNullOrEmpty( entity.ProductInformation.ItemCode)) + .GroupBy(entity => entity.ProductInformation.ItemCode) + .ToDictionary(entities => entities.Key, entities => entities.Count()); + return new ViewCrowdfundViewModel() { Title = settings.Title, @@ -309,6 +316,7 @@ namespace BTCPayServer.Hubs DisqusShortname = settings.DisqusShortname, AnimationsEnabled = settings.AnimationsEnabled, ResetEveryAmount = settings.ResetEveryAmount, + PerkCount = perkCount, ResetEvery = Enum.GetName(typeof(CrowdfundResetEvery),settings.ResetEvery), Info = new ViewCrowdfundViewModel.CrowdfundInfo() { diff --git a/BTCPayServer/Models/AppViewModels/ViewCrowdfundViewModel.cs b/BTCPayServer/Models/AppViewModels/ViewCrowdfundViewModel.cs index df272b6a4..0e1469aa4 100644 --- a/BTCPayServer/Models/AppViewModels/ViewCrowdfundViewModel.cs +++ b/BTCPayServer/Models/AppViewModels/ViewCrowdfundViewModel.cs @@ -32,7 +32,8 @@ namespace BTCPayServer.Models.AppViewModels public int ResetEveryAmount { get; set; } public string ResetEvery { get; set; } - + public Dictionary PerkCount { get; set; } + public class CrowdfundInfo { public int TotalContributors { get; set; } @@ -50,7 +51,7 @@ namespace BTCPayServer.Models.AppViewModels public bool Started => !StartDate.HasValue || DateTime.Now.ToUniversalTime() > StartDate; public bool Ended => !EndDate.HasValue || DateTime.Now.ToUniversalTime() > EndDate; - + } public class ContributeToCrowdfund diff --git a/BTCPayServer/Views/AppsPublic/Crowdfund/ContributeForm.cshtml b/BTCPayServer/Views/AppsPublic/Crowdfund/ContributeForm.cshtml index f0e299204..586926088 100644 --- a/BTCPayServer/Views/AppsPublic/Crowdfund/ContributeForm.cshtml +++ b/BTCPayServer/Views/AppsPublic/Crowdfund/ContributeForm.cshtml @@ -38,6 +38,12 @@

@Html.Raw(item.Description)

+ @if (Model.ViewCrowdfundViewModel.PerkCount.ContainsKey(item.Id)) + { + + } } @if (Model.ViewCrowdfundViewModel.Started && !Model.ViewCrowdfundViewModel.Ended) diff --git a/BTCPayServer/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml b/BTCPayServer/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml index bc27e8e29..d20c4fdc2 100644 --- a/BTCPayServer/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml +++ b/BTCPayServer/Views/AppsPublic/Crowdfund/MinimalCrowdfund.cshtml @@ -43,11 +43,11 @@ } @if (Model.EnforceTargetAmount) { - Hardcap Goal + Hardcap Goal } else { - Softcap Goal + Softcap Goal } } @@ -89,7 +89,7 @@ @if (Model.Started && !Model.Ended) { -
+
@TimeZoneInfo.ConvertTimeFromUtc(Model.EndDate.Value, TimeZoneInfo.Local) @@ -98,7 +98,7 @@
} else if (!Model.Started) { -
+
@TimeZoneInfo.ConvertTimeFromUtc(Model.StartDate.Value, TimeZoneInfo.Local)
@@ -107,7 +107,7 @@ }else if (Model.Ended) { -
+
Campaign
@@ -145,7 +145,7 @@
- @@ -154,7 +154,7 @@ + :perks="perks">
@@ -251,6 +251,9 @@
+ diff --git a/BTCPayServer/wwwroot/crowdfund/app.js b/BTCPayServer/wwwroot/crowdfund/app.js index f5689aca8..2bdaa8df7 100644 --- a/BTCPayServer/wwwroot/crowdfund/app.js +++ b/BTCPayServer/wwwroot/crowdfund/app.js @@ -125,12 +125,24 @@ addLoadEvent(function (ev) { } for (var i = 0; i < result.length; i++) { - if(result.label.endsWith("LIGHTNINGLIKE")){ - result.label = result.label.substr(0,result.label.findIndex("LIGHTNINGLIKE")); - result.lightning = true; + var current = result[i]; + if(current.label.endsWith("LightningLike")){ + current.label = current.label.substr(0,current.label.findIndex("LightningLike")); + current.lightning = true; } } + return result; + }, + perks: function(){ + var result = []; + for (var i = 0; i < this.srvModel.perks.length; i++) { + var currentPerk = this.srvModel.perks[i]; + if(this.srvModel.perkCount.hasOwnProperty(currentPerk.id)){ + currentPerk.sold = this.srvModel.perkCount[currentPerk.id]; + } + result.push(currentPerk); + } return result; } },