This commit is contained in:
104
BimAI.UI.Shared/Components/ProductListComponent.razor.cs
Normal file
104
BimAI.UI.Shared/Components/ProductListComponent.razor.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using BimAI.UI.Shared.Interfaces;
|
||||
using BimAI.UI.Shared.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using BimAI.Application.DTOModels;
|
||||
using BimAI.Application.DTOModels.Common;
|
||||
using MudBlazor;
|
||||
|
||||
namespace BimAI.UI.Shared.Components;
|
||||
|
||||
public partial class ProductListComponent : ComponentBase
|
||||
{
|
||||
[Inject] private ProductService ProductService { get; set; } = default!;
|
||||
[Inject] private IScannerService ScannerService { get; set; } = default!;
|
||||
[Inject] private ISnackbar Snackbar { get; set; } = default!;
|
||||
|
||||
|
||||
private PagedResult<ProductDto> products = new();
|
||||
private ProductFilterRequest filterRequest = new();
|
||||
private bool isLoading = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadProducts();
|
||||
}
|
||||
|
||||
private async Task LoadProducts()
|
||||
{
|
||||
isLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
products = await ProductService.GetProductsAsync(filterRequest);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Loading products failed: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SearchProducts()
|
||||
{
|
||||
filterRequest.Page = 1;
|
||||
await LoadProducts();
|
||||
}
|
||||
|
||||
private async Task OnPageChanged(int page)
|
||||
{
|
||||
filterRequest.Page = page;
|
||||
await LoadProducts();
|
||||
}
|
||||
|
||||
private async Task ClearFilters()
|
||||
{
|
||||
filterRequest = new ProductFilterRequest();
|
||||
await LoadProducts();
|
||||
}
|
||||
|
||||
private async Task EditProduct(Guid productId)
|
||||
{
|
||||
// TODO
|
||||
Console.WriteLine($"Edytuj produkt: {productId}");
|
||||
}
|
||||
|
||||
private async Task DeleteProduct(Guid productId)
|
||||
{
|
||||
// TODO
|
||||
Console.WriteLine($"Usuń produkt: {productId}");
|
||||
}
|
||||
|
||||
private string GetScannerIcon()
|
||||
{
|
||||
return ScannerService.IsAvailable ? Icons.Material.Filled.CameraAlt : "";
|
||||
}
|
||||
|
||||
private async Task OnScannerClick()
|
||||
{
|
||||
if (!ScannerService.IsAvailable)
|
||||
{
|
||||
Snackbar.Add("Skaner nie jest dostępny na tej platformie", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var scannedCode = await ScannerService.ScanBarcodeAsync();
|
||||
if (!string.IsNullOrEmpty(scannedCode))
|
||||
{
|
||||
filterRequest.Ean = scannedCode;
|
||||
await SearchProducts();
|
||||
Snackbar.Add($"Zeskanowano kod: {scannedCode}", Severity.Success);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Scanner error: {ex.Message}");
|
||||
Snackbar.Add("Błąd podczas skanowania", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user