@using CommunityToolkit.Mvvm.Messaging @using SteUp.Shared.Components.SingleElements.MessageBox @using SteUp.Shared.Core.Messages.Ispezione @using SteUp.Shared.Core.Messages.Scheda @inject INetworkService NetworkService @inject IDialogService Dialog @inject IMessenger Messenger
@code { private bool IsVisible { get; set; } = true; private bool PlusVisible { get; set; } = true; private bool ShowCompleteInspection { get; set; } private bool SchedaVisible { get; set; } private ConfirmMessageBox _messageBox = null!; protected override Task OnInitializedAsync() { NavigationManager.LocationChanged += (_, args) => { var location = args.Location.Remove(0, NavigationManager.BaseUri.Length); var newIsVisible = new List { "ispezioni", "ispezione", "user" } .Contains(location); var newPlusVisible = new List { "ispezioni", "ispezione", "user" } .Contains(location); if (IsVisible == newIsVisible && PlusVisible == newPlusVisible) return; IsVisible = newIsVisible; PlusVisible = newPlusVisible; StateHasChanged(); }; return Task.CompletedTask; } private async Task NewInspection() { if (await SteupDataService.CanOpenNewInspection()) { _ = Dialog.OpenSelectShop(); } else { await Dialog.ShowWarning("Per aprire una nuova ispezione è necessario concludere prima tutte le ispezioni aperte più vecchie di 20 giorni!"); } } private async Task CompleteInspection() { var result = await _messageBox.ShowAsync(); if (result is true) Messenger.Send(new CompleteInspectionMessage()); } private async Task NewScheda() { 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 void OnOpenMenu() { var location = NavigationManager.Uri.Remove(0, NavigationManager.BaseUri.Length); SchedaVisible = new List { "ispezione" }.Contains(location); ShowCompleteInspection = !SteupDataService.InspectionPageState.Ispezione.ActivityId.IsNullOrEmpty(); StateHasChanged(); } }