|
1 | 1 | @using Microsoft.AspNetCore.SignalR.Client |
2 | 2 | @using OpenShock.Desktop.Backend |
| 3 | +@using OpenShock.Desktop.ModuleBase.Models |
3 | 4 | @using OpenShock.Desktop.ModuleManager |
4 | 5 | @using OpenShock.Desktop.Services |
5 | 6 | @using OpenShock.Desktop.Ui.Utils |
6 | 7 | @using OpenShock.SDK.CSharp.Hub |
7 | 8 | @using OpenShock.Desktop.Ui.Pages.Dash.Components |
| 9 | +@using OpenShock.SDK.CSharp.Models |
8 | 10 | @using StatePart = OpenShock.Desktop.Ui.Pages.Dash.Components.StatePart |
9 | 11 | @inject OpenShockApi Api |
10 | 12 | @inject OpenShockHubClient ApiHubClient |
11 | 13 | @inject ISnackbar Snackbar |
12 | 14 | @inject LiveControlManager LiveControlManager |
13 | 15 | @inject StatusHandler StatusHandler |
14 | 16 | @inject ModuleManager ModuleManager |
| 17 | +@inject AuthService AuthService |
15 | 18 | @implements IAsyncDisposable |
16 | 19 |
|
17 | 20 | <MudPaper Width="250px" Height="100%" Elevation="0" Class="flex-none"> |
|
22 | 25 | <div class="d-flex" style="align-items: center"> |
23 | 26 | @* ReSharper disable once Html.PathError *@ |
24 | 27 | <a href="/dash/dashboard"> |
25 | | - <MudImage Src="images/NavbarLogoSpin.svg" Alt="Logo" Height="45" Width="218" Class="mx-4 my-2" Style="vertical-align: bottom;"/> |
| 28 | + <MudImage Src="images/NavbarLogoSpin.svg" Alt="Logo" Height="45" Width="218" Class="mx-4 my-2" |
| 29 | + Style="vertical-align: bottom;"/> |
26 | 30 | </a> |
27 | 31 | </div> |
28 | 32 | <MudDivider Style="margin-bottom: 5px" DividerType="DividerType.Middle"/> |
29 | 33 | </div> |
30 | 34 |
|
31 | 35 |
|
32 | | - <MudNavMenu style="align-self: flex-start; overflow-y: auto" Class="flex-auto flex-grow-1" Margin="Margin.Dense" Color="Color.Primary" Bordered="true"> |
| 36 | + <MudNavMenu style="align-self: flex-start; overflow-y: auto" Class="flex-auto flex-grow-1" Margin="Margin.Dense" |
| 37 | + Color="Color.Primary" Bordered="true"> |
33 | 38 |
|
34 | 39 | <MudNavLink Icon="@Icons.Material.Filled.ViewModule" Href="/dash/modules">Manage Modules</MudNavLink> |
35 | | - |
| 40 | + |
36 | 41 | <MudDivider Style="margin-bottom: 5px; margin-top: 5px;" DividerType="DividerType.Middle"/> |
37 | | - |
| 42 | + |
38 | 43 | @foreach (var modules in ModuleManager.Modules) |
39 | 44 | { |
40 | 45 | <ModuleNavComponent LoadedModule="@modules.Value"></ModuleNavComponent> |
41 | 46 | } |
42 | 47 | </MudNavMenu> |
43 | 48 |
|
44 | 49 | <div class="flex-none" style="align-self: flex-end"> |
| 50 | + @if (AuthService.MissingPermissions) |
| 51 | + { |
| 52 | + <MudTooltip |
| 53 | + Arrow="true" Placement="Placement.Right"> |
| 54 | + <ChildContent> |
| 55 | + <div class="mb-2 pa-4 flex row gap-2"> |
| 56 | + <MudIcon Icon="@Icons.Material.Filled.Warning" Color="Color.Warning"/> |
| 57 | + <MudText Typo="Typo.body2" Class="mt-1">Permissions Required</MudText> |
| 58 | + </div> |
| 59 | + </ChildContent> |
| 60 | + <TooltipContent> |
| 61 | + <MudText Typo="Typo.body2">Addition API Token Permissions Required</MudText> |
| 62 | + <MudText Typo="Typo.caption">for one or more installed modules.</MudText> |
| 63 | + <br/> |
| 64 | + <br/> |
| 65 | + <br/> |
| 66 | + @foreach (var perm in PermissionInfos) |
| 67 | + { |
| 68 | + @if (perm.Missing) |
| 69 | + { |
| 70 | + <MudText Typo="Typo.subtitle2" Color="Color.Warning">@perm.Permission</MudText> |
| 71 | + } |
| 72 | + else |
| 73 | + { |
| 74 | + <MudText Typo="Typo.subtitle2">@perm.Permission</MudText> |
| 75 | + } |
| 76 | + } |
| 77 | + <br/> |
| 78 | + </TooltipContent> |
| 79 | + </MudTooltip> |
| 80 | + } |
| 81 | + |
45 | 82 | <MudDivider DividerType="DividerType.Middle"/> |
46 | 83 | <div Class="pa-4"> |
47 | | - |
48 | | - |
49 | 84 | <div class="d-flex gap-5" style="flex-wrap: wrap; margin-bottom: 10px;"> |
50 | 85 |
|
51 | 86 | <div style="display: flex; flex-direction: column" class="child-div-align-center flex-grow-1"> |
52 | 87 | <MudText Style="font-size: 10pt; text-align: center">SignalR</MudText> |
53 | 88 | <MudTooltip Arrow="true" Placement="Placement.Top" Text="@ApiHubClient.State.ToString()"> |
54 | | - <MudIcon Icon="@Icons.Material.Filled.Wifi" Color="@GetConnectionStateColor(ApiHubClient.State)" |
| 89 | + <MudIcon Icon="@Icons.Material.Filled.Wifi" |
| 90 | + Color="@GetConnectionStateColor(ApiHubClient.State)" |
55 | 91 | Class="d-block ma-auto"/> |
56 | 92 | </MudTooltip> |
57 | 93 | </div> |
|
64 | 100 | } |
65 | 101 | else |
66 | 102 | { |
67 | | - <div style="display: flex; flex-direction: column" class="child-div-align-center flex-grow-1"> |
| 103 | + <div style="display: flex; flex-direction: column" |
| 104 | + class="child-div-align-center flex-grow-1"> |
68 | 105 | <MudText Style="font-size: 10pt; text-align: center">@device.Name.Truncate(13)</MudText> |
69 | 106 | <MudTooltip Arrow="true" Placement="Placement.Top" Text="Offline"> |
70 | | - <MudIcon Icon="@Icons.Material.Filled.Wifi" Color="@Color.Dark"/> |
| 107 | + <MudIcon Icon="@Icons.Material.Filled.Wifi" Color="@Color.Dark" |
| 108 | + Class="d-block ma-auto"/> |
71 | 109 | </MudTooltip> |
72 | 110 | </div> |
73 | 111 | } |
|
83 | 121 |
|
84 | 122 | @code { |
85 | 123 | private IAsyncDisposable _statusSubscription = null!; |
| 124 | + private IAsyncDisposable _authStateSubscription = null!; |
86 | 125 |
|
87 | 126 | protected override async Task OnInitializedAsync() |
88 | 127 | { |
89 | 128 | _statusSubscription = await StatusHandler.OnWebsocketStatusChanged.SubscribeAsync(() => InvokeAsync(StateHasChanged)); |
| 129 | + _authStateSubscription = await AuthService.AuthState.ValueUpdated.SubscribeAsync(_ => InvokeAsync(StateHasChanged)); |
90 | 130 | } |
91 | | - |
| 131 | + |
| 132 | + private struct PermissionInfo |
| 133 | + { |
| 134 | + public string Permission { get; set; } |
| 135 | + public bool Missing { get; set; } |
| 136 | + } |
| 137 | + |
| 138 | + private IEnumerable<PermissionInfo> PermissionInfos => Constants.BasePermissions.Concat(ModuleManager.RequiredPermissions).Distinct() |
| 139 | + .Select(x => new PermissionInfo |
| 140 | + { |
| 141 | + Permission = PermissionTypeBindings.PermissionTypeToName[x].Name, |
| 142 | + Missing = !(AuthService.TokenSelf?.Permissions.Contains(x) ?? false) |
| 143 | + }); |
| 144 | + |
92 | 145 |
|
93 | 146 | private static Color GetConnectionStateColor(HubConnectionState state) => |
94 | 147 | state switch |
|
101 | 154 | }; |
102 | 155 |
|
103 | 156 | private bool _disposed = false; |
104 | | - |
| 157 | + |
105 | 158 | public async ValueTask DisposeAsync() |
106 | 159 | { |
107 | 160 | if (_disposed) return; |
108 | 161 | _disposed = true; |
109 | 162 | await _statusSubscription.DisposeAsync(); |
| 163 | + await _authStateSubscription.DisposeAsync(); |
110 | 164 | } |
111 | 165 |
|
112 | 166 | } |
|
0 commit comments