diff --git a/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs b/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs index 42f20f8..fc3b4f5 100644 --- a/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs +++ b/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore; using SteUp.Shared.Core.Entities; using SteUp.Shared.Core.Enum; using SteUp.Shared.Core.Helpers; @@ -17,6 +18,11 @@ public class IspezioniService(AppDbContext db) : IIspezioniService x.Data == data && x.Rilevatore == rilevatore); + public Task> GetAllIspezioni() => + db.Ispezioni + .AsNoTracking() + .ToListAsync(); + public Task> GetAllIspezioniWithSchedeAsync() => db.Ispezioni .Include(x => x.Schede) @@ -67,15 +73,16 @@ public class IspezioniService(AppDbContext db) : IIspezioniService await db.SaveChangesAsync(); return true; } - - public async Task UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore, StatusEnum stato) + + public async Task UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore, + StatusEnum stato) { var ispezione = await db.Ispezioni .FirstOrDefaultAsync(x => x.CodMdep == codMdep && x.Data == data && x.Rilevatore == rilevatore); - + if (ispezione is null) return false; @@ -93,7 +100,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService x.CodMdep == codMdep && x.Data == data && x.Rilevatore == rilevatore); - + if (ispezione is null) return false; diff --git a/SteUp.Shared/Components/Layout/NavMenu.razor b/SteUp.Shared/Components/Layout/NavMenu.razor index fd07947..12c4ce5 100644 --- a/SteUp.Shared/Components/Layout/NavMenu.razor +++ b/SteUp.Shared/Components/Layout/NavMenu.razor @@ -1,7 +1,4 @@ @using CommunityToolkit.Mvvm.Messaging -@using SteUp.Shared.Core.Entities -@using SteUp.Shared.Core.Interface.IntegryApi -@using SteUp.Shared.Core.Interface.System.Network @using SteUp.Shared.Core.Messages.Ispezione @using SteUp.Shared.Core.Messages.Scheda @inject INetworkService NetworkService @@ -40,18 +37,18 @@ Size="Size.Medium" IconSize="Size.Medium"> @if (SchedaVisible) { + + if (ShowCompleteInspection) { } - - } else { - } @@ -87,9 +84,16 @@ return Task.CompletedTask; } - private void NewActivity() + private async Task NewInspection() { - _ = ModalHelper.OpenSelectShop(Dialog); + 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 void CompleteInspection() => @@ -98,7 +102,7 @@ private async Task NewScheda() { var ispezione = SteupDataService.InspectionPageState.Ispezione; - var modal = await ModalHelper.OpenFormScheda(Dialog, ispezione.CodMdep, ispezione.Data, true); + var modal = await Dialog.OpenFormScheda(ispezione.CodMdep, ispezione.Data, true); if (modal is { Canceled: false }) Messenger.Send(new NewSchedaMessage()); diff --git a/SteUp.Shared/Components/Pages/IspezionePage.razor b/SteUp.Shared/Components/Pages/IspezionePage.razor index c8cc8f0..90457cd 100644 --- a/SteUp.Shared/Components/Pages/IspezionePage.razor +++ b/SteUp.Shared/Components/Pages/IspezionePage.razor @@ -133,7 +133,7 @@ catch (Exception e) { Console.WriteLine(e.Message); - + await InvokeAsync(() => { VisibleOverlay = false; @@ -173,8 +173,7 @@ private async Task CreateNewScheda(JtbFasiDto jtbFasi) { - var modal = await ModalHelper.OpenFormScheda( - Dialog, + var modal = await Dialog.OpenFormScheda( SteupDataService.InspectionPageState.Ispezione.CodMdep, SteupDataService.InspectionPageState.Ispezione.Data, true, @@ -244,7 +243,7 @@ { if (errorMessage == null) return; - _ = ModalHelper.ShowError(Dialog, errorMessage); + _ = Dialog.ShowError(errorMessage); } void IDisposable.Dispose() diff --git a/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor index 0efb813..f0739c5 100644 --- a/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor +++ b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor @@ -64,18 +64,27 @@ private async Task UpdateScheda() { - var modal = await ModalHelper.OpenFormScheda(Dialog, CodMdep, Data, false, Scheda); + var modal = await Dialog.OpenFormScheda(CodMdep, Data, false, Scheda); if (modal is { Canceled: false, Data: Scheda scheda }) await OnSchedaModified.InvokeAsync(scheda); } private async Task DeleteScheda() { var result = await _deleteMessageBox.ShowAsync(); - + if (result is true) { + VisibleOverlay = true; + StateHasChanged(); + + if (Scheda.ActivityId != null) + await IntegrySteupService.DeleteScheda(Scheda.ActivityId); + var deleteScheda = await IspezioniService.DeleteSchedaAsync(Scheda.Id); if (deleteScheda) await OnSchedaDeleted.InvokeAsync(Scheda); + + VisibleOverlay = false; + StateHasChanged(); } } diff --git a/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor b/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor index 94cd262..c6dffb3 100644 --- a/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor +++ b/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor @@ -1,9 +1,19 @@  -
- - Ops -
+ @if (IsWarning) + { +
+ + Attenzione +
+ } + else + { +
+ + Ops +
+ }
@ErrorMessage
@@ -18,6 +28,7 @@ @code { [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!; [Parameter] public string ErrorMessage { get; set; } = string.Empty; + [Parameter] public bool IsWarning { get; set; } private void Cancel() => MudDialog.Cancel(); } \ No newline at end of file diff --git a/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor.css b/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor.css index fcb2236..3b43398 100644 --- a/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor.css +++ b/SteUp.Shared/Components/SingleElements/Modal/ExceptionModal/ModalError.razor.css @@ -8,9 +8,16 @@ .exception-header > i { font-size: 3rem; line-height: normal; +} + +.error-icon { color: var(--bs-danger); } +.warning-icon { + color: var(--bs-warning); +} + .exception-header > span { font-size: x-large; font-weight: 700; diff --git a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor index 72d3643..c722eed 100644 --- a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor +++ b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor @@ -285,7 +285,7 @@ { Console.WriteLine(e.Message); - await ModalHelper.ShowError(Dialog, e.Message); + await Dialog.ShowError(e.Message); } if (IsNew) await NewSave(apiResponse); @@ -474,7 +474,7 @@ private async Task OpenAddAttached() { - var result = await ModalHelper.OpenAddAttached(Dialog); + var result = await Dialog.OpenAddAttached(); if (result is not { Canceled: false, Data: List attachedList }) return; OnLoading = true; @@ -561,7 +561,7 @@ return; } - var modal = await ModalHelper.OpenSelectArt(Dialog, articoli); + var modal = await Dialog.OpenSelectArt(articoli); await InvokeAsync(() => { @@ -614,7 +614,7 @@ { var activityDescriptions = await IntegryApiService.SuggestActivityDescription(Scheda.ActivityTypeId); - var modal = await ModalHelper.OpenSuggestActivityDescription(Dialog, activityDescriptions); + var modal = await Dialog.OpenSuggestActivityDescription(activityDescriptions); if (modal is { Canceled: false, Data: not null }) Scheda.Note = modal.Data!.ToString(); @@ -694,7 +694,7 @@ { if (errorMessage == null) return; - _ = ModalHelper.ShowError(Dialog, errorMessage); + _ = Dialog.ShowError(errorMessage); } private void RemoveArt(string barcode) diff --git a/SteUp.Shared/Core/Data/Contracts/ISteupDataService.cs b/SteUp.Shared/Core/Data/Contracts/ISteupDataService.cs index 749033d..45b668c 100644 --- a/SteUp.Shared/Core/Data/Contracts/ISteupDataService.cs +++ b/SteUp.Shared/Core/Data/Contracts/ISteupDataService.cs @@ -6,6 +6,7 @@ namespace SteUp.Shared.Core.Data.Contracts; public interface ISteupDataService { Task Init(); + Task CanOpenNewInspection(); void RegisterAppVersion(); List PuntiVenditaList { get; } diff --git a/SteUp.Shared/Core/Data/SteupDataService.cs b/SteUp.Shared/Core/Data/SteupDataService.cs index ade3df5..d2d60c3 100644 --- a/SteUp.Shared/Core/Data/SteupDataService.cs +++ b/SteUp.Shared/Core/Data/SteupDataService.cs @@ -3,11 +3,11 @@ using IntegryApiClient.Core.Domain.Abstraction.Contracts.Device; using SteUp.Shared.Core.Data.Contracts; using SteUp.Shared.Core.Dto; using SteUp.Shared.Core.Dto.PageState; +using SteUp.Shared.Core.Enum; using SteUp.Shared.Core.Helpers; using SteUp.Shared.Core.Interface.IntegryApi; using SteUp.Shared.Core.Interface.LocalDb; using SteUp.Shared.Core.Interface.System; -using SteUp.Shared.Core.Interface.System.Network; namespace SteUp.Shared.Core.Data; @@ -76,6 +76,20 @@ public class SteupDataService( } } + public async Task CanOpenNewInspection() + { + var completedInspection = await ispezioniService.GetAllIspezioni(); + + if (completedInspection.IsNullOrEmpty()) return true; + + //Controllo se sono presenti attività più vecchie di 20 giorni non chiuse + //Se presenti non si possono aprire nuove ispezioni + return !completedInspection.Any(x => + x.Stato != StatusEnum.Completata && + x.Data < DateTime.Now.AddDays(-20) + ); + } + private async Task LoadDataAsync() { if (!await userSession.IsLoggedIn()) return; diff --git a/SteUp.Shared/Core/Helpers/ModalHelper.cs b/SteUp.Shared/Core/Helpers/ModalHelper.cs index 9dc0afe..b8565bf 100644 --- a/SteUp.Shared/Core/Helpers/ModalHelper.cs +++ b/SteUp.Shared/Core/Helpers/ModalHelper.cs @@ -6,129 +6,154 @@ using SteUp.Shared.Core.Entities; namespace SteUp.Shared.Core.Helpers; -public abstract class ModalHelper +public static class ModalHelper { - public static async Task OpenSelectShop(IDialogService dialog) + extension(IDialogService dialog) { - var modal = await dialog.ShowAsync( - "ModalSelectShop", - new DialogParameters(), - new DialogOptions - { - FullScreen = false, - CloseButton = false, - NoHeader = true, - BackdropClick = true - } - ); + public async Task OpenSelectShop() + { + var modal = await dialog.ShowAsync( + "ModalSelectShop", + new DialogParameters(), + new DialogOptions + { + FullScreen = false, + CloseButton = false, + NoHeader = true, + BackdropClick = true + } + ); - return await modal.Result; - } + return await modal.Result; + } - public static async Task OpenFormScheda(IDialogService dialog, string codMdep, DateTime data, - bool isNew = false, Scheda? scheda = null) - { - scheda = isNew && scheda == null ? new Scheda() : scheda; + public async Task OpenFormScheda(string codMdep, DateTime data, + bool isNew = false, Scheda? scheda = null) + { + scheda = isNew && scheda == null ? new Scheda() : scheda; - var modal = await dialog.ShowAsync( - "ModalFormScheda", - new DialogParameters - { - { x => x.CodMdep, codMdep }, - { x => x.Data, data }, - { x => x.IsNew, isNew }, - { x => x.Scheda, scheda } - }, - new DialogOptions - { - FullScreen = true, - CloseButton = false, - NoHeader = true - } - ); + var modal = await dialog.ShowAsync( + "ModalFormScheda", + new DialogParameters + { + { x => x.CodMdep, codMdep }, + { x => x.Data, data }, + { x => x.IsNew, isNew }, + { x => x.Scheda, scheda } + }, + new DialogOptions + { + FullScreen = true, + CloseButton = false, + NoHeader = true + } + ); - return await modal.Result; - } + return await modal.Result; + } - public static async Task OpenAddAttached(IDialogService dialog) - { - var modal = await dialog.ShowAsync( - "Add attached", - new DialogParameters(), - new DialogOptions - { - FullScreen = false, - CloseButton = false, - NoHeader = true, - BackdropClick = false - } - ); + public async Task OpenAddAttached() + { + var modal = await dialog.ShowAsync( + "Add attached", + new DialogParameters(), + new DialogOptions + { + FullScreen = false, + CloseButton = false, + NoHeader = true, + BackdropClick = false + } + ); - return await modal.Result; - } + return await modal.Result; + } - public static async Task OpenSuggestActivityDescription(IDialogService dialog, - List? activityTypers) - { - var modal = await dialog.ShowAsync( - "Suggest activity description", - new DialogParameters - { - { x => x.ActivityTypers, activityTypers } - }, - new DialogOptions - { - FullScreen = false, - CloseButton = false, - NoHeader = true, - BackdropClick = true - } - ); + public async Task OpenSuggestActivityDescription(List? activityTypers) + { + var modal = await dialog.ShowAsync( + "Suggest activity description", + new DialogParameters + { + { x => x.ActivityTypers, activityTypers } + }, + new DialogOptions + { + FullScreen = false, + CloseButton = false, + NoHeader = true, + BackdropClick = true + } + ); - return await modal.Result; - } + return await modal.Result; + } - public static async Task OpenSelectArt(IDialogService dialog, List? articoli) - { - var modal = await dialog.ShowAsync( - "ModalSelectArt", - new DialogParameters - { - { x => x.Articoli, articoli } - }, - new DialogOptions - { - FullScreen = false, - CloseButton = false, - NoHeader = true, - BackdropClick = true, - FullWidth = true, - MaxWidth = MaxWidth.ExtraLarge - } - ); + public async Task OpenSelectArt(List? articoli) + { + var modal = await dialog.ShowAsync( + "ModalSelectArt", + new DialogParameters + { + { x => x.Articoli, articoli } + }, + new DialogOptions + { + FullScreen = false, + CloseButton = false, + NoHeader = true, + BackdropClick = true, + FullWidth = true, + MaxWidth = MaxWidth.ExtraLarge + } + ); - return await modal.Result; - } + return await modal.Result; + } - public static async Task ShowError(IDialogService dialog, string message) - { - var modal = await dialog.ShowAsync( - "ModalError", - new DialogParameters - { - { x => x.ErrorMessage, message } - }, - new DialogOptions - { - FullScreen = false, - CloseButton = false, - NoHeader = true, - BackdropClick = true, - FullWidth = true, - MaxWidth = MaxWidth.ExtraLarge - } - ); + public async Task ShowError(string message) + { + var modal = await dialog.ShowAsync( + "ModalError", + new DialogParameters + { + { x => x.ErrorMessage, message } + }, + new DialogOptions + { + FullScreen = false, + CloseButton = false, + NoHeader = true, + BackdropClick = true, + FullWidth = true, + MaxWidth = MaxWidth.ExtraLarge + } + ); - await modal.Result; + await modal.Result; + } + + public async Task ShowWarning(string message) + { + var modal = await dialog.ShowAsync( + "ModalError", + new DialogParameters + { + { x => x.ErrorMessage, message }, + { x => x.IsWarning, true } + }, + new DialogOptions + { + FullScreen = false, + CloseButton = false, + NoHeader = true, + BackdropClick = true, + FullWidth = true, + MaxWidth = MaxWidth.ExtraLarge + } + ); + + await modal.Result; + } } } \ No newline at end of file diff --git a/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs b/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs index f4fe3be..1fcfbbc 100644 --- a/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs +++ b/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs @@ -17,4 +17,6 @@ public interface IIntegrySteupService Task SaveMultipleSchede(List request); Task CompleteInspection(string activityId); Task UploadFile(string activityId, byte[] file, string fileName); + + Task DeleteScheda(string activityId); } \ No newline at end of file diff --git a/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs b/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs index 9fa10d8..21fb9a1 100644 --- a/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs +++ b/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs @@ -1,4 +1,5 @@ -using SteUp.Shared.Core.Entities; +using System.Linq.Expressions; +using SteUp.Shared.Core.Entities; using SteUp.Shared.Core.Enum; namespace SteUp.Shared.Core.Interface.LocalDb; @@ -7,6 +8,7 @@ public interface IIspezioniService { // ISPEZIONI Task GetIspezioneAsync(string codMdep, DateTime data, string rilevatore); + Task> GetAllIspezioni(); Task> GetAllIspezioniWithSchedeAsync(); Task AddIspezioneAsync(Ispezione ispezione); Task GetOrCreateIspezioneAsync(string codMdep, DateTime data, string rilevatore); diff --git a/SteUp.Shared/Core/Services/IntegrySteupService.cs b/SteUp.Shared/Core/Services/IntegrySteupService.cs index 579f02f..613b05d 100644 --- a/SteUp.Shared/Core/Services/IntegrySteupService.cs +++ b/SteUp.Shared/Core/Services/IntegrySteupService.cs @@ -67,4 +67,13 @@ public class IntegrySteupService(IIntegryApiRestClient integryApiRestClient) : I return integryApiRestClient.Post($"{BaseRequest}/uploadAttachment", content, queryParams!); } + + public Task DeleteScheda(string activityId) => + integryApiRestClient.AuthorizedGet( + $"{BaseRequest}/deleteScheda", + new Dictionary + { + { "activityId", activityId } + } + ); } \ No newline at end of file