DataInbox list

This commit is contained in:
2025-12-01 12:55:47 +01:00
parent a71b6feefc
commit 3d654d972e
9 changed files with 292 additions and 15 deletions

View File

@@ -0,0 +1,75 @@
@using MudBlazor.Internal
<MudExpansionPanels Class="mb-4">
<MudExpansionPanel Icon="@Icons.Material.Filled.FilterList"
Text="Filters"
Expanded="true">
<MudGrid>
<MudItem xs="12" sm="6" md="4">
<MudTextField @bind-Value="filterRequest.Search"
Label="Search"
Placeholder="Name, source..."
Immediate="true"
DebounceInterval="500"
OnDebounceIntervalElapsed="SearchDataInbox"
Clearable="true"/>
</MudItem>
<MudItem xs="12" sm="6" md="4">
<MudButton Variant="Variant.Outlined"
OnClick="ClearFilters"
StartIcon="Icons.Material.Filled.Clear">
Clear filters
</MudButton>
</MudItem>
</MudGrid>
</MudExpansionPanel>
</MudExpansionPanels>
<MudDivider Class="my-4"></MudDivider>
<MudTable Items="dataInbox.Items"
Dense="true"
Hover="true"
Loading="isLoading"
LoadingProgressColor="Color.Info"
T="DataInboxDto"
Style="cursor: pointer;">
<HeaderContent>
<MudTh>Name</MudTh>
<MudTh>Source</MudTh>
<MudTh>Created At</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="Source">@context.Source</MudTd>
<MudTd DataLabel="Created At">@context.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss")</MudTd>
</RowTemplate>
<NoRecordsContent>
<MudText>No data inbox items to display</MudText>
</NoRecordsContent>
<LoadingContent>
Loading...
</LoadingContent>
</MudTable>
@if (dataInbox.TotalCount > 0)
{
<MudGrid Class="mt-4" AlignItems="Center.Center">
<MudItem xs="12" sm="6">
<MudText Typo="Typo.body2">
Results @((dataInbox.Page - 1) * dataInbox.PageSize + 1) - @Math.Min(dataInbox.Page * dataInbox.PageSize, dataInbox.TotalCount)
of @dataInbox.TotalCount
</MudText>
</MudItem>
<MudItem xs="12" sm="6" Class="d-flex justify-end">
<MudPagination Count="dataInbox.TotalPages"
Selected="dataInbox.Page"
SelectedChanged="OnPageChanged"
ShowFirstButton="true"
ShowLastButton="true"
Variant="Variant.Outlined"
/>
</MudItem>
</MudGrid>
}

View File

@@ -0,0 +1,60 @@
using DiunaBI.UI.Shared.Services;
using Microsoft.AspNetCore.Components;
using DiunaBI.Application.DTOModels;
using DiunaBI.Application.DTOModels.Common;
using MudBlazor;
namespace DiunaBI.UI.Shared.Components;
public partial class DataInboxListComponent : ComponentBase
{
[Inject] private DataInboxService DataInboxService { get; set; } = default!;
[Inject] private ISnackbar Snackbar { get; set; } = default!;
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
private PagedResult<DataInboxDto> dataInbox = new();
private DataInboxFilterRequest filterRequest = new();
private bool isLoading = false;
protected override async Task OnInitializedAsync()
{
await LoadDataInbox();
}
private async Task LoadDataInbox()
{
isLoading = true;
try
{
dataInbox = await DataInboxService.GetDataInboxAsync(filterRequest);
}
catch (Exception ex)
{
Console.WriteLine($"Loading data inbox failed: {ex.Message}");
}
finally
{
isLoading = false;
}
}
private async Task SearchDataInbox()
{
filterRequest.Page = 1;
await LoadDataInbox();
}
private async Task OnPageChanged(int page)
{
filterRequest.Page = page;
await LoadDataInbox();
}
private async Task ClearFilters()
{
filterRequest = new DataInboxFilterRequest();
await LoadDataInbox();
}
}

View File

@@ -1,10 +0,0 @@
@using Microsoft.AspNetCore.Components.Routing
@using MudBlazor
<MudNavMenu>
<MudNavLink href="dashboard" Icon="@Icons.Material.Filled.Dashboard" Match="NavLinkMatch.All">
Dashboard
</MudNavLink>
<MudNavLink Href="layers" Icon="@Icons.Material.Filled.List" Match="NavLinkMatch.All">
Layers
</MudNavLink>
</MudNavMenu>

View File

@@ -36,6 +36,7 @@ public static class ServiceCollectionExtensions
// Services
services.AddScoped<AuthService>();
services.AddScoped<LayerService>();
services.AddScoped<DataInboxService>();
return services;
}

View File

@@ -35,6 +35,7 @@
<MudNavMenu>
<MudNavLink Href="/dashboard" Icon="@Icons.Material.Filled.Dashboard">Dashboard</MudNavLink>
<MudNavLink Href="/layers" Icon="@Icons.Material.Filled.Inventory">Layers</MudNavLink>
<MudNavLink Href="/datainbox" Icon="@Icons.Material.Filled.Inbox">Data Inbox</MudNavLink>
</MudNavMenu>
</MudDrawer>

View File

@@ -0,0 +1,8 @@
@page "/datainbox"
@using DiunaBI.UI.Shared.Components
<PageTitle>Data Inbox</PageTitle>
<MudContainer MaxWidth="MaxWidth.ExtraExtraLarge">
<DataInboxListComponent />
</MudContainer>

View File

@@ -0,0 +1,49 @@
using System.Net.Http.Json;
using System.Text.Json;
using DiunaBI.Application.DTOModels;
using DiunaBI.Application.DTOModels.Common;
namespace DiunaBI.UI.Shared.Services;
public class DataInboxService
{
private readonly HttpClient _httpClient;
public DataInboxService(HttpClient httpClient)
{
_httpClient = httpClient;
}
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
public async Task<PagedResult<DataInboxDto>> GetDataInboxAsync(DataInboxFilterRequest filterRequest)
{
// Calculate start index from page number (page 1 = start 0, page 2 = start 50, etc.)
var start = (filterRequest.Page - 1) * filterRequest.PageSize;
var query = $"DataInbox/GetAll?start={start}&limit={filterRequest.PageSize}";
if (!string.IsNullOrEmpty(filterRequest.Search))
query += $"&name={Uri.EscapeDataString(filterRequest.Search)}";
var response = await _httpClient.GetAsync(query);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<PagedResult<DataInboxDto>>(json, _jsonOptions);
return result ?? new PagedResult<DataInboxDto>();
}
public async Task<DataInboxDto?> GetDataInboxByIdAsync(Guid id)
{
var response = await _httpClient.GetAsync($"DataInbox/{id}");
if (!response.IsSuccessStatusCode)
return null;
return await response.Content.ReadFromJsonAsync<DataInboxDto>();
}
}