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

View File

@@ -99,10 +99,10 @@ namespace BTCPayServer.Hubs
switch (invoiceEvent.Name)
{
case InvoiceEvent.ReceivedPayment:
var data = invoiceEvent.Payment.GetCryptoPaymentData();
_HubContext.Clients.Group(appId).SendCoreAsync(CrowdfundHub.PaymentReceived, new object[]
{
invoiceEvent.Payment.GetCryptoPaymentData().GetValue(),
data.GetValue(),
invoiceEvent.Payment.GetCryptoCode(),
Enum.GetName(typeof(PaymentTypes),
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)
{
decimal result = 0;
var stats = GetCurrentContributionAmountStats(invoices);
var ratesTask = rateFetcher.FetchRates(
stats.Keys
.Select((x) => new CurrencyPair(PaymentMethodId.Parse(x).CryptoCode, primaryCurrency))
@@ -158,14 +156,24 @@ namespace BTCPayServer.Hubs
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 groupedByMethod = payments.GroupBy(entity => entity.GetPaymentMethodId());
return groupedByMethod.ToDictionary(entities => entities.Key.ToString(),
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)
{
@@ -177,15 +185,16 @@ namespace BTCPayServer.Hubs
var rateRules = appData.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider);
var pendingPaymentStats = GetCurrentContributionAmountStats(pendingInvoices, !settings.UseInvoiceAmount);
var paymentStats = GetCurrentContributionAmountStats(completeInvoices, !settings.UseInvoiceAmount);
var currentAmount = await GetCurrentContributionAmount(
completeInvoices,
paymentStats,
settings.TargetCurrency, _RateFetcher, rateRules);
var currentPendingAmount = await GetCurrentContributionAmount(
pendingInvoices,
pendingPaymentStats,
settings.TargetCurrency, _RateFetcher, rateRules);
var pendingPaymentStats = GetCurrentContributionAmountStats(pendingInvoices);
var paymentStats = GetCurrentContributionAmountStats(completeInvoices);
return new ViewCrowdfundViewModel()
{

View File

@@ -61,6 +61,8 @@ namespace BTCPayServer.Models.AppViewModels
public string CustomCSSLink { 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 class="form-group">
<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>
</div>
<div class="form-group">
@@ -121,6 +121,11 @@
<input asp-for="Enabled" type="checkbox" class="form-check"/>
<span asp-validation-for="Enabled" class="text-danger"></span>
</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">
<label asp-for="SoundsEnabled"></label>
<input asp-for="SoundsEnabled" type="checkbox" class="form-check"/>
@@ -154,7 +159,14 @@
@section Scripts {
<link rel="stylesheet" href="~/vendor/highlightjs/default.min.css">
<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">
<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