PCRB webassembly
This commit is contained in:
@ -1,8 +1,14 @@
|
||||
@inherits LayoutComponentBase
|
||||
@using System.Text.Json
|
||||
@using System.Text
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@inject MesaFabApprovalAuthStateProvider authStateProvider
|
||||
@inject IAuthenticationService authenticationService
|
||||
@inject IConfiguration Configuration
|
||||
@inject IMemoryCache cache
|
||||
@inject IJSRuntime jsRuntime
|
||||
@inject IHttpClientFactory httpClientFactory
|
||||
@inject ISnackbar snackbar
|
||||
@inject NavigationManager navManager
|
||||
|
||||
<MudThemeProvider />
|
||||
@ -28,19 +34,22 @@
|
||||
<MudDrawer @bind-Open="_drawerOpen" ClipMode="DrawerClipMode.Always" Elevation="2">
|
||||
<MudNavMenu Color="Color.Info" Bordered="true" Class="d-flex flex-column justify-center p-1 gap-1">
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Tertiary"
|
||||
Href="@Configuration["OldFabApprovalUrl"]"
|
||||
Target="_blank"
|
||||
StartIcon="@Icons.Material.Filled.Home">
|
||||
Color="Color.Tertiary"
|
||||
Href="@Configuration["OldFabApprovalUrl"]"
|
||||
Target="_blank"
|
||||
StartIcon="@Icons.Material.Filled.Home">
|
||||
Return to Main Site
|
||||
</MudButton>
|
||||
|
||||
<MudDivider Class="my-1" />
|
||||
@if (authStateProvider.CurrentUser is not null) {
|
||||
<MudNavGroup Title="Create New">
|
||||
<MudNavLink OnClick="@(() => GoTo("mrb/new"))">Create New MRB</MudNavLink>
|
||||
<MudNavLink OnClick="@(() => GoTo("pcrb/new"))">Create New PCRB</MudNavLink>
|
||||
</MudNavGroup>
|
||||
<MudNavLink OnClick="@(() => GoTo(""))" Icon="@Icons.Material.Filled.Dashboard">Dashboard</MudNavLink>
|
||||
<MudNavLink OnClick="@(() => GoTo("mrb/all"))" Icon="@Icons.Material.Filled.Ballot">MRB List</MudNavLink>
|
||||
<MudNavLink OnClick="@(() => GoTo("pcrb/all"))" Icon="@Icons.Material.Filled.Ballot">PCRB List</MudNavLink>
|
||||
}
|
||||
</MudNavMenu>
|
||||
</MudDrawer>
|
||||
@ -68,4 +77,48 @@
|
||||
cache.Set("redirectUrl", page);
|
||||
navManager.NavigateTo(page);
|
||||
}
|
||||
|
||||
private async Task GoToExternal(string url, string content) {
|
||||
IJSObjectReference windowModule = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./js/OpenInNewWindow.js");
|
||||
await windowModule.InvokeAsync<object>("OpenInNewWindow", url, content);
|
||||
}
|
||||
|
||||
private async Task GoToOldSite() {
|
||||
try {
|
||||
User? currentUser = authStateProvider.CurrentUser;
|
||||
|
||||
AuthTokens? authTokens = await authenticationService.GetAuthTokens();
|
||||
|
||||
if (currentUser is null || authTokens is null) {
|
||||
await authStateProvider.Logout();
|
||||
navManager.NavigateTo("login");
|
||||
return;
|
||||
}
|
||||
|
||||
AuthAttempt authAttempt = new() {
|
||||
LoginID = currentUser.LoginID,
|
||||
AuthTokens = authTokens
|
||||
};
|
||||
|
||||
HttpClient httpClient = httpClientFactory.CreateClient("OldSite");
|
||||
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "Account/ExternalAuthSetup");
|
||||
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(authAttempt),
|
||||
Encoding.UTF8,
|
||||
"application/json");
|
||||
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(request);
|
||||
|
||||
if (httpResponseMessage.IsSuccessStatusCode) {
|
||||
snackbar.Add("Old site auth setup successful", Severity.Success);
|
||||
} else {
|
||||
snackbar.Add($"Old site auth setup failed, because {httpResponseMessage.ReasonPhrase}", Severity.Error);
|
||||
}
|
||||
|
||||
await GoToExternal($"{Configuration["OldFabApprovalUrl"]}", "");
|
||||
} catch (Exception ex) {
|
||||
snackbar.Add($"Unable to go to old site, because {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user