Files
DiunaBI/DiunaBI.UI.Shared/Pages/Layers/Index.razor.cs

115 lines
3.1 KiB
C#
Raw Normal View History

2025-11-06 10:20:00 +01:00
using DiunaBI.UI.Shared.Services;
using Microsoft.AspNetCore.Components;
2025-12-02 13:43:01 +01:00
using Microsoft.AspNetCore.Components.Web;
2025-11-06 10:20:00 +01:00
using DiunaBI.Application.DTOModels;
using DiunaBI.Application.DTOModels.Common;
using MudBlazor;
2025-12-02 13:43:01 +01:00
using Microsoft.JSInterop;
2025-11-06 10:20:00 +01:00
2025-12-05 09:51:04 +01:00
namespace DiunaBI.UI.Shared.Pages.Layers;
2025-11-06 10:20:00 +01:00
public partial class Index : ComponentBase, IDisposable
2025-11-06 10:20:00 +01:00
{
[Inject] private LayerService LayerService { get; set; } = default!;
[Inject] private EntityChangeHubService HubService { get; set; } = default!;
2025-11-06 10:20:00 +01:00
[Inject] private ISnackbar Snackbar { get; set; } = default!;
2025-11-20 21:03:19 +01:00
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
2025-12-02 13:23:03 +01:00
[Inject] private LayerFilterStateService FilterStateService { get; set; } = default!;
2025-12-02 13:43:01 +01:00
[Inject] private IJSRuntime JSRuntime { get; set; } = default!;
2025-11-06 10:20:00 +01:00
private PagedResult<LayerDto> layers = new();
private LayerFilterRequest filterRequest = new();
private bool isLoading = false;
2025-12-02 13:23:03 +01:00
2025-11-06 10:20:00 +01:00
protected override async Task OnInitializedAsync()
{
2025-12-02 13:23:03 +01:00
filterRequest = FilterStateService.FilterRequest;
2025-11-19 18:51:09 +01:00
await LoadLayers();
// Subscribe to SignalR entity changes
HubService.EntityChanged += OnEntityChanged;
}
private async void OnEntityChanged(string module, string id, string operation)
{
// Only react if it's a Layers change
if (module.Equals("Layers", StringComparison.OrdinalIgnoreCase))
{
await InvokeAsync(async () =>
{
await LoadLayers();
StateHasChanged();
});
}
2025-11-06 10:20:00 +01:00
}
2025-11-19 18:51:09 +01:00
private async Task LoadLayers()
2025-11-06 10:20:00 +01:00
{
isLoading = true;
try
{
2025-12-02 13:23:03 +01:00
FilterStateService.UpdateFilter(filterRequest);
2025-11-06 10:20:00 +01:00
layers = await LayerService.GetLayersAsync(filterRequest);
}
catch (Exception ex)
{
2025-11-19 18:51:09 +01:00
Console.WriteLine($"Loading layers failed: {ex.Message}");
2025-11-06 10:20:00 +01:00
}
finally
{
isLoading = false;
}
}
2025-11-19 18:51:09 +01:00
private async Task SearchLayers()
2025-11-06 10:20:00 +01:00
{
filterRequest.Page = 1;
2025-11-19 18:51:09 +01:00
await LoadLayers();
2025-11-06 10:20:00 +01:00
}
2025-12-05 09:51:04 +01:00
2025-11-06 10:20:00 +01:00
private async Task OnPageChanged(int page)
{
filterRequest.Page = page;
2025-11-19 18:51:09 +01:00
await LoadLayers();
2025-11-06 10:20:00 +01:00
}
private async Task ClearFilters()
{
filterRequest = new LayerFilterRequest();
2025-12-02 13:23:03 +01:00
FilterStateService.ClearFilter();
2025-11-20 21:03:19 +01:00
await LoadLayers();
}
2025-12-01 13:21:45 +01:00
private async Task OnTypeClear()
{
filterRequest.Type = null;
filterRequest.Page = 1;
await LoadLayers();
}
private async Task OnTypeChanged(LayerType? type)
{
filterRequest.Type = type;
filterRequest.Page = 1;
await LoadLayers();
}
2025-11-20 21:03:19 +01:00
private void OnRowClick(LayerDto layer)
{
NavigationManager.NavigateTo($"/layers/{layer.Id}");
2025-11-06 10:20:00 +01:00
}
2025-12-02 13:43:01 +01:00
private async Task OnRowRightClick(MouseEventArgs e, LayerDto layer)
{
var url = NavigationManager.ToAbsoluteUri($"/layers/{layer.Id}").ToString();
await JSRuntime.InvokeVoidAsync("open", url, "_blank");
}
public void Dispose()
{
HubService.EntityChanged -= OnEntityChanged;
}
2025-12-05 09:51:04 +01:00
}