You've already forked onecmonitor
mirror of
https://github.com/akpaevj/onecmonitor.git
synced 2026-06-17 22:34:48 +02:00
116 lines
4.1 KiB
Plaintext
116 lines
4.1 KiB
Plaintext
@using System.Reflection
|
|
@using Microsoft.AspNetCore.Components.Authorization
|
|
@using Microsoft.AspNetCore.Identity
|
|
@using Microsoft.AspNetCore.SignalR.Client
|
|
@using MudBlazor.StaticInput
|
|
@using OneSwiss.Server.Models
|
|
@using OneSwiss.Server.Services
|
|
@inherits LayoutComponentBase
|
|
@inject ISnackbar SnackbarService
|
|
@inject IHttpContextAccessor ContextAccessor
|
|
@inject UpdatesChecker.State UpdatesCheckerState
|
|
@inject NavigationManager NavManager
|
|
@inject UserManager<ApplicationUser> UserManager
|
|
@inject IJSRuntime Js
|
|
|
|
<script>
|
|
window.blazorSetCookie = (name, value, days, secure) => {
|
|
const secureStr = secure ? ';secure' : '';
|
|
const expires = new Date();
|
|
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/${secureStr};samesite=strict`;
|
|
};
|
|
</script>
|
|
|
|
<MudThemeProvider @bind-IsDarkMode="@_isDarkMode" Theme="_theme"/>
|
|
<MudPopoverProvider/>
|
|
<MudDialogProvider/>
|
|
<MudSnackbarProvider/>
|
|
|
|
<MudLayout>
|
|
<MudAppBar Elevation="1">
|
|
<AuthorizeView>
|
|
<MudStaticNavDrawerToggle DrawerId="nav-drawer" Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit"
|
|
Edge="Edge.Start"/>
|
|
<AppLabel/>
|
|
</AuthorizeView>
|
|
<MudSpacer/>
|
|
<AuthorizeView>
|
|
@if (UpdatesCheckerState.UpdatesAvailable)
|
|
{
|
|
var text = UpdatesCheckerState?.ReleaseInfo?.Prerelease == true ? "Доступно обновление (pre)" : "Доступно обновление";
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Warning"
|
|
OnClick="GoToReleasePage">@text</MudButton>
|
|
}
|
|
<MudText Class="ms-3">@_user?.ToString()</MudText>
|
|
<MudSwitch
|
|
Color="Color.Primary"
|
|
@bind-Value="_isDarkMode"
|
|
@bind-Value:after="OnChangeTheme"
|
|
ThumbIcon="@(_isDarkMode ? Icons.Material.Outlined.LightMode : Icons.Material.Outlined.DarkMode)"/>
|
|
</AuthorizeView>
|
|
<MudText>@Assembly.GetExecutingAssembly().GetName().Version</MudText>
|
|
</MudAppBar>
|
|
<AuthorizeView>
|
|
<MudDrawer id="nav-drawer" @bind-Open="_drawerOpen" ClipMode="DrawerClipMode.Always" Elevation="2">
|
|
<NavMenu @ref="_navMenu"/>
|
|
</MudDrawer>
|
|
</AuthorizeView>
|
|
<CascadingValue Name="NavMenu" Value="_navMenu">
|
|
<MudMainContent Class="pt-16 pa-5">
|
|
@Body
|
|
</MudMainContent>
|
|
</CascadingValue>
|
|
</MudLayout>
|
|
|
|
<div id="blazor-error-ui" data-nosnippet>
|
|
An unhandled error has occurred.
|
|
<a href="." class="reload">Reload</a>
|
|
<span class="dismiss">🗙</span>
|
|
</div>
|
|
|
|
@code {
|
|
private HubConnection? _hubConnection;
|
|
bool _isDarkMode = true;
|
|
NavMenu? _navMenu;
|
|
bool _drawerOpen = true;
|
|
readonly MudTheme _theme = new();
|
|
private ApplicationUser? _user;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (ContextAccessor.HttpContext != null)
|
|
_user = await UserManager.GetUserAsync(ContextAccessor.HttpContext.User);
|
|
|
|
SnackbarService.Configuration.PositionClass = Defaults.Classes.Position.BottomEnd;
|
|
|
|
if (ContextAccessor.HttpContext?.Request.Cookies.TryGetValue("IsDarkMode", out var value) == true &&
|
|
bool.TryParse(value, out var isDarkMode))
|
|
_isDarkMode = isDarkMode;
|
|
|
|
_hubConnection = new HubConnectionBuilder()
|
|
.WithUrl(NavManager.ToAbsoluteUri("/updatesHub"))
|
|
.Build();
|
|
|
|
_hubConnection.On("UpdatesAvailable", async () => { await InvokeAsync(StateHasChanged); });
|
|
|
|
await _hubConnection.StartAsync();
|
|
}
|
|
|
|
private async Task SetIsDarkModeCookie()
|
|
{
|
|
await Js.InvokeVoidAsync("blazorSetCookie", "IsDarkMode", _isDarkMode, 7, false);
|
|
}
|
|
|
|
private async Task OnChangeTheme()
|
|
{
|
|
await SetIsDarkModeCookie();
|
|
}
|
|
|
|
private async Task GoToReleasePage()
|
|
{
|
|
if (UpdatesCheckerState.ReleaseInfo != null)
|
|
await Js.InvokeVoidAsync("open", UpdatesCheckerState.ReleaseInfo.HtmlUrl, "_blank");
|
|
}
|
|
|
|
} |