add rich text and options

This commit is contained in:
Kukks
2019-01-02 12:47:06 +01:00
parent 92a2bb4d32
commit e4b9895ba7
6 changed files with 42 additions and 13 deletions

View File

@@ -36,6 +36,7 @@ namespace BTCPayServer.Controllers
public bool SoundsEnabled { get; set; } public bool SoundsEnabled { get; set; }
public string DisqusShortname { get; set; } public string DisqusShortname { get; set; }
public bool AnimationsEnabled { get; set; } public bool AnimationsEnabled { get; set; }
public bool UseInvoiceAmount { get; set; }
} }
@@ -67,6 +68,7 @@ namespace BTCPayServer.Controllers
SoundsEnabled = settings.SoundsEnabled, SoundsEnabled = settings.SoundsEnabled,
DisqusShortname = settings.DisqusShortname, DisqusShortname = settings.DisqusShortname,
AnimationsEnabled = settings.AnimationsEnabled, AnimationsEnabled = settings.AnimationsEnabled,
UseInvoiceAmount = settings.UseInvoiceAmount
}; };
return View(vm); return View(vm);
} }
@@ -114,6 +116,8 @@ namespace BTCPayServer.Controllers
SoundsEnabled = vm.SoundsEnabled, SoundsEnabled = vm.SoundsEnabled,
DisqusShortname = vm.DisqusShortname, DisqusShortname = vm.DisqusShortname,
AnimationsEnabled = vm.AnimationsEnabled, AnimationsEnabled = vm.AnimationsEnabled,
UseInvoiceAmount = vm.UseInvoiceAmount
}); });
await UpdateAppSettings(app); await UpdateAppSettings(app);
_EventAggregator.Publish(new CrowdfundAppUpdated() _EventAggregator.Publish(new CrowdfundAppUpdated()

View File

@@ -99,10 +99,10 @@ namespace BTCPayServer.Hubs
switch (invoiceEvent.Name) switch (invoiceEvent.Name)
{ {
case InvoiceEvent.ReceivedPayment: case InvoiceEvent.ReceivedPayment:
var data = invoiceEvent.Payment.GetCryptoPaymentData();
_HubContext.Clients.Group(appId).SendCoreAsync(CrowdfundHub.PaymentReceived, new object[] _HubContext.Clients.Group(appId).SendCoreAsync(CrowdfundHub.PaymentReceived, new object[]
{ {
invoiceEvent.Payment.GetCryptoPaymentData().GetValue(), data.GetValue(),
invoiceEvent.Payment.GetCryptoCode(), invoiceEvent.Payment.GetCryptoCode(),
Enum.GetName(typeof(PaymentTypes), Enum.GetName(typeof(PaymentTypes),
invoiceEvent.Payment.GetPaymentMethodId().PaymentType) invoiceEvent.Payment.GetPaymentMethodId().PaymentType)
@@ -127,13 +127,11 @@ namespace BTCPayServer.Hubs
} }
private static async Task<decimal> GetCurrentContributionAmount(InvoiceEntity[] invoices, string primaryCurrency, private static async Task<decimal> GetCurrentContributionAmount(Dictionary<string, decimal> stats, string primaryCurrency,
RateFetcher rateFetcher, RateRules rateRules) RateFetcher rateFetcher, RateRules rateRules)
{ {
decimal result = 0; decimal result = 0;
var stats = GetCurrentContributionAmountStats(invoices);
var ratesTask = rateFetcher.FetchRates( var ratesTask = rateFetcher.FetchRates(
stats.Keys stats.Keys
.Select((x) => new CurrencyPair(PaymentMethodId.Parse(x).CryptoCode, primaryCurrency)) .Select((x) => new CurrencyPair(PaymentMethodId.Parse(x).CryptoCode, primaryCurrency))
@@ -158,8 +156,9 @@ namespace BTCPayServer.Hubs
return result; return result;
} }
private static Dictionary<string, decimal> GetCurrentContributionAmountStats(InvoiceEntity[] invoices) private static Dictionary<string, decimal> GetCurrentContributionAmountStats(InvoiceEntity[] invoices, bool usePaymentData = true)
{ {
if(usePaymentData){
var payments = invoices.SelectMany(entity => entity.GetPayments()); var payments = invoices.SelectMany(entity => entity.GetPayments());
var groupedByMethod = payments.GroupBy(entity => entity.GetPaymentMethodId()); var groupedByMethod = payments.GroupBy(entity => entity.GetPaymentMethodId());
@@ -167,6 +166,15 @@ namespace BTCPayServer.Hubs
return groupedByMethod.ToDictionary(entities => entities.Key.ToString(), return groupedByMethod.ToDictionary(entities => entities.Key.ToString(),
entities => entities.Sum(entity => entity.GetCryptoPaymentData().GetValue())); entities => entities.Sum(entity => entity.GetCryptoPaymentData().GetValue()));
} }
else
{
return invoices
.GroupBy(entity => entity.ProductInformation.Currency)
.ToDictionary(
entities => entities.Key,
entities => entities.Sum(entity => entity.ProductInformation.Price));
}
}
private async Task<ViewCrowdfundViewModel> GetInfo(AppData appData, string statusMessage= null) private async Task<ViewCrowdfundViewModel> GetInfo(AppData appData, string statusMessage= null)
{ {
var settings = appData.GetSettings<AppsController.CrowdfundSettings>(); var settings = appData.GetSettings<AppsController.CrowdfundSettings>();
@@ -177,15 +185,16 @@ namespace BTCPayServer.Hubs
var rateRules = appData.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider); var rateRules = appData.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider);
var pendingPaymentStats = GetCurrentContributionAmountStats(pendingInvoices, !settings.UseInvoiceAmount);
var paymentStats = GetCurrentContributionAmountStats(completeInvoices, !settings.UseInvoiceAmount);
var currentAmount = await GetCurrentContributionAmount( var currentAmount = await GetCurrentContributionAmount(
completeInvoices, paymentStats,
settings.TargetCurrency, _RateFetcher, rateRules); settings.TargetCurrency, _RateFetcher, rateRules);
var currentPendingAmount = await GetCurrentContributionAmount( var currentPendingAmount = await GetCurrentContributionAmount(
pendingInvoices, pendingPaymentStats,
settings.TargetCurrency, _RateFetcher, rateRules); settings.TargetCurrency, _RateFetcher, rateRules);
var pendingPaymentStats = GetCurrentContributionAmountStats(pendingInvoices);
var paymentStats = GetCurrentContributionAmountStats(completeInvoices);
return new ViewCrowdfundViewModel() return new ViewCrowdfundViewModel()
{ {

View File

@@ -62,5 +62,7 @@ namespace BTCPayServer.Models.AppViewModels
public string EmbeddedCSS { get; set; } public string EmbeddedCSS { get; set; }
[Display(Name = "Base the contributed goal amount on the invoice amount and not actual payments")]
public bool UseInvoiceAmount { get; set; } = true;
} }
} }

View File

@@ -50,7 +50,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Description" class="control-label"></label>* <label asp-for="Description" class="control-label"></label>*
<textarea asp-for="Description" rows="20" cols="40" class="form-control"></textarea> <textarea asp-for="Description" rows="20" cols="40" class="form-control richtext"></textarea>
<span asp-validation-for="Description" class="text-danger"></span> <span asp-validation-for="Description" class="text-danger"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -121,6 +121,11 @@
<input asp-for="Enabled" type="checkbox" class="form-check"/> <input asp-for="Enabled" type="checkbox" class="form-check"/>
<span asp-validation-for="Enabled" class="text-danger"></span> <span asp-validation-for="Enabled" class="text-danger"></span>
</div> </div>
<div class="form-group">
<label asp-for="UseInvoiceAmount"></label>
<input asp-for="UseInvoiceAmount" type="checkbox" class="form-check"/>
<span asp-validation-for="UseInvoiceAmount" class="text-danger"></span>
</div>
<div class="form-group"> <div class="form-group">
<label asp-for="SoundsEnabled"></label> <label asp-for="SoundsEnabled"></label>
<input asp-for="SoundsEnabled" type="checkbox" class="form-check"/> <input asp-for="SoundsEnabled" type="checkbox" class="form-check"/>
@@ -154,7 +159,14 @@
@section Scripts { @section Scripts {
<link rel="stylesheet" href="~/vendor/highlightjs/default.min.css"> <link rel="stylesheet" href="~/vendor/highlightjs/default.min.css">
<script src="~/vendor/highlightjs/highlight.min.js"></script> <script src="~/vendor/highlightjs/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script> <script src="~/vendor/richtext/jquery.richtext.min.js"></script>
<link rel="stylesheet" href="~/vendor/richtext/richtext.min.css">
<script>
hljs.initHighlightingOnLoad();
$(document).ready(function() {
$(".richtext").richText();
});
</script>
<script id="template-product-item" type="text/template"> <script id="template-product-item" type="text/template">
<div class="col-sm-4 col-md-3 mb-3"> <div class="col-sm-4 col-md-3 mb-3">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long