|
3 | 3 | @using _10xGitHubPolicies.App.Services.Scanning |
4 | 4 | @using _10xGitHubPolicies.App.ViewModels |
5 | 5 | @using Hangfire |
| 6 | +@using Microsoft.FluentUI.AspNetCore.Components |
| 7 | +@using Microsoft.FluentUI.AspNetCore.Components.Icons |
| 8 | +@using System.Linq |
6 | 9 | @inject IDashboardService DashboardService |
7 | 10 | @inject IScanningService ScanningService |
8 | 11 | @inject IBackgroundJobClient BackgroundJobClient |
9 | 12 |
|
10 | 13 | <PageTitle>Compliance Dashboard</PageTitle> |
11 | 14 |
|
12 | | -<MudGrid Justify="Justify.FlexStart" Spacing="3"> |
13 | | - <MudItem xs="12" sm="6" md="3"> |
14 | | - <MudPaper Elevation="2" Class="pa-4" Style="height: 100%;"> |
15 | | - <MudText Typo="Typo.h6">Overall Compliance</MudText> |
16 | | - <MudText Typo="Typo.h3">@($"{_viewModel?.CompliancePercentage:F2}%")</MudText> |
17 | | - </MudPaper> |
18 | | - </MudItem> |
19 | | - <MudItem xs="12" sm="6" md="3"> |
20 | | - <MudPaper Elevation="2" Class="pa-4" Style="height: 100%;"> |
21 | | - <MudText Typo="Typo.h6">Total Repositories</MudText> |
22 | | - <MudText Typo="Typo.h3">@_viewModel?.TotalRepositories</MudText> |
23 | | - </MudPaper> |
24 | | - </MudItem> |
25 | | - <MudItem xs="12" sm="6" md="3"> |
26 | | - <MudPaper Elevation="2" Class="pa-4" Style="height: 100%; background-color: var(--mud-palette-success); color: var(--mud-palette-success-text);"> |
27 | | - <MudText Typo="Typo.h6">Compliant</MudText> |
28 | | - <MudText Typo="Typo.h3">@_viewModel?.CompliantRepositories</MudText> |
29 | | - </MudPaper> |
30 | | - </MudItem> |
31 | | - <MudItem xs="12" sm="6" md="3"> |
32 | | - <MudPaper Elevation="2" Class="pa-4" Style="height: 100%; background-color: var(--mud-palette-error); color: var(--mud-palette-error-text);"> |
33 | | - <MudText Typo="Typo.h6">Non-Compliant</MudText> |
34 | | - <MudText Typo="Typo.h3">@_viewModel?.NonCompliantRepositoriesCount</MudText> |
35 | | - </MudPaper> |
36 | | - </MudItem> |
37 | | -</MudGrid> |
38 | | - |
39 | | -<MudPaper Elevation="2" Class="mt-4"> |
40 | | - <MudTable Items="@_viewModel?.NonCompliantRepositories" Dense="true" Hover="true" Filter="new Func<NonCompliantRepositoryViewModel, bool>(FilterFunc)"> |
41 | | - <ToolBarContent> |
42 | | - <MudTextField @bind-Value="_nameFilter" Placeholder="Filter by name..." Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField> |
43 | | - <MudSpacer /> |
44 | | - <MudButton Variant="Variant.Filled" |
45 | | - Color="Color.Primary" |
46 | | - StartIcon="@Icons.Material.Filled.Refresh" |
47 | | - OnClick="StartScan" |
48 | | - Disabled="_isScanning"> |
49 | | - @if (_isScanning) |
50 | | - { |
51 | | - <MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" /> |
52 | | - <MudText Class="ms-2">Scanning...</MudText> |
53 | | - } |
54 | | - else |
55 | | - { |
56 | | - <MudText>Scan Now</MudText> |
57 | | - } |
58 | | - </MudButton> |
59 | | - </ToolBarContent> |
60 | | - <HeaderContent> |
61 | | - <MudTh>Repository</MudTh> |
62 | | - <MudTh>Violations</MudTh> |
63 | | - </HeaderContent> |
64 | | - <RowTemplate> |
65 | | - <MudTd DataLabel="Repository"> |
66 | | - <MudLink Href="@context.Url" Target="_blank">@context.Name</MudLink> |
67 | | - </MudTd> |
68 | | - <MudTd DataLabel="Violations"> |
69 | | - @foreach (var policy in context.ViolatedPolicies) |
70 | | - { |
71 | | - <MudChip T="string" Text="@policy" Color="Color.Error" Size="Size.Small" /> |
72 | | - } |
73 | | - </MudTd> |
74 | | - </RowTemplate> |
75 | | - <PagerContent> |
76 | | - <MudTablePager /> |
77 | | - </PagerContent> |
78 | | - </MudTable> |
79 | | -</MudPaper> |
| 15 | +@if (_viewModel == null) |
| 16 | +{ |
| 17 | + <FluentProgress Ring="true" /> |
| 18 | +} |
| 19 | +else |
| 20 | +{ |
| 21 | + <div class="kpi-grid"> |
| 22 | + <FluentCard class="kpi-card"> |
| 23 | + <div class="kpi-title"> |
| 24 | + <FluentIcon Icon="@(Microsoft.FluentUI.AspNetCore.Components.Icons.Regular.Size24.ChartMultiple)" /> |
| 25 | + <span>Overall Compliance</span> |
| 26 | + </div> |
| 27 | + <div class="kpi-value">@($"{_viewModel.CompliancePercentage:F2}%")</div> |
| 28 | + </FluentCard> |
| 29 | + |
| 30 | + <FluentCard class="kpi-card"> |
| 31 | + <div class="kpi-title"> |
| 32 | + <FluentIcon Icon="@(Microsoft.FluentUI.AspNetCore.Components.Icons.Regular.Size24.Apps)" /> |
| 33 | + <span>Total Repositories</span> |
| 34 | + </div> |
| 35 | + <div class="kpi-value">@_viewModel.TotalRepositories</div> |
| 36 | + </FluentCard> |
| 37 | + |
| 38 | + <FluentCard class="kpi-card compliant"> |
| 39 | + <div class="kpi-title"> |
| 40 | + <FluentIcon Icon="@(Microsoft.FluentUI.AspNetCore.Components.Icons.Regular.Size24.ShieldCheckmark)" /> |
| 41 | + <span>Compliant</span> |
| 42 | + </div> |
| 43 | + <div class="kpi-value">@_viewModel.CompliantRepositories</div> |
| 44 | + </FluentCard> |
| 45 | + |
| 46 | + <FluentCard class="kpi-card non-compliant"> |
| 47 | + <div class="kpi-title"> |
| 48 | + <FluentIcon Icon="@(Microsoft.FluentUI.AspNetCore.Components.Icons.Regular.Size24.ShieldError)" /> |
| 49 | + <span>Non-Compliant</span> |
| 50 | + </div> |
| 51 | + <div class="kpi-value">@_viewModel.NonCompliantRepositoriesCount</div> |
| 52 | + </FluentCard> |
| 53 | + </div> |
| 54 | + |
| 55 | + <FluentCard Class="mt-4" Style="padding: 16px; margin-top: 2rem;"> |
| 56 | + <FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center" Style="width: 100%;"> |
| 57 | + <FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center"> |
| 58 | + <FluentIcon Icon="@(Microsoft.FluentUI.AspNetCore.Components.Icons.Regular.Size24.ShieldError)" /> |
| 59 | + <h3 style="margin-left: 8px; margin-bottom: 0;">Non-Compliant Repositories</h3> |
| 60 | + </FluentStack> |
| 61 | + |
| 62 | + <FluentSpacer /> |
| 63 | + |
| 64 | + <FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center"> |
| 65 | + <FluentTextField @bind-Value="_repositoryFilter" Placeholder="Filter by name..." Immediate="true" Style="width: 250px;"/> |
| 66 | + <FluentButton Id="scan-button" Appearance="Appearance.Accent" OnClick="StartScan" Disabled="@_isScanning" Style="margin-left: 16px;"> |
| 67 | + @if (_isScanning) |
| 68 | + { |
| 69 | + <FluentProgress Ring="true" /> |
| 70 | + <span>Scanning...</span> |
| 71 | + } |
| 72 | + else |
| 73 | + { |
| 74 | + <span>Scan Now</span> |
| 75 | + } |
| 76 | + </FluentButton> |
| 77 | + </FluentStack> |
| 78 | + </FluentStack> |
| 79 | + |
| 80 | + @if (GetFilteredRepositories().Any()) |
| 81 | + { |
| 82 | + <FluentDataGrid Items="@GetFilteredRepositories().AsQueryable()" TGridItem="NonCompliantRepositoryViewModel" Striped="true" Style="margin-top: 16px;"> |
| 83 | + <TemplateColumn Title="Repository"> |
| 84 | + <FluentAnchor Href="@context.Url" Target="_blank" Appearance="Appearance.Hypertext">@context.Name</FluentAnchor> |
| 85 | + </TemplateColumn> |
| 86 | + <TemplateColumn Title="Violations"> |
| 87 | + <FluentStack Wrap="true"> |
| 88 | + @foreach (var policy in context.ViolatedPolicies) |
| 89 | + { |
| 90 | + <FluentBadge Appearance="Appearance.Accent" Style="margin: 2px;">@policy</FluentBadge> |
| 91 | + } |
| 92 | + </FluentStack> |
| 93 | + </TemplateColumn> |
| 94 | + </FluentDataGrid> |
| 95 | + } |
| 96 | + else |
| 97 | + { |
| 98 | + <div style="padding: 24px; text-align: center;"> |
| 99 | + <p>All repositories are compliant or match the current filter.</p> |
| 100 | + </div> |
| 101 | + } |
| 102 | + </FluentCard> |
| 103 | +} |
| 104 | + |
| 105 | +<style> |
| 106 | + .kpi-grid { |
| 107 | + display: grid; |
| 108 | + grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); |
| 109 | + gap: 1rem; |
| 110 | + margin-top: 1rem; |
| 111 | + } |
| 112 | +
|
| 113 | + .kpi-card { |
| 114 | + padding: 16px; |
| 115 | + display: flex; |
| 116 | + flex-direction: column; |
| 117 | + justify-content: space-between; |
| 118 | + } |
| 119 | +
|
| 120 | + .kpi-title { |
| 121 | + display: flex; |
| 122 | + align-items: center; |
| 123 | + gap: 8px; |
| 124 | + font-size: 1rem; |
| 125 | + color: var(--neutral-foreground-rest); |
| 126 | + } |
| 127 | + |
| 128 | + .kpi-value { |
| 129 | + font-size: 2.5rem; |
| 130 | + font-weight: 600; |
| 131 | + margin-top: 16px; |
| 132 | + text-align: right; |
| 133 | + } |
| 134 | + |
| 135 | + .compliant { |
| 136 | + border-left: 4px solid var(--success-fill-rest); |
| 137 | + } |
| 138 | + |
| 139 | + .non-compliant { |
| 140 | + border-left: 4px solid var(--error-fill-rest); |
| 141 | + } |
| 142 | +</style> |
80 | 143 |
|
81 | 144 | @code { |
82 | 145 | private DashboardViewModel? _viewModel; |
83 | | - private string _nameFilter = string.Empty; |
84 | 146 | private bool _isScanning = false; |
| 147 | + private string _repositoryFilter = string.Empty; |
85 | 148 |
|
86 | | - protected override async Task OnInitializedAsync() |
| 149 | + private IEnumerable<NonCompliantRepositoryViewModel> GetFilteredRepositories() |
87 | 150 | { |
88 | | - await LoadDashboardData(); |
| 151 | + if (_viewModel?.NonCompliantRepositories == null) |
| 152 | + { |
| 153 | + return Enumerable.Empty<NonCompliantRepositoryViewModel>(); |
| 154 | + } |
| 155 | + |
| 156 | + return _viewModel.NonCompliantRepositories |
| 157 | + .Where(r => string.IsNullOrWhiteSpace(_repositoryFilter) || r.Name.Contains(_repositoryFilter, StringComparison.OrdinalIgnoreCase)); |
89 | 158 | } |
90 | 159 |
|
91 | | - private bool FilterFunc(NonCompliantRepositoryViewModel repo) |
| 160 | + protected override async Task OnInitializedAsync() |
92 | 161 | { |
93 | | - if (string.IsNullOrWhiteSpace(_nameFilter)) |
94 | | - return true; |
95 | | - if (repo.Name.Contains(_nameFilter, StringComparison.OrdinalIgnoreCase)) |
96 | | - return true; |
97 | | - return false; |
| 162 | + await LoadDashboardData(); |
98 | 163 | } |
99 | 164 |
|
100 | 165 | private async Task LoadDashboardData() |
101 | 166 | { |
102 | | - _viewModel = await DashboardService.GetDashboardViewModelAsync(_nameFilter); |
| 167 | + _viewModel = await DashboardService.GetDashboardViewModelAsync(string.Empty); |
103 | 168 | } |
104 | 169 |
|
105 | 170 | private async Task StartScan() |
|
0 commit comments