diff --git a/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs b/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs index a2962bb..44548e0 100644 --- a/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs +++ b/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs @@ -8,11 +8,11 @@ public class IspezioniService(AppDbContext db) : IIspezioniService { public Task GetIspezioneAsync(string codMdep, DateOnly data, string rilevatore) => db.Ispezioni - .Include(x => x.Schede) - .FirstOrDefaultAsync(x => - x.CodMdep == codMdep && - x.Data == data && - x.Rilevatore == rilevatore); + .Include(x => x.Schede) + .FirstOrDefaultAsync(x => + x.CodMdep == codMdep && + x.Data == data && + x.Rilevatore == rilevatore); public Task> GetAllIspezioniWithSchedeAsync() => db.Ispezioni @@ -30,7 +30,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService public async Task GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore) { var existing = await db.Ispezioni - .Include(x => x.Schede) + .AsNoTracking() .FirstOrDefaultAsync(x => x.CodMdep == codMdep && x.Data == data && @@ -48,8 +48,20 @@ public class IspezioniService(AppDbContext db) : IIspezioniService db.Ispezioni.Add(created); await db.SaveChangesAsync(); + + return await db.Ispezioni + .AsNoTracking() + .FirstAsync(x => + x.CodMdep == codMdep && + x.Data == data && + x.Rilevatore == rilevatore); + } - return created; + public async Task UpdateIspezioneAsync(Ispezione ispezione) + { + db.Ispezioni.Update(ispezione); + await db.SaveChangesAsync(); + return true; } /// @@ -84,16 +96,24 @@ public class IspezioniService(AppDbContext db) : IIspezioniService await db.SaveChangesAsync(); } + public Task> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore) => + db.Schede + .AsNoTracking() + .Where(x => x.CodMdep == codMdep && + x.Data == data && + x.Rilevatore == rilevatore) + .ToListAsync(); + public Task GetSchedaAsync(int schedaId) => db.Schede - .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == schedaId); + .AsNoTracking() + .FirstOrDefaultAsync(x => x.Id == schedaId); public Task GetSchedaWithIspezioneAsync(int schedaId) => db.Schede - .Include(x => x.Ispezione) - .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == schedaId); + .Include(x => x.Ispezione) + .AsNoTracking() + .FirstOrDefaultAsync(x => x.Id == schedaId); public async Task DeleteSchedaAsync(int schedaId) { @@ -106,6 +126,17 @@ public class IspezioniService(AppDbContext db) : IIspezioniService return true; } + public async Task UpdateSchedaAsync(Scheda scheda) + { + var exists = await db.Schede.AnyAsync(x => x.Id == scheda.Id); + if (!exists) + return false; + + db.Schede.Update(scheda); + await db.SaveChangesAsync(); + return true; + } + /// /// Cancella tutte le schede di una ispezione senza cancellare l'ispezione. /// diff --git a/SteUp.Maui/Core/CoreModule.cs b/SteUp.Maui/Core/CoreModule.cs index f19d680..02b3381 100644 --- a/SteUp.Maui/Core/CoreModule.cs +++ b/SteUp.Maui/Core/CoreModule.cs @@ -1,4 +1,5 @@ using System.Data; +using CommunityToolkit.Mvvm.Messaging; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.EntityFrameworkCore; using SteUp.Data.LocalDb; @@ -13,6 +14,7 @@ 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; +using SteUp.Shared.Core.Messages.Scheda; using SteUp.Shared.Core.Services; namespace SteUp.Maui.Core; @@ -47,6 +49,12 @@ public static class CoreModule provider.GetRequiredService()); } + public static void RegisterMessageServices(this MauiAppBuilder builder) + { + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + } + public static void RegisterDbServices(this MauiAppBuilder builder) { builder.Services.AddSingleton(); @@ -55,7 +63,7 @@ public static class CoreModule var dbPath = sp.GetRequiredService().GetDbPath(); options.UseSqlite($"Filename={dbPath}"); }); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); } } \ No newline at end of file diff --git a/SteUp.Maui/MauiProgram.cs b/SteUp.Maui/MauiProgram.cs index f127796..c0eec22 100644 --- a/SteUp.Maui/MauiProgram.cs +++ b/SteUp.Maui/MauiProgram.cs @@ -47,6 +47,7 @@ namespace SteUp.Maui builder.RegisterIntegryServices(); builder.RegisterSystemService(); builder.RegisterDbServices(); + builder.RegisterMessageServices(); return builder.Build(); } diff --git a/SteUp.Shared/Components/Layout/HeaderLayout.razor b/SteUp.Shared/Components/Layout/HeaderLayout.razor index a39115b..aa69175 100644 --- a/SteUp.Shared/Components/Layout/HeaderLayout.razor +++ b/SteUp.Shared/Components/Layout/HeaderLayout.razor @@ -38,7 +38,7 @@ @Title - + } diff --git a/SteUp.Shared/Components/Layout/NavMenu.razor b/SteUp.Shared/Components/Layout/NavMenu.razor index 27afc7c..23c55d2 100644 --- a/SteUp.Shared/Components/Layout/NavMenu.razor +++ b/SteUp.Shared/Components/Layout/NavMenu.razor @@ -1,6 +1,9 @@ +@using CommunityToolkit.Mvvm.Messaging @using SteUp.Shared.Core.Interface.System.Network +@using SteUp.Shared.Core.Messages.Scheda @inject INetworkService NetworkService @inject IDialogService Dialog +@inject IMessenger Messenger
@@ -30,8 +33,9 @@ { - + @if (SchedaVisible) @@ -84,15 +88,19 @@ _ = ModalHelper.OpenSelectShop(Dialog); } - private void NewScheda() + private async Task NewScheda() { - _ = ModalHelper.OpenFormScheda(Dialog); + var ispezione = SteupDataService.InspectionPageState.Ispezione; + var modal = await ModalHelper.OpenFormScheda(Dialog, ispezione.CodMdep, ispezione.Data); + + 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); StateHasChanged(); } diff --git a/SteUp.Shared/Components/Pages/IspezionePage.razor b/SteUp.Shared/Components/Pages/IspezionePage.razor index 6f1db60..7340885 100644 --- a/SteUp.Shared/Components/Pages/IspezionePage.razor +++ b/SteUp.Shared/Components/Pages/IspezionePage.razor @@ -1,17 +1,85 @@ @page "/ispezione" @using SteUp.Shared.Components.Layout @using SteUp.Shared.Components.SingleElements.Card +@using SteUp.Shared.Core.Dto +@using SteUp.Shared.Core.Entities +@using SteUp.Shared.Core.Interface.LocalDb +@using SteUp.Shared.Core.Messages.Scheda +@inject NewSchedaService NewScheda +@inject IIspezioniService IspezioniService +@implements IDisposable
+ + @if (!SchedeGrouped.IsNullOrEmpty()) + { + + @foreach (var group in SchedeGrouped) + { + + +
+
+ @group.Key.Descrizione + + @($"{group.Value.Count} sched{(group.Value.Count == 1 ? "a" : "e")}") + +
+
+ +
+
+
+ + @foreach (var scheda in group.Value) + { + + } + +
+ } +
+ }
@code { + private Dictionary> SchedeGrouped { get; set; } = []; - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { + NewScheda.OnNewScheda += LoadSchede; + + LoadSchede(); + } + + private void LoadSchede() + { + var ispezione = SteupDataService.InspectionPageState.Ispezione; + + InvokeAsync(async () => + { + var schede = await IspezioniService.GetAllSchedeOfIspezioneAsync( + ispezione.CodMdep, ispezione.Data, ispezione.Rilevatore + ); + + SchedeGrouped = schede + .Where(s => s.Reparto != null) + .GroupBy(s => s.CodJfas) + .ToDictionary( + g => g.First().Reparto!, + g => g.ToList() + ); + + StateHasChanged(); + }); + } + + void IDisposable.Dispose() + { + NewScheda.OnNewScheda -= LoadSchede; } } \ No newline at end of file diff --git a/SteUp.Shared/Components/Pages/UserPage.razor b/SteUp.Shared/Components/Pages/UserPage.razor index b0598b5..774c67c 100644 --- a/SteUp.Shared/Components/Pages/UserPage.razor +++ b/SteUp.Shared/Components/Pages/UserPage.razor @@ -3,7 +3,6 @@ @using SteUp.Shared.Components.Layout @using SteUp.Shared.Components.SingleElements @using SteUp.Shared.Core.Authorization.Enum -@using SteUp.Shared.Core.Helpers @using SteUp.Shared.Core.Interface.System.Network @using SteUp.Shared.Core.Services @using SteUp.Shared.Core.Utility @@ -15,7 +14,7 @@ @if (IsLoggedIn) {
-
+
@@ -64,7 +63,7 @@
-
+
-
+
+
@if (CompactView) diff --git a/SteUp.Shared/Components/SingleElements/Card/InspectionCard.razor.css b/SteUp.Shared/Components/SingleElements/Card/InspectionCard.razor.css index 30b6ad6..bead280 100644 --- a/SteUp.Shared/Components/SingleElements/Card/InspectionCard.razor.css +++ b/SteUp.Shared/Components/SingleElements/Card/InspectionCard.razor.css @@ -1,8 +1,8 @@ .container-primary-info { - background: var(--light-card-background); + /*background: var(--light-card-background);*/ width: 100%; margin-bottom: 2rem; - border-radius: 12px; + border-radius: 20px; } .container-primary-info .divider { diff --git a/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor new file mode 100644 index 0000000..ff7de1f --- /dev/null +++ b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor @@ -0,0 +1,30 @@ +@using SteUp.Shared.Core.Entities + +
+
+
+ + @Scheda.ActivityTypeId + + +
+ + 0 + + + 0 + +
+
+ +
+ Modifica + Cancella +
+
+
+ +@code{ + [Parameter] public required Scheda Scheda { get; set; } + +} \ No newline at end of file diff --git a/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor.css b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor.css new file mode 100644 index 0000000..c313d26 --- /dev/null +++ b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor.css @@ -0,0 +1,23 @@ +.scheda-card{ + padding: .75rem 1.25rem; + background-color: var(--light-card-background); + border-radius: 1em; +} + +.scheda-body-section{ + display: flex; + flex-direction: column; + gap: 1rem; +} + +.title-section{ + display: flex; + align-items: center; + justify-content: space-between; +} + +.scheda-card-action{ + display: flex; + gap: 1rem; + justify-content: center; +} \ No newline at end of file diff --git a/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor b/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor index d7ce958..a956c8a 100644 --- a/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor +++ b/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor @@ -19,7 +19,7 @@
- + @PuntoVendita.Citta diff --git a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor index 5c84ab3..0f7c795 100644 --- a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor +++ b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor @@ -6,12 +6,14 @@ @using SteUp.Shared.Core.Dto @using SteUp.Shared.Core.Entities @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 @inject INetworkService NetworkService @inject IDialogService Dialog @inject IIntegryApiService IntegryApiService @inject IAttachedService AttachedService +@inject IIspezioniService IspezioniService @@ -128,6 +130,8 @@ @code { [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!; + [Parameter] public required string CodMdep { get; set; } + [Parameter] public required DateOnly Data { get; set; } private Scheda Scheda { get; set; } = new(); @@ -155,6 +159,16 @@ private async Task Save() { + VisibleOverlay = true; + StateHasChanged(); + + await IspezioniService.AddSchedaAsync(CodMdep, Data, UserSession.User.Username, Scheda); + + SuccessAnimation = true; + StateHasChanged(); + + await Task.Delay(1250); + MudDialog.Close(Scheda); } private async Task Cancel() diff --git a/SteUp.Shared/Core/Entities/Scheda.cs b/SteUp.Shared/Core/Entities/Scheda.cs index 48e929a..5f2bdd0 100644 --- a/SteUp.Shared/Core/Entities/Scheda.cs +++ b/SteUp.Shared/Core/Entities/Scheda.cs @@ -21,7 +21,7 @@ public class Scheda : EntityBase public string? ActivityTypeId { get; set; } public string? Note { get; set; } public string? Responsabile { get; set; } - public int Scadenza { get; set; } = 24; + public int Scadenza { get; set; } = 1460; [NotMapped] public JtbFasiDto? Reparto diff --git a/SteUp.Shared/Core/Helpers/ModalHelper.cs b/SteUp.Shared/Core/Helpers/ModalHelper.cs index 6fb1e72..4b95245 100644 --- a/SteUp.Shared/Core/Helpers/ModalHelper.cs +++ b/SteUp.Shared/Core/Helpers/ModalHelper.cs @@ -23,11 +23,15 @@ public abstract class ModalHelper return await modal.Result; } - public static async Task OpenFormScheda(IDialogService dialog) + public static async Task OpenFormScheda(IDialogService dialog, string codMdep, DateOnly data) { var modal = await dialog.ShowAsync( "ModalFormScheda", - new DialogParameters(), + new DialogParameters + { + { x => x.CodMdep, codMdep }, + { x => x.Data, data }, + }, new DialogOptions { FullScreen = true, diff --git a/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs b/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs index 3e75339..acfab30 100644 --- a/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs +++ b/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs @@ -9,12 +9,15 @@ public interface IIspezioniService Task> GetAllIspezioniWithSchedeAsync(); Task AddIspezioneAsync(Ispezione ispezione); Task GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore); + Task UpdateIspezioneAsync(Ispezione ispezione); Task DeleteIspezioneAsync(string codMdep, DateOnly data, string rilevatore); // SCHEDE Task AddSchedaAsync(string codMdep, DateOnly data, string rilevatore, Scheda scheda); + Task> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore); Task GetSchedaAsync(int schedaId); Task GetSchedaWithIspezioneAsync(int schedaId); + Task UpdateSchedaAsync(Scheda scheda); Task DeleteSchedaAsync(int schedaId); Task DeleteAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore); } \ No newline at end of file diff --git a/SteUp.Shared/Core/Messages/Scheda/NewSchedaMessage.cs b/SteUp.Shared/Core/Messages/Scheda/NewSchedaMessage.cs new file mode 100644 index 0000000..da592d4 --- /dev/null +++ b/SteUp.Shared/Core/Messages/Scheda/NewSchedaMessage.cs @@ -0,0 +1,5 @@ +using CommunityToolkit.Mvvm.Messaging.Messages; + +namespace SteUp.Shared.Core.Messages.Scheda; + +public class NewSchedaMessage(object? value = null) : ValueChangedMessage(value); \ No newline at end of file diff --git a/SteUp.Shared/Core/Messages/Scheda/NewSchedaService.cs b/SteUp.Shared/Core/Messages/Scheda/NewSchedaService.cs new file mode 100644 index 0000000..e9c9773 --- /dev/null +++ b/SteUp.Shared/Core/Messages/Scheda/NewSchedaService.cs @@ -0,0 +1,13 @@ +using CommunityToolkit.Mvvm.Messaging; + +namespace SteUp.Shared.Core.Messages.Scheda; + +public class NewSchedaService +{ + public event Action? OnNewScheda; + + public NewSchedaService(IMessenger messenger) + { + messenger.Register(this, (_, _) => { OnNewScheda?.Invoke(); }); + } +} \ No newline at end of file diff --git a/SteUp.Shared/wwwroot/css/custom-mudBlazor.css b/SteUp.Shared/wwwroot/css/custom-mudBlazor.css index 0c64115..8bd460a 100644 --- a/SteUp.Shared/wwwroot/css/custom-mudBlazor.css +++ b/SteUp.Shared/wwwroot/css/custom-mudBlazor.css @@ -24,6 +24,15 @@ border-radius: 1em !important; } -.mud-skeleton{ +.mud-skeleton { border-radius: .5em !important; +} + +/*.mud-expand-panel{*/ +/* background: var(--light-card-background) !important;*/ +/* box-shadow: unset !important;*/ +/*}*/ + +.mud-expansion-panels { + width: 100%; } \ No newline at end of file diff --git a/SteUp.Shared/wwwroot/css/form.css b/SteUp.Shared/wwwroot/css/form.css index 08e35ae..4790712 100644 --- a/SteUp.Shared/wwwroot/css/form.css +++ b/SteUp.Shared/wwwroot/css/form.css @@ -138,9 +138,9 @@ .container-button { width: 100%; - background: var(--mud-palette-table-striped); + /*background: var(--mud-palette-table-striped);*/ padding: .5rem 0; - border-radius: 12px; + border-radius: 20px; margin-bottom: 2rem; }