-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKpiViewComponents.cs
More file actions
21 lines (18 loc) · 922 Bytes
/
KpiViewComponents.cs
File metadata and controls
21 lines (18 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using Code311.Tabler.Core.Mapping;
using Code311.Tabler.Dashboard.Models;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
namespace Code311.Tabler.Dashboard.Kpi;
/// <summary>
/// Renders KPI summary surfaces for dashboard pages.
/// </summary>
public sealed class Cd311KpiSummaryViewComponent(ITablerSemanticClassMapper mapper) : ViewComponent
{
public IViewComponentResult Invoke(string title, IReadOnlyCollection<DashboardKpiItem>? items)
{
var htmlItems = string.Join(string.Empty, (items ?? []).Select(i =>
$"<div class=\"kpi-item text-{mapper.MapTone(i.Tone)}\"><div>{i.Label}</div><strong>{i.Value}</strong><small>{i.Trend}</small></div>"));
return new HtmlContentViewComponentResult(new HtmlString($"<section class=\"kpi-summary\"><h3>{title}</h3><div class=\"kpi-grid\">{htmlItems}</div></section>"));
}
}