PlanTempusApp/PlanTempus.Application/Features/Dashboard/Components/AttentionList/AttentionListViewComponent.cs

61 lines
1.7 KiB
C#
Raw Permalink 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 AttentionListViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public AttentionListViewComponent(ILocalizationService localization)
{
_localization = localization;
}
2026-01-11 18:18:36 +01:00
public IViewComponentResult Invoke(string key)
{
var model = AttentionListCatalog.Get(key, _localization);
2026-01-11 18:18:36 +01:00
return View(model);
}
}
public class AttentionListViewModel
{
public required string Key { get; init; }
public required string Title { get; init; }
public required IReadOnlyList<string> AttentionKeys { get; init; }
}
internal class AttentionListData
{
public required string Key { get; init; }
public required string TitleKey { get; init; }
public required IReadOnlyList<string> AttentionKeys { get; init; }
}
2026-01-11 18:18:36 +01:00
public static class AttentionListCatalog
{
private static readonly Dictionary<string, AttentionListData> Lists = new()
2026-01-11 18:18:36 +01:00
{
["current-attentions"] = new AttentionListData
2026-01-11 18:18:36 +01:00
{
Key = "current-attentions",
TitleKey = "dashboard.attentions.title",
2026-01-11 18:18:36 +01:00
AttentionKeys = ["attention-1", "attention-2", "attention-3"]
}
};
public static AttentionListViewModel Get(string key, ILocalizationService localization)
2026-01-11 18:18:36 +01:00
{
if (!Lists.TryGetValue(key, out var list))
throw new KeyNotFoundException($"AttentionList with key '{key}' not found");
2026-01-11 18:18:36 +01:00
return new AttentionListViewModel
{
Key = list.Key,
Title = localization.Get(list.TitleKey),
AttentionKeys = list.AttentionKeys
};
2026-01-11 18:18:36 +01:00
}
}