web UI
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
@inherits LayoutComponentBase
|
||||
@using MudBlazor
|
||||
@using VisionBuilder.UI.Common.ViewModel
|
||||
@using VisionBuilder.UI.Common.Services
|
||||
@using VisionBuilder.UI.Common
|
||||
@inject MainWindowVM MainWindowVm
|
||||
@inject IPasswordInputService PasswordInputService
|
||||
@implements IDisposable
|
||||
|
||||
<MudThemeProvider Theme="@_currentTheme" />
|
||||
<MudPopoverProvider />
|
||||
<MudDialogProvider />
|
||||
<MudSnackbarProvider />
|
||||
|
||||
<div class="app-root @(_testMode ? "test-mode" : "")">
|
||||
<div class="app-content">
|
||||
@Body
|
||||
</div>
|
||||
<div class="app-divider"></div>
|
||||
<div class="app-toolbar">
|
||||
<div class="toolbar-buttons">
|
||||
@if (_showTestModeButton)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" Class="toolbar-btn" OnClick="ToggleTestMode">Test Mode</MudButton>
|
||||
}
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" Class="toolbar-btn" OnClick="OnSettings">Settings</MudButton>
|
||||
</div>
|
||||
<span class="toolbar-version">@_version</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,103 @@
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using VisionBuilder.UI.Blazor.Services;
|
||||
using VisionBuilder.UI.Common;
|
||||
using VisionBuilder.UI.Common.Services;
|
||||
using VisionBuilder.UI.Common.ViewModel;
|
||||
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;
|
||||
using Ninject;
|
||||
|
||||
namespace VisionBuilder.UI.Blazor.Uno.Components.Layout;
|
||||
|
||||
public partial class MainLayout : IDisposable
|
||||
{
|
||||
[Microsoft.AspNetCore.Components.Inject] private IDialogService DialogService { get; set; } = null!;
|
||||
[Microsoft.AspNetCore.Components.Inject] private IKernel Kernel { get; set; } = null!;
|
||||
|
||||
private bool _testMode;
|
||||
private bool _showTestModeButton;
|
||||
private string _version = "";
|
||||
|
||||
private readonly MudTheme _inspectronTheme = new()
|
||||
{
|
||||
PaletteLight = new PaletteLight
|
||||
{
|
||||
Primary = "#d32f2f",
|
||||
AppbarBackground = "#37474f"
|
||||
},
|
||||
LayoutProperties = new LayoutProperties
|
||||
{
|
||||
DefaultBorderRadius = "0px"
|
||||
}
|
||||
};
|
||||
|
||||
private readonly MudTheme _testModeTheme = new()
|
||||
{
|
||||
PaletteLight = new PaletteLight
|
||||
{
|
||||
Primary = "#2e7d32",
|
||||
AppbarBackground = "#2e7d32"
|
||||
},
|
||||
LayoutProperties = new LayoutProperties
|
||||
{
|
||||
DefaultBorderRadius = "0px"
|
||||
}
|
||||
};
|
||||
|
||||
private MudTheme _currentTheme = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_currentTheme = _inspectronTheme;
|
||||
_version = $"v{Assembly.GetEntryAssembly()?.GetName().Version?.ToString(3) ?? "0.0.0"}";
|
||||
|
||||
var uiConfig = Kernel.Get<UIConfiguration>();
|
||||
_showTestModeButton = uiConfig.ShowTestModeButton;
|
||||
|
||||
MainWindowVm.PropertyChanged += OnPropertyChanged;
|
||||
|
||||
// Wire up dialog services
|
||||
if (Kernel.Get<IRecipeSelectionDialogService>() is BlazorRecipeSelectionDialogService recipeService)
|
||||
recipeService.SetDialogService(DialogService);
|
||||
if (Kernel.Get<IImagePreviewService>() is BlazorImagePreviewService imageService)
|
||||
imageService.SetDialogService(DialogService);
|
||||
if (Kernel.Get<IPasswordInputService>() is BlazorPasswordInputService passwordService)
|
||||
passwordService.SetDialogService(DialogService);
|
||||
if (Kernel.Get<ISettingsService>() is BlazorSettingsService settingsService)
|
||||
settingsService.SetDialogService(DialogService);
|
||||
}
|
||||
|
||||
private async void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(MainWindowVM.TestMode))
|
||||
{
|
||||
_testMode = MainWindowVm.TestMode;
|
||||
_currentTheme = _testMode ? _testModeTheme : _inspectronTheme;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleTestMode()
|
||||
{
|
||||
MainWindowVm.ToggleTestModeCommand.Execute(null);
|
||||
}
|
||||
|
||||
private async Task OnSettings()
|
||||
{
|
||||
var uiConfig = Kernel.Get<UIConfiguration>();
|
||||
if (uiConfig.ProtectSettingsWithPassword)
|
||||
{
|
||||
var password = await PasswordInputService.GetPasswordAsync();
|
||||
if (password != uiConfig.AdminPassword)
|
||||
return;
|
||||
}
|
||||
MainWindowVm.SettingsCommand.Execute(null);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
MainWindowVm.PropertyChanged -= OnPropertyChanged;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user