PlanTempusApp/PlanTempus.Application/Features/Dashboard/Components/QuickStatList/QuickStatListViewComponent.cs

65 lines
1.9 KiB
C#
Raw Normal View History

2026-01-11 18:18:36 +01:00
using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
2026-01-11 18:18:36 +01:00
namespace PlanTempus.Application.Features.Dashboard.Components;
public class QuickStatListViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public QuickStatListViewComponent(ILocalizationService localization)
{
_localization = localization;
}
2026-01-11 18:18:36 +01:00
public IViewComponentResult Invoke(string key)
{
var model = QuickStatListCatalog.Get(key, _localization);
2026-01-11 18:18:36 +01:00
return View(model);
}
}
public class QuickStatListViewModel
{
public required string Key { get; init; }
public required string Title { get; init; }
public required string Icon { get; init; }
public required IReadOnlyList<string> StatKeys { get; init; }
}
internal class QuickStatListData
{
public required string Key { get; init; }
public required string TitleKey { get; init; }
public required string Icon { get; init; }
public required IReadOnlyList<string> StatKeys { get; init; }
}
2026-01-11 18:18:36 +01:00
public static class QuickStatListCatalog
{
private static readonly Dictionary<string, QuickStatListData> Lists = new()
2026-01-11 18:18:36 +01:00
{
["this-week"] = new QuickStatListData
2026-01-11 18:18:36 +01:00
{
Key = "this-week",
TitleKey = "dashboard.quickStats.title",
2026-01-11 18:18:36 +01:00
Icon = "chart-line-up",
StatKeys = ["bookings-week", "revenue-week", "new-customers", "avg-occupancy"]
}
};
public static QuickStatListViewModel Get(string key, ILocalizationService localization)
2026-01-11 18:18:36 +01:00
{
if (!Lists.TryGetValue(key, out var list))
throw new KeyNotFoundException($"QuickStatList with key '{key}' not found");
2026-01-11 18:18:36 +01:00
return new QuickStatListViewModel
{
Key = list.Key,
Title = localization.Get(list.TitleKey),
Icon = list.Icon,
StatKeys = list.StatKeys
};
2026-01-11 18:18:36 +01:00
}
}