2022-06-28 07:05:02 +02:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2022-04-12 09:55:10 +02:00
|
|
|
using System.Threading.Tasks;
|
2023-03-16 07:51:24 +01:00
|
|
|
using BTCPayServer.Components.AppSales;
|
2022-04-12 09:55:10 +02:00
|
|
|
using BTCPayServer.Data;
|
|
|
|
using BTCPayServer.Services.Apps;
|
|
|
|
using BTCPayServer.Services.Stores;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-03-20 10:39:26 +09:00
|
|
|
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
|
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
2022-04-12 09:55:10 +02:00
|
|
|
|
|
|
|
namespace BTCPayServer.Components.AppTopItems;
|
|
|
|
|
|
|
|
public class AppTopItems : ViewComponent
|
|
|
|
{
|
|
|
|
private readonly AppService _appService;
|
|
|
|
|
2022-07-06 05:40:16 +02:00
|
|
|
public AppTopItems(AppService appService)
|
2022-04-12 09:55:10 +02:00
|
|
|
{
|
|
|
|
_appService = appService;
|
|
|
|
}
|
|
|
|
|
2023-03-20 10:39:26 +09:00
|
|
|
public async Task<IViewComponentResult> InvokeAsync(string appId, string appType)
|
2022-04-12 09:55:10 +02:00
|
|
|
{
|
2023-03-20 10:39:26 +09:00
|
|
|
var type = _appService.GetAppType(appType);
|
2023-07-20 09:03:39 +02:00
|
|
|
if (type is not (IHasItemStatsAppType and AppBaseType appBaseType))
|
2023-03-20 10:39:26 +09:00
|
|
|
return new HtmlContentViewComponentResult(new StringHtmlContent(string.Empty));
|
|
|
|
|
2023-03-17 03:56:32 +01:00
|
|
|
var vm = new AppTopItemsViewModel
|
2023-03-16 07:51:24 +01:00
|
|
|
{
|
|
|
|
Id = appId,
|
|
|
|
AppType = appType,
|
2023-03-17 03:56:32 +01:00
|
|
|
DataUrl = Url.Action("AppTopItems", "UIApps", new { appId }),
|
2023-03-16 07:51:24 +01:00
|
|
|
InitialRendering = HttpContext.GetAppData()?.Id != appId
|
|
|
|
};
|
2023-01-06 14:18:07 +01:00
|
|
|
if (vm.InitialRendering)
|
|
|
|
return View(vm);
|
|
|
|
|
2023-03-16 07:51:24 +01:00
|
|
|
var app = HttpContext.GetAppData();
|
2023-03-17 03:56:32 +01:00
|
|
|
var entries = await _appService.GetItemStats(app);
|
2023-03-16 07:51:24 +01:00
|
|
|
vm.SalesCount = entries.Select(e => e.SalesCount).ToList();
|
2023-06-23 11:31:05 +02:00
|
|
|
vm.Entries = entries.Take(5).ToList();
|
2023-03-17 03:56:32 +01:00
|
|
|
vm.AppType = app.AppType;
|
2023-03-20 10:39:26 +09:00
|
|
|
vm.AppUrl = await appBaseType.ConfigureLink(app);
|
|
|
|
vm.Name = app.Name;
|
2022-04-12 09:55:10 +02:00
|
|
|
|
|
|
|
return View(vm);
|
|
|
|
}
|
|
|
|
}
|