From 492512f527fa711fe82816a9c8302f4a56185301 Mon Sep 17 00:00:00 2001 From: d11n Date: Thu, 14 Sep 2023 02:26:47 +0200 Subject: [PATCH] Dashboard: Show revenue data for keypad (#5317) * POS: Display fixes * Dashboard: Fix Top Items component * Dashboard: Fix App Sales component * Dashboard: Show revenue data for keypad Closes #5303. --- .../Components/AppSales/Default.cshtml.js | 15 ++++++--------- .../Components/AppTopItems/Default.cshtml | 4 ++-- .../Components/AppTopItems/Default.cshtml.js | 7 +++---- .../Plugins/PointOfSale/PointOfSalePlugin.cs | 4 ++-- BTCPayServer/Services/Apps/AppService.cs | 12 +++++------- .../Views/Shared/PointOfSale/Public/Cart.cshtml | 2 +- .../Views/Shared/PointOfSale/Public/Static.cshtml | 2 +- BTCPayServer/wwwroot/pos/common.css | 1 - 8 files changed, 20 insertions(+), 27 deletions(-) diff --git a/BTCPayServer/Components/AppSales/Default.cshtml.js b/BTCPayServer/Components/AppSales/Default.cshtml.js index 49ebd2716..055596b1e 100644 --- a/BTCPayServer/Components/AppSales/Default.cshtml.js +++ b/BTCPayServer/Components/AppSales/Default.cshtml.js @@ -1,27 +1,24 @@ if (!window.appSales) { - window.appSales = - { - dataLoaded: function (model) { - const id = "AppSales-" + model.id; + window.appSales = { + dataLoaded (model) { + const id = `AppSales-${model.id}`; const appId = model.id; const period = model.period; - const baseUrl = model.url; + const baseUrl = model.dataUrl; const data = model; const render = (data, period) => { const series = data.series.map(s => s.salesCount); - const labels = data.series.map((s, i) => period === model.period ? s.label : (i % 5 === 0 ? s.label : '')); + const labels = data.series.map((s, i) => period === 'Month' ? (i % 5 === 0 ? s.label : '') : s.label); const min = Math.min(...series); const max = Math.max(...series); const low = min === max ? 0 : Math.max(min - ((max - min) / 5), 0); - document.querySelectorAll(`#${id} .sales-count`).innerText = data.salesCount; - new Chartist.Bar(`#${id} .ct-chart`, { labels, series: [series] }, { - low, + low }); }; diff --git a/BTCPayServer/Components/AppTopItems/Default.cshtml b/BTCPayServer/Components/AppTopItems/Default.cshtml index bbaa56b21..ea6efdf87 100644 --- a/BTCPayServer/Components/AppTopItems/Default.cshtml +++ b/BTCPayServer/Components/AppTopItems/Default.cshtml @@ -27,8 +27,8 @@ const response = await fetch(url); if (response.ok) { document.getElementById(`AppTopItems-${appId}`).outerHTML = await response.text(); - const data = document.querySelector(`#AppSales-${appId} template`); - if (data) window.appSales.dataLoaded(JSON.parse(data.innerHTML)); + const data = document.querySelector(`#AppTopItems-${appId} template`); + if (data) window.appTopItems.dataLoaded(JSON.parse(data.innerHTML)); } })(); diff --git a/BTCPayServer/Components/AppTopItems/Default.cshtml.js b/BTCPayServer/Components/AppTopItems/Default.cshtml.js index 8eb3adf99..2d6c09583 100644 --- a/BTCPayServer/Components/AppTopItems/Default.cshtml.js +++ b/BTCPayServer/Components/AppTopItems/Default.cshtml.js @@ -1,8 +1,7 @@ if (!window.appTopItems) { - window.appTopItems = - { - dataLoaded: function (model) { - const id = "AppTopItems-" + model.id; + window.appTopItems = { + dataLoaded (model) { + const id = `AppTopItems-${model.id}`; const series = model.salesCount; new Chartist.Bar(`#${id} .ct-chart`, { series }, { distributeSeries: true, diff --git a/BTCPayServer/Plugins/PointOfSale/PointOfSalePlugin.cs b/BTCPayServer/Plugins/PointOfSale/PointOfSalePlugin.cs index 50ecd957b..f271370a3 100644 --- a/BTCPayServer/Plugins/PointOfSale/PointOfSalePlugin.cs +++ b/BTCPayServer/Plugins/PointOfSale/PointOfSalePlugin.cs @@ -40,7 +40,7 @@ namespace BTCPayServer.Plugins.PointOfSale Static, [Display(Name = "Product list with cart")] Cart, - [Display(Name = "Keypad only")] + [Display(Name = "Keypad")] Light, [Display(Name = "Print display")] Print @@ -87,7 +87,7 @@ namespace BTCPayServer.Plugins.PointOfSale public Task> GetItemStats(AppData appData, InvoiceEntity[] paidInvoices) { var settings = appData.GetSettings(); - var items = AppService.Parse( settings.Template); + var items = AppService.Parse(settings.Template); var itemCount = paidInvoices .Where(entity => entity.Currency.Equals(settings.Currency, StringComparison.OrdinalIgnoreCase) && ( // The POS data is present for the cart view, where multiple items can be bought diff --git a/BTCPayServer/Services/Apps/AppService.cs b/BTCPayServer/Services/Apps/AppService.cs index cfdcf53bc..ea8af1f65 100644 --- a/BTCPayServer/Services/Apps/AppService.cs +++ b/BTCPayServer/Services/Apps/AppService.cs @@ -160,12 +160,10 @@ namespace BTCPayServer.Services.Apps { return (res, e) => { - if (e.Metadata.PosData != null) + // flatten single items from POS data + var data = e.Metadata.PosData?.ToObject(); + if (data is { Cart.Length: > 0 }) { - // flatten single items from POS data - var data = e.Metadata.PosData.ToObject(); - if (data is not { Cart.Length: > 0 }) - return res; foreach (var lineItem in data.Cart) { var item = items.FirstOrDefault(p => p.Id == lineItem.Id); @@ -184,10 +182,10 @@ namespace BTCPayServer.Services.Apps } } else - {; + { res.Add(new InvoiceStatsItem { - ItemCode = e.Metadata.ItemCode, + ItemCode = e.Metadata.ItemCode ?? typeof(PosViewType).DisplayName(PosViewType.Light.ToString()), FiatPrice = e.PaidAmount.Net, Date = e.InvoiceTime.Date }); diff --git a/BTCPayServer/Views/Shared/PointOfSale/Public/Cart.cshtml b/BTCPayServer/Views/Shared/PointOfSale/Public/Cart.cshtml index 0d081734d..35410d0a2 100644 --- a/BTCPayServer/Views/Shared/PointOfSale/Public/Cart.cshtml +++ b/BTCPayServer/Views/Shared/PointOfSale/Public/Cart.cshtml @@ -70,7 +70,7 @@ { @item.Title } -
+
@Safe.Raw(item.Title)
@if (item.PriceType == ViewPointOfSaleViewModel.ItemPriceType.Topup || item.Price == 0) diff --git a/BTCPayServer/Views/Shared/PointOfSale/Public/Static.cshtml b/BTCPayServer/Views/Shared/PointOfSale/Public/Static.cshtml index 025fc494b..c6b845f92 100644 --- a/BTCPayServer/Views/Shared/PointOfSale/Public/Static.cshtml +++ b/BTCPayServer/Views/Shared/PointOfSale/Public/Static.cshtml @@ -41,7 +41,7 @@ { @Safe.Raw(item.Title) } -
+
@Safe.Raw(item.Title)
@if (item.PriceType == ViewPointOfSaleViewModel.ItemPriceType.Topup || item.Price == 0) diff --git a/BTCPayServer/wwwroot/pos/common.css b/BTCPayServer/wwwroot/pos/common.css index 35a3d00d0..b3b5579bd 100644 --- a/BTCPayServer/wwwroot/pos/common.css +++ b/BTCPayServer/wwwroot/pos/common.css @@ -56,5 +56,4 @@ .posItem .card .card-img-top { max-height: 210px; object-fit: scale-down; - margin-bottom: auto; }