Gestite schede nella pagina ispezione e migliorie grafiche

This commit is contained in:
2026-02-23 10:12:36 +01:00
parent b39b7ba751
commit efefd3499b
21 changed files with 253 additions and 37 deletions

View File

@@ -30,7 +30,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
public async Task<Ispezione> 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 &&
@@ -49,7 +49,19 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
db.Ispezioni.Add(created);
await db.SaveChangesAsync();
return created;
return await db.Ispezioni
.AsNoTracking()
.FirstAsync(x =>
x.CodMdep == codMdep &&
x.Data == data &&
x.Rilevatore == rilevatore);
}
public async Task<bool> UpdateIspezioneAsync(Ispezione ispezione)
{
db.Ispezioni.Update(ispezione);
await db.SaveChangesAsync();
return true;
}
/// <summary>
@@ -84,6 +96,14 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
await db.SaveChangesAsync();
}
public Task<List<Scheda>> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore) =>
db.Schede
.AsNoTracking()
.Where(x => x.CodMdep == codMdep &&
x.Data == data &&
x.Rilevatore == rilevatore)
.ToListAsync();
public Task<Scheda?> GetSchedaAsync(int schedaId) =>
db.Schede
.AsNoTracking()
@@ -106,6 +126,17 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
return true;
}
public async Task<bool> 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;
}
/// <summary>
/// Cancella tutte le schede di una ispezione senza cancellare l'ispezione.
/// </summary>

View File

@@ -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<AppAuthenticationStateProvider>());
}
public static void RegisterMessageServices(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<IMessenger, WeakReferenceMessenger>();
builder.Services.AddSingleton<NewSchedaService>();
}
public static void RegisterDbServices(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<IDbPathProvider, DbPathProvider>();
@@ -55,7 +63,7 @@ public static class CoreModule
var dbPath = sp.GetRequiredService<IDbPathProvider>().GetDbPath();
options.UseSqlite($"Filename={dbPath}");
});
builder.Services.AddSingleton<IDbInitializer, DbInitializer>();
builder.Services.AddSingleton<IIspezioniService, IspezioniService>();
builder.Services.AddScoped<IDbInitializer, DbInitializer>();
builder.Services.AddScoped<IIspezioniService, IspezioniService>();
}
}

View File

@@ -47,6 +47,7 @@ namespace SteUp.Maui
builder.RegisterIntegryServices();
builder.RegisterSystemService();
builder.RegisterDbServices();
builder.RegisterMessageServices();
return builder.Build();
}

View File

@@ -38,7 +38,7 @@
<MudText Typo="Typo.h6">
<b>@Title</b>
</MudText>
<MudIconButton Icon="@Icons.Material.Filled.Close" OnClick="@GoBack" />
<MudIconButton Icon="@Icons.Material.Rounded.Close" OnClick="@GoBack" />
</div>
}
</div>

View File

@@ -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
<div
class="container animated-navbar @(IsVisible ? "show-nav" : "hide-nav") @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
@@ -30,8 +33,9 @@
{
<MudMenu PopoverClass="custom_popover" AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomRight">
<ActivatorContent>
<MudFab Class="custom-plus-button" OnClick="OnOpenMenu" Color="Color.Surface" Size="Size.Medium" IconSize="Size.Medium"
IconColor="Color.Primary" StartIcon="@Icons.Material.Filled.Add"/>
<MudFab Class="custom-plus-button" OnClick="OnOpenMenu" Color="Color.Surface" Size="Size.Medium"
IconSize="Size.Medium"
IconColor="Color.Primary" StartIcon="@Icons.Material.Rounded.Add"/>
</ActivatorContent>
<ChildContent>
@if (SchedaVisible)
@@ -84,9 +88,13 @@
_ = 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()

View File

@@ -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
<HeaderLayout Title="Ispezione" BackTo="Indietro" Back="true"/>
<div class="container content pb-safe-area">
<InspectionCard Ispezione="SteupDataService.InspectionPageState.Ispezione"/>
@if (!SchedeGrouped.IsNullOrEmpty())
{
<MudExpansionPanels MultiExpansion="true">
@foreach (var group in SchedeGrouped)
{
<MudExpansionPanel Expanded="true" Text="@group.Key.Descrizione">
<TitleContent>
<div class="header-scheda-group">
<div class="title">
<MudText Typo="Typo.h6"><b>@group.Key.Descrizione</b></MudText>
<MudChip T="string" Size="Size.Small" Color="Color.Default">
@($"{group.Value.Count} sched{(group.Value.Count == 1 ? "a" : "e")}")
</MudChip>
</div>
<div class="action-scheda-group">
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Rounded.Add" Color="Color.Warning" Size="Size.Medium"/>
</div>
</div>
</TitleContent>
<ChildContent>
@foreach (var scheda in group.Value)
{
<SchedaCard Scheda="scheda"/>
}
</ChildContent>
</MudExpansionPanel>
}
</MudExpansionPanels>
}
</div>
@code {
private Dictionary<JtbFasiDto, List<Scheda>> 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;
}
}

View File

@@ -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)
{
<div class="container content pb-safe-area">
<div class="container-primary-info">
<div class="container-primary-info mud-elevation-1">
<div class="section-primary-info">
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold"
Color="Color.Secondary">
@@ -64,7 +63,7 @@
</div>
</div>
<div class="container-button">
<div class="container-button mud-elevation-1">
<MudButton Class="button-settings green-icon"
FullWidth="true"
StartIcon="@Icons.Material.Outlined.Sync"
@@ -75,7 +74,7 @@
</MudButton>
</div>
<div class="container-button">
<div class="container-button mud-elevation-1">
<MudButton Class="button-settings exit"
FullWidth="true"
Color="Color.Error"

View File

@@ -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 {

View File

@@ -1,7 +1,7 @@
@using SteUp.Shared.Core.Dto
@using SteUp.Shared.Core.Entities
<div class="container-primary-info @(OnClick.HasDelegate ? "ripple-container" : "")" @onclick="OnCardClick">
<div class="container-primary-info mud-elevation-1 @(OnClick.HasDelegate ? "ripple-container" : "")" @onclick="OnCardClick">
<div class="section-primary-info">
<div class="inspection-info">
@if (CompactView)

View File

@@ -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 {

View File

@@ -0,0 +1,30 @@
@using SteUp.Shared.Core.Entities
<div class="scheda-card">
<div class="scheda-body-section">
<div class="title-section">
<MudText Class="scheda-title" Typo="Typo.subtitle1">
<b>@Scheda.ActivityTypeId</b>
</MudText>
<div class="sub-info-section">
<MudChip T="string" Icon="@Icons.Material.Rounded.PhotoCamera" Size="Size.Small" Color="Color.Default">
0
</MudChip>
<MudChip T="string" Icon="@Icons.Material.Rounded.QrCode2" Size="Size.Small" Color="Color.Default">
0
</MudChip>
</div>
</div>
<div class="scheda-card-action">
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Rounded.Edit" Color="Color.Info" Size="Size.Small">Modifica</MudButton>
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Rounded.Delete" Color="Color.Error" Size="Size.Small">Cancella</MudButton>
</div>
</div>
</div>
@code{
[Parameter] public required Scheda Scheda { get; set; }
}

View File

@@ -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;
}

View File

@@ -19,7 +19,7 @@
</MudText>
</div>
<div class="sub-info-section">
<MudChip T="string" Icon="@Icons.Material.Filled.LocationCity" Size="Size.Small" Color="Color.Default">
<MudChip T="string" Icon="@Icons.Material.Rounded.LocationCity" Size="Size.Small" Color="Color.Default">
@PuntoVendita.Citta
</MudChip>
<MudChip T="string" Size="Size.Small" Color="Color.Default">

View File

@@ -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
<MudDialog Class="customDialog-form">
<DialogContent>
@@ -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()

View File

@@ -21,7 +21,7 @@ public class Scheda : EntityBase<Scheda>
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

View File

@@ -23,11 +23,15 @@ public abstract class ModalHelper
return await modal.Result;
}
public static async Task<DialogResult?> OpenFormScheda(IDialogService dialog)
public static async Task<DialogResult?> OpenFormScheda(IDialogService dialog, string codMdep, DateOnly data)
{
var modal = await dialog.ShowAsync<ModalFormScheda>(
"ModalFormScheda",
new DialogParameters(),
new DialogParameters<ModalFormScheda>
{
{ x => x.CodMdep, codMdep },
{ x => x.Data, data },
},
new DialogOptions
{
FullScreen = true,

View File

@@ -9,12 +9,15 @@ public interface IIspezioniService
Task<List<Ispezione>> GetAllIspezioniWithSchedeAsync();
Task AddIspezioneAsync(Ispezione ispezione);
Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
Task<bool> UpdateIspezioneAsync(Ispezione ispezione);
Task<bool> DeleteIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
// SCHEDE
Task AddSchedaAsync(string codMdep, DateOnly data, string rilevatore, Scheda scheda);
Task<List<Scheda>> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
Task<Scheda?> GetSchedaAsync(int schedaId);
Task<Scheda?> GetSchedaWithIspezioneAsync(int schedaId);
Task<bool> UpdateSchedaAsync(Scheda scheda);
Task<bool> DeleteSchedaAsync(int schedaId);
Task<int> DeleteAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
}

View File

@@ -0,0 +1,5 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
namespace SteUp.Shared.Core.Messages.Scheda;
public class NewSchedaMessage(object? value = null) : ValueChangedMessage<object?>(value);

View File

@@ -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<NewSchedaMessage>(this, (_, _) => { OnNewScheda?.Invoke(); });
}
}

View File

@@ -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%;
}

View File

@@ -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;
}