2026-01-11 18:18:36 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-01-12 15:42:18 +01:00
|
|
|
using PlanTempus.Application.Features.Localization.Services;
|
2026-01-11 18:18:36 +01:00
|
|
|
|
|
|
|
|
namespace PlanTempus.Application.Features.Dashboard.Components;
|
|
|
|
|
|
|
|
|
|
public class QuickStatListViewComponent : ViewComponent
|
|
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
private readonly ILocalizationService _localization;
|
|
|
|
|
|
|
|
|
|
public QuickStatListViewComponent(ILocalizationService localization)
|
|
|
|
|
{
|
|
|
|
|
_localization = localization;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 18:18:36 +01:00
|
|
|
public IViewComponentResult Invoke(string key)
|
|
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 15:42:18 +01:00
|
|
|
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
|
|
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
private static readonly Dictionary<string, QuickStatListData> Lists = new()
|
2026-01-11 18:18:36 +01:00
|
|
|
{
|
2026-01-12 15:42:18 +01:00
|
|
|
["this-week"] = new QuickStatListData
|
2026-01-11 18:18:36 +01:00
|
|
|
{
|
|
|
|
|
Key = "this-week",
|
2026-01-12 15:42:18 +01:00
|
|
|
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"]
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-12 15:42:18 +01:00
|
|
|
public static QuickStatListViewModel Get(string key, ILocalizationService localization)
|
2026-01-11 18:18:36 +01:00
|
|
|
{
|
2026-01-12 15:42:18 +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
|
|
|
|
2026-01-12 15:42:18 +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
|
|
|
}
|
|
|
|
|
}
|