@using CommunityToolkit.Mvvm.Messaging @using SteUp.Shared.Components.Layout.Sheet @using SteUp.Shared.Components.SingleElements.MessageBox @using SteUp.Shared.Core.Enum @using SteUp.Shared.Core.Interface.LocalDb @using SteUp.Shared.Core.Messages.Ispezione @using SteUp.Shared.Core.Messages.Scheda @inject INetworkService NetworkService @inject IDialogService Dialog @inject IMessenger Messenger @inject IIspezioniService IspezioniService @inject IJSRuntime Js @implements IDisposable @* Navigazione flottante in basso (STILE_UI ยง6.15): il contenuto le scorre sotto, le destinazioni restano a portata di pollice. Icona outline a riposo, piena da selezionata, etichetta sempre visibile in entrambe. Da 720px diventa una colonna laterale (vedi components.css). *@
@if (OnInspectionPage) { @if (!_isCompleted) { } @if (ShowCompleteInspection) { } } else { } @if (!NetworkService.IsNetworkAvailable()) { }
@code { private bool IsVisible { get; set; } = true; private bool ActionsVisible { get; set; } = true; private bool OnInspectionPage { get; set; } private bool ShowCompleteInspection { get; set; } private bool _isCompleted; private bool _sheetOpen; private ConfirmMessageBox _messageBox = null!; private static readonly string[] NavigableRoutes = ["ispezioni", "ispezione", "user"]; private string SheetTitle => OnInspectionPage ? "Azioni ispezione" : "Nuova ispezione"; private string? SheetSubtitle => OnInspectionPage ? SteupDataService.InspectionPageState.Ispezione.CodMdep : null; private string CurrentRoute => NavigationManager.Uri.Remove(0, NavigationManager.BaseUri.Length).Split('?')[0]; private bool IsOn(string route) => CurrentRoute.EqualsIgnoreCase(route); protected override Task OnInitializedAsync() { NavigationManager.LocationChanged += OnLocationChanged; Refresh(); return Task.CompletedTask; } private void OnLocationChanged(object? sender, LocationChangedEventArgs args) { // Cambiando schermata un menu aperto non ha piu' senso. _sheetOpen = false; Refresh(); } private void Refresh() { var route = CurrentRoute; IsVisible = NavigableRoutes.Contains(route, StringComparer.OrdinalIgnoreCase); OnInspectionPage = route.EqualsIgnoreCase("ispezione"); ActionsVisible = IsVisible && !route.EqualsIgnoreCase("user"); if (OnInspectionPage) { var ispezione = SteupDataService.InspectionPageState.Ispezione; _isCompleted = ispezione.Stato == StatusEnum.Completata; // "Concludi" non ha senso su un'ispezione mai inviata o gia' conclusa. ShowCompleteInspection = !ispezione.ActivityId.IsNullOrEmpty() && !_isCompleted; // Su un'ispezione conclusa resta solo la consultazione. if (_isCompleted) ActionsVisible = false; } StateHasChanged(); } private void OpenActions() { Refresh(); _sheetOpen = true; } private async Task NewInspection() { _sheetOpen = false; if (await SteupDataService.CanOpenNewInspection()) { _ = Dialog.OpenSelectShop(); } else { await Dialog.ShowWarning( "Per aprire una nuova ispezione devi prima concludere tutte le ispezioni aperte da piu' di 20 giorni."); } } private async Task CompleteInspection() { _sheetOpen = false; var result = await _messageBox.ShowAsync(); if (result is true) Messenger.Send(new CompleteInspectionMessage()); } private async Task NewScheda() { _sheetOpen = false; var ispezione = SteupDataService.InspectionPageState.Ispezione; var modal = await Dialog.OpenFormScheda(ispezione.CodMdep, ispezione.Data, true); if (modal is { Canceled: false }) Messenger.Send(new NewSchedaMessage()); } private async Task DeleteInspection() { _sheetOpen = false; try { var ispezione = SteupDataService.InspectionPageState.Ispezione; await IspezioniService.DeleteIspezioneAsync(ispezione.CodMdep, ispezione.Data, ispezione.Rilevatore); await Js.InvokeVoidAsync("goBack"); } catch (Exception e) { await Dialog.ShowError(e.Message); } } public void Dispose() => NavigationManager.LocationChanged -= OnLocationChanged; }