@using DevExpress.Blazor
@inject Microsoft.JSInterop.IJSRuntime JSRuntime
@if (_isFullscreen)
{
}
else
{
@RenderMainContent()
}
@code {
private IInfoPanelBase? _infoPanelInstance;
private IMgGridBase? _currentGrid;
private bool _isFullscreen;
private string _currentInfoPanelSize = "400px";
private bool _sizeLoaded;
///
/// The grid content to display in the left pane
///
[Parameter]
public RenderFragment? GridContent { get; set; }
///
/// InfoPanel content (e.g., GridShippingDocumentInfoPanel) to display in the right pane.
/// If not set, the default MgGridInfoPanel is used.
///
[Parameter]
public RenderFragment? ChildContent { get; set; }
///
/// Initial size of the InfoPanel pane. Default is "400px".
///
[Parameter]
public string InfoPanelSize { get; set; } = "400px";
///
/// Whether to show the InfoPanel. Default is true.
///
[Parameter]
public bool ShowInfoPanel { get; set; } = true;
///
/// Whether the wrapper is currently in fullscreen mode
///
public bool IsFullscreen => _isFullscreen;
///
/// Gets or sets the InfoPanel instance for grid-InfoPanel communication
///
public IInfoPanelBase? InfoPanelInstance
{
get => _infoPanelInstance;
set => _infoPanelInstance = value;
}
///
/// Registers an InfoPanel instance (called by child InfoPanel components)
///
public void RegisterInfoPanel(IInfoPanelBase infoPanel)
{
_infoPanelInstance = infoPanel;
}
///
/// Registers the grid instance (called by MgGridBase)
///
public void RegisterGrid(IMgGridBase grid)
{
_currentGrid = grid;
// Load saved size when grid is registered
if (!_sizeLoaded)
{
_ = LoadSavedSizeAsync();
}
}
///
/// Toggles fullscreen mode
///
public void ToggleFullscreen()
{
_isFullscreen = !_isFullscreen;
StateHasChanged();
}
///
/// Enters fullscreen mode
///
public void EnterFullscreen()
{
_isFullscreen = true;
StateHasChanged();
}
///
/// Exits fullscreen mode
///
public void ExitFullscreen()
{
_isFullscreen = false;
StateHasChanged();
}
private string GetStorageKey() => _currentGrid != null
? $"Splitter_{_currentGrid.AutomaticLayoutStorageKey}"
: null!;
private async Task LoadSavedSizeAsync()
{
if (_currentGrid == null) return;
try
{
var storageKey = GetStorageKey();
var savedSize = await JSRuntime.InvokeAsync("localStorage.getItem", storageKey);
if (!string.IsNullOrWhiteSpace(savedSize))
{
_currentInfoPanelSize = savedSize;
_sizeLoaded = true;
await InvokeAsync(StateHasChanged);
}
else
{
_currentInfoPanelSize = InfoPanelSize;
_sizeLoaded = true;
}
}
catch
{
// Mute exceptions for the server prerender stage
_currentInfoPanelSize = InfoPanelSize;
_sizeLoaded = true;
}
}
private async Task SaveSizeAsync(string size)
{
if (_currentGrid == null) return;
try
{
var storageKey = GetStorageKey();
await JSRuntime.InvokeVoidAsync("localStorage.setItem", storageKey, size);
}
catch
{
// Mute exceptions for the server prerender stage
}
}
private async Task OnInfoPanelSizeChanged(string newSize)
{
_currentInfoPanelSize = newSize;
await SaveSizeAsync(newSize);
}
protected override void OnParametersSet()
{
if (!_sizeLoaded)
{
_currentInfoPanelSize = InfoPanelSize;
}
base.OnParametersSet();
}
private RenderFragment RenderMainContent() => __builder =>
{
if (ShowInfoPanel)
{
@GridContent
@if (ChildContent != null)
{
@ChildContent
}
else
{
}
}
else
{
@GridContent
}
};
}