Skip to content

Commit 55bfdfa

Browse files
committed
feat(portal): add Tenants/Cells/Operations pages with in-memory data service and DI wiring
1 parent fd3cf29 commit 55bfdfa

File tree

7 files changed

+157
-0
lines changed

7 files changed

+157
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Stamps.ManagementPortal.Models;
2+
3+
public record Tenant(string Id, string DisplayName, string Domain, string Tier, string Status, string CellId);
4+
public record Cell(string Id, string Region, string AvailabilityZone, string Status, int CapacityUsed, int CapacityTotal);
5+
public record Operation(string Id, string TenantId, string Type, string Status, DateTimeOffset CreatedAt);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@page "/cells"
2+
@inject Stamps.ManagementPortal.Services.IDataService Data
3+
4+
<h1>Cells</h1>
5+
6+
@if (cells is null)
7+
{
8+
<p>Loading...</p>
9+
}
10+
else
11+
{
12+
<table>
13+
<thead>
14+
<tr><th>Id</th><th>Region</th><th>AZ</th><th>Status</th><th>Utilization</th></tr>
15+
</thead>
16+
<tbody>
17+
@foreach (var c in cells)
18+
{
19+
<tr>
20+
<td>@c.Id</td>
21+
<td>@c.Region</td>
22+
<td>@c.AvailabilityZone</td>
23+
<td>@c.Status</td>
24+
<td>@c.CapacityUsed/@c.CapacityTotal</td>
25+
</tr>
26+
}
27+
</tbody>
28+
</table>
29+
}
30+
31+
@code {
32+
private IReadOnlyList<Stamps.ManagementPortal.Models.Cell>? cells;
33+
protected override async Task OnInitializedAsync()
34+
{
35+
cells = await Data.GetCellsAsync();
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@page "/operations"
2+
@inject Stamps.ManagementPortal.Services.IDataService Data
3+
4+
<h1>Operations</h1>
5+
6+
@if (ops is null)
7+
{
8+
<p>Loading...</p>
9+
}
10+
else
11+
{
12+
<table>
13+
<thead>
14+
<tr><th>Id</th><th>Tenant</th><th>Type</th><th>Status</th><th>Created</th></tr>
15+
</thead>
16+
<tbody>
17+
@foreach (var o in ops)
18+
{
19+
<tr>
20+
<td>@o.Id</td>
21+
<td>@o.TenantId</td>
22+
<td>@o.Type</td>
23+
<td>@o.Status</td>
24+
<td>@o.CreatedAt.ToLocalTime()</td>
25+
</tr>
26+
}
27+
</tbody>
28+
</table>
29+
}
30+
31+
@code {
32+
private IReadOnlyList<Stamps.ManagementPortal.Models.Operation>? ops;
33+
protected override async Task OnInitializedAsync()
34+
{
35+
ops = await Data.GetOperationsAsync();
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@page "/tenants"
2+
@inject Stamps.ManagementPortal.Services.IDataService Data
3+
4+
<h1>Tenants</h1>
5+
6+
@if (tenants is null)
7+
{
8+
<p>Loading...</p>
9+
}
10+
else
11+
{
12+
<table>
13+
<thead>
14+
<tr><th>Id</th><th>Name</th><th>Domain</th><th>Tier</th><th>Status</th><th>Cell</th></tr>
15+
</thead>
16+
<tbody>
17+
@foreach (var t in tenants)
18+
{
19+
<tr>
20+
<td>@t.Id</td>
21+
<td>@t.DisplayName</td>
22+
<td>@t.Domain</td>
23+
<td>@t.Tier</td>
24+
<td>@t.Status</td>
25+
<td>@t.CellId</td>
26+
</tr>
27+
}
28+
</tbody>
29+
</table>
30+
}
31+
32+
@code {
33+
private IReadOnlyList<Stamps.ManagementPortal.Models.Tenant>? tenants;
34+
protected override async Task OnInitializedAsync()
35+
{
36+
tenants = await Data.GetTenantsAsync();
37+
}
38+
}

management-portal/src/Portal/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using Microsoft.AspNetCore.Components;
22
using Microsoft.AspNetCore.Components.Web;
3+
using ServiceDefaults;
34

45
var builder = WebApplication.CreateBuilder(args);
6+
builder.AddServiceDefaults("Stamps.ManagementPortal");
57

68
builder.Services.AddRazorPages();
79
builder.Services.AddServerSideBlazor();
10+
builder.Services.AddSingleton<Stamps.ManagementPortal.Services.IDataService, Stamps.ManagementPortal.Services.InMemoryDataService>();
811

912
var app = builder.Build();
1013

@@ -20,5 +23,6 @@
2023

2124
app.MapBlazorHub();
2225
app.MapFallbackToPage("/_Host");
26+
app.MapHealthChecks("/health");
2327

2428
app.Run();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Stamps.ManagementPortal.Models;
2+
3+
namespace Stamps.ManagementPortal.Services;
4+
5+
public interface IDataService
6+
{
7+
Task<IReadOnlyList<Tenant>> GetTenantsAsync(CancellationToken ct = default);
8+
Task<IReadOnlyList<Cell>> GetCellsAsync(CancellationToken ct = default);
9+
Task<IReadOnlyList<Operation>> GetOperationsAsync(CancellationToken ct = default);
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Stamps.ManagementPortal.Models;
2+
3+
namespace Stamps.ManagementPortal.Services;
4+
5+
public class InMemoryDataService : IDataService
6+
{
7+
private static readonly IReadOnlyList<Tenant> Tenants = new List<Tenant>
8+
{
9+
new("contoso","Contoso","contoso.com","enterprise","active","cell-eastus-1"),
10+
new("fabrikam","Fabrikam","fabrikam.io","smb","active","cell-westus-1")
11+
};
12+
private static readonly IReadOnlyList<Cell> Cells = new List<Cell>
13+
{
14+
new("cell-eastus-1","eastus","1","healthy",60,100),
15+
new("cell-westus-1","westus","2","healthy",40,100)
16+
};
17+
private static readonly IReadOnlyList<Operation> Operations = new List<Operation>
18+
{
19+
new("op-001","contoso","migrate","running", DateTimeOffset.UtcNow.AddMinutes(-12)),
20+
new("op-002","fabrikam","suspend","completed", DateTimeOffset.UtcNow.AddDays(-1))
21+
};
22+
23+
public Task<IReadOnlyList<Tenant>> GetTenantsAsync(CancellationToken ct = default) => Task.FromResult(Tenants);
24+
public Task<IReadOnlyList<Cell>> GetCellsAsync(CancellationToken ct = default) => Task.FromResult(Cells);
25+
public Task<IReadOnlyList<Operation>> GetOperationsAsync(CancellationToken ct = default) => Task.FromResult(Operations);
26+
}

0 commit comments

Comments
 (0)