2022-07-06 05:40:16 +02:00
|
|
|
using System;
|
2023-03-16 07:51:24 +01:00
|
|
|
using System.Security.AccessControl;
|
2022-04-12 09:55:10 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Data;
|
|
|
|
using BTCPayServer.Models.AppViewModels;
|
|
|
|
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.AppSales;
|
|
|
|
|
2022-07-06 05:40:16 +02:00
|
|
|
public enum AppSalesPeriod
|
|
|
|
{
|
|
|
|
Week,
|
|
|
|
Month
|
|
|
|
}
|
|
|
|
|
2022-04-12 09:55:10 +02:00
|
|
|
public class AppSales : ViewComponent
|
|
|
|
{
|
|
|
|
private readonly AppService _appService;
|
|
|
|
|
2022-07-06 05:40:16 +02:00
|
|
|
public AppSales(AppService appService)
|
2022-04-12 09:55:10 +02:00
|
|
|
{
|
|
|
|
_appService = appService;
|
|
|
|
}
|
|
|
|
|
2023-03-16 07:51:24 +01: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);
|
|
|
|
if (type is not IHasSaleStatsAppType salesAppType || type is not AppBaseType appBaseType)
|
|
|
|
return new HtmlContentViewComponentResult(new StringHtmlContent(string.Empty));
|
2023-03-17 03:56:32 +01:00
|
|
|
var vm = new AppSalesViewModel
|
2023-03-16 07:51:24 +01:00
|
|
|
{
|
|
|
|
Id = appId,
|
|
|
|
AppType = appType,
|
2023-03-17 03:56:32 +01:00
|
|
|
DataUrl = Url.Action("AppSales", "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-04-10 11:07:03 +09:00
|
|
|
|
2023-03-16 07:51:24 +01:00
|
|
|
var app = HttpContext.GetAppData();
|
2023-03-17 03:56:32 +01:00
|
|
|
var stats = await _appService.GetSalesStats(app);
|
2022-07-06 05:40:16 +02:00
|
|
|
vm.SalesCount = stats.SalesCount;
|
|
|
|
vm.Series = stats.Series;
|
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);
|
|
|
|
}
|
|
|
|
}
|