@page "/customers" @rendermode InteractiveWebAssembly @using IntegryControlPanel.Client.Models @using Microsoft.AspNetCore.Authorization @using System.Net.Http.Json @attribute [Authorize] @inject HttpClient Http @inject ISnackbar Snackbar Gestione Clienti Gestione Clienti @if (isLoading) { Caricamento clienti... } else if (customers?.Any() == true) { @context.Item.DisplayName @context.Item.Name @* #@context.Item.Id - @context.Item.Slug *@ @context.Item.PartitaIva @* @(context.Item.Active == true ? "Attivo" : "Inattivo") *@ @(context.Item.Active == true ? "Attivo" : "Inattivo") @* *@ Dettagli } else { Nessun cliente trovato. } Dettagli Cliente: @selectedCustomer?.Name @if (selectedCustomer != null) { @if (isLoadingServers) { Caricamento server... } else if (customerServers?.Any() == true) { } else { Nessun server configurato per questo cliente. } @if (isLoadingDevices) { Caricamento dispositivi... } else if (customerDevices?.Any() == true) { } else { Nessun dispositivo configurato per questo cliente. } @if (selectedCustomer.ApplicationInfos?.Any() == true) { @(context.Item.NewUpdProgMaga ? "Sì" : "No") } else { Nessuna applicazione configurata per questo cliente. } @if (selectedCustomer.PvmsInfos?.Any() == true) { @foreach (var pvms in selectedCustomer.PvmsInfos) { } } else { Nessuna informazione PVMS disponibile per questo cliente. } } Chiudi @code { private List? customers; private long? selectedCustomerId; private Customer? selectedCustomer; private List? customerServers; private List? customerDevices; private bool isLoading = true; private bool isLoadingServers = false; private bool isLoadingDevices = false; private bool isDetailsDialogVisible = false; private DialogOptions dialogOptions = new() { MaxWidth = MaxWidth.ExtraLarge, FullWidth = true, CloseButton = true }; protected override async Task OnInitializedAsync() { try { await LoadCustomers(); } catch (Exception ex) { Console.WriteLine($"❌ Customers page - OnInitializedAsync error: {ex.Message}"); Console.WriteLine($"📋 Stack trace: {ex.StackTrace}"); Snackbar.Add($"Errore nell'inizializzazione della pagina: {ex.Message}", Severity.Error); } } private async Task LoadCustomers() { try { isLoading = true; StateHasChanged(); // Force UI update customers = await Http.GetFromJsonAsync>("api/CustomerAnagInfo/"); } catch (HttpRequestException httpEx) { Console.WriteLine($"🌐 LoadCustomers - HTTP error: {httpEx.Message}"); Snackbar.Add($"Errore di connessione: {httpEx.Message}", Severity.Error); } catch (Exception ex) { Console.WriteLine($"❌ LoadCustomers - Generic error: {ex.Message}"); Console.WriteLine($"📋 Stack trace: {ex.StackTrace}"); Snackbar.Add($"Errore nel caricamento dei clienti: {ex.Message}", Severity.Error); } finally { isLoading = false; StateHasChanged(); // Force UI update } } private async Task ShowCustomerDetails(CustomerWithAnagInfoDto customer) { selectedCustomerId = customer.Id; isDetailsDialogVisible = true; // Load complete customer details with all related data try { selectedCustomer = await Http.GetFromJsonAsync($"api/IntegryData/customers/{customer.Id}"); } catch (Exception ex) { Snackbar.Add($"Errore nel caricamento dei dettagli del cliente: {ex.Message}", Severity.Error); } // Load related data await LoadCustomerServers(customer.Id); await LoadCustomerDevices(customer.Id); } private async Task LoadCustomerServers(int customerId) { try { isLoadingServers = true; customerServers = await Http.GetFromJsonAsync>($"api/IntegryData/customers/{customerId}/servers"); } catch (Exception ex) { Snackbar.Add($"Errore nel caricamento dei server: {ex.Message}", Severity.Error); } finally { isLoadingServers = false; } } private async Task LoadCustomerDevices(int customerId) { try { isLoadingDevices = true; customerDevices = await Http.GetFromJsonAsync>($"api/IntegryData/customers/{customerId}/devices"); } finally { isLoadingDevices = false; } } private void CloseDetailsDialog() { isDetailsDialogVisible = false; selectedCustomerId = null; customerServers = null; customerDevices = null; } }