1
0
mirror of https://github.com/akpaevj/onecmonitor.git synced 2026-06-17 22:34:48 +02:00
Files

128 lines
5.6 KiB
Plaintext

@inject IDbContextFactory<AppDbContext> ContextFactory
@inject NavigationManager NavigationManager
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.EntityFrameworkCore
@using MudBlazor.Utilities
@using OneSwiss.Server.Extensions
@implements IDisposable
<MudNavMenu>
<AuthorizeView>
<Authorized>
<MudNavLink Href="" Class="mt-1 mb-1" Icon="@Icons.Material.Filled.Dashboard" IconColor="Color.Secondary"
Match="NavLinkMatch.All">Панель
</MudNavLink>
@if (context.IsInRoles(Roles.ReadMaintenanceTasks, Roles.WriteMaintenanceTasks))
{
<MudNavGroup Class="mb-1" Title="Обслуживание" Expanded="true"
Icon="@Icons.Material.Filled.HomeRepairService" IconColor="Color.Primary">
<MudNavLink Href="configurationrepositories">Хранилища конфигураций</MudNavLink>
<MudNavLink Href="files">Конфигурации обработки и скрипты</MudNavLink>
<MudNavLink Href="maintenancetasks">Задачи обслуживания</MudNavLink>
<MudNavLink Href="maintenancetaskstemplates">Шаблоны задач обслуживания</MudNavLink>
</MudNavGroup>
}
@if (context.IsInRoles(Roles.ReadTechLogSeances, Roles.WriteTechLogSeances))
{
<MudNavGroup hidden="@_techLogDisabled" Class="mb-1" Title="Технологический журнал"
Icon="@Icons.Material.Filled.Task" IconColor="Color.Warning">
<MudNavLink Href="techlog/seances">Сеансы сбора</MudNavLink>
<MudNavLink Href="techlog/templates">Шаблоны</MudNavLink>
</MudNavGroup>
}
@if (context.IsInRoles(Roles.ReadErrorLoggingReports))
{
<MudNavLink hidden="@_errorLoggingServiceDisabled" Class="mb-1" Href="errorLoggingService"
Icon="@Icons.Material.Filled.BugReport" IconColor="Color.Error">
Сервис регистрации ошибок
</MudNavLink>
}
@if (context.IsInRoles(Roles.ReadEventLog))
{
<MudNavLink hidden="@_eventLogExportDisabled" Class="mb-1" Href="eventlog"
Icon="@Icons.Material.Filled.TextFields" IconColor="Color.Primary">
Журнал регистрации
</MudNavLink>
}
@if (context.IsInRoles(Roles.ReadGitRepositories, Roles.WriteGitRepositories))
{
<MudNavLink Class="mb-1" Href="gitrepositories" Icon="@Icons.Custom.Brands.GitHub"
IconColor="Color.Info">
Репозитории Git
</MudNavLink>
}
@if (context.IsAdmin())
{
<MudNavGroup Title="Общее" Expanded="true" Icon="@Icons.Material.Filled.Settings"
IconColor="Color.Tertiary">
<MudNavLink Href="settings">Настройки</MudNavLink>
<MudNavLink Href="credentials">Учетные данные и токены</MudNavLink>
<MudNavLink Href="dbms">СУБД</MudNavLink>
</MudNavGroup>
}
<form action="Account/Logout" method="post">
<AntiforgeryToken/>
<input type="hidden" name="ReturnUrl" value="@currentUrl"/>
<button type="submit" class="mud-nav-link mud-ripple">
<MudIcon Icon="@Icons.Material.Filled.Logout" Color="Color.Info" Class="mr-3"></MudIcon>
Выход
</button>
</form>
</Authorized>
<NotAuthorized>
<MudNavLink Href="Account/Register" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Person">
Регистрация
</MudNavLink>
<MudNavLink Href="Account/Login" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Login">Вход
</MudNavLink>
</NotAuthorized>
</AuthorizeView>
</MudNavMenu>
@code {
private string? currentUrl;
private bool _techLogDisabled = true;
private bool _errorLoggingServiceDisabled = true;
private bool _eventLogExportDisabled = true;
protected override async Task OnInitializedAsync()
{
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.LocationChanged += OnLocationChanged;
await UpdateVisibility();
}
private async Task UpdateVisibility()
{
await using var context = await ContextFactory.CreateDbContextAsync();
var elss = await context.ErrorLoggingServiceSettings.SingleOrDefaultAsync();
_errorLoggingServiceDisabled = !elss?.Enabled ?? true;
var tls = await context.TechLogSettings.SingleOrDefaultAsync();
_techLogDisabled = !tls?.Enabled ?? true;
var el = await context.EventLogSettings.SingleOrDefaultAsync();
_eventLogExportDisabled = !el?.Enabled ?? true;
}
public async Task NotifyStateHasChanged()
{
await UpdateVisibility();
await InvokeAsync(StateHasChanged);
}
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
StateHasChanged();
}
public void Dispose()
{
NavigationManager.LocationChanged -= OnLocationChanged;
}
}