mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-31 12:44:29 +01:00
* Dashboard: Fix app stats tiles They broke with #4747, because they contain script blocks that are loaded asynchronuosly and need to get run once the chart data is added to the page. * Refactor PoS dashboard component * Collocate the component JS files in separate files --------- Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Components.AppSales;
|
|
using BTCPayServer.Data;
|
|
using BTCPayServer.Services.Apps;
|
|
using BTCPayServer.Services.Stores;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BTCPayServer.Components.AppTopItems;
|
|
|
|
public class AppTopItems : ViewComponent
|
|
{
|
|
private readonly AppService _appService;
|
|
|
|
public AppTopItems(AppService appService)
|
|
{
|
|
_appService = appService;
|
|
}
|
|
|
|
public async Task<IViewComponentResult> InvokeAsync(string appId, string appType = null)
|
|
{
|
|
var vm = new AppTopItemsViewModel()
|
|
{
|
|
Id = appId,
|
|
AppType = appType,
|
|
Url = Url.Action("AppTopItems", "UIApps", new { appId = appId }),
|
|
InitialRendering = HttpContext.GetAppData()?.Id != appId
|
|
};
|
|
if (vm.InitialRendering)
|
|
return View(vm);
|
|
|
|
var app = HttpContext.GetAppData();
|
|
vm.AppType = app.AppType;
|
|
var entries = Enum.Parse<AppType>(vm.AppType) == AppType.Crowdfund
|
|
? await _appService.GetPerkStats(app)
|
|
: await _appService.GetItemStats(app);
|
|
|
|
vm.SalesCount = entries.Select(e => e.SalesCount).ToList();
|
|
vm.Entries = entries.ToList();
|
|
|
|
return View(vm);
|
|
}
|
|
}
|