Files
SteUP_Dotnet/SteUp.Maui/Core/CoreModule.cs
T
MarcoE d076a4b77a Salvataggio come bozza: il lavoro in corso non si perde piu'
Uscendo da una scheda a meta' (tasto indietro del dispositivo o "Annulla")
il lavoro veniva scartato. Il tasto indietro non era nemmeno gestito: non
arriva alla WebView e non c'e' stack di navigazione, quindi mandava l'app
in background con i dati solo in memoria.

Nuovo stato Bozza ("Da completare"): salvata in locale, mai inviabile
finche' non viene conclusa.

- Scheda.Bozza + migration additiva (default false: le schede esistenti
  non cambiano stato).
- SchedaSyncHelper: terzo SyncState, CountBozze(). CountDaInviare()
  esclude le bozze, quindi il badge "da inviare" resta corretto.
- ModalFormScheda: SaveDraft() salva solo in locale senza validazione;
  Save() azzera il flag; Submit() avvisa quando il form e' invalido
  (prima il tocco su "Salva" sembrava non fare nulla se i campi mancanti
  erano fuori schermo); Update() prende preserveActivityId cosi' una
  bozza di scheda gia' inviata mantiene il link al server e al
  completamento lo aggiorna invece di duplicarlo.
- ConfirmUpdateActivity: il pulsante bozza sta su NoText, non CancelText
  (CancelText ritorna null, NoText ritorna false).
- BackButtonService + MainActivity.OnBackPressed: il tasto indietro passa
  dallo stesso percorso di "Annulla". Ignorato mentre e' aperto un dialog
  figlio, per non mostrare il prompt sotto un altro dialog.
- IspezionePage: "Concludi ispezione" si blocca se ci sono bozze,
  "Esporta reparto" le salta, chip "N da completare" per reparto.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 13:24:35 +02:00

96 lines
3.7 KiB
C#

using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SteUp.Data.LocalDb;
using SteUp.Data.LocalDb.EntityServices;
using SteUp.Maui.Core.Logger;
using SteUp.Maui.Core.Services;
using SteUp.Maui.Core.System;
using SteUp.Maui.Core.System.Network;
using SteUp.Shared.Core.BarcodeReader;
using SteUp.Shared.Core.BarcodeReader.Contracts;
using SteUp.Shared.Core.Data;
using SteUp.Shared.Core.Data.Contracts;
using SteUp.Shared.Core.Interface;
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.Ispezione;
using SteUp.Shared.Core.Messages.Scanner;
using SteUp.Shared.Core.Messages.Scheda;
using SteUp.Shared.Core.Messages.System;
using SteUp.Shared.Core.Services;
namespace SteUp.Maui.Core;
public static class CoreModule
{
extension(MauiAppBuilder builder)
{
public void RegisterAppServices()
{
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddSingleton<IGenericSystemService, GenericSystemService>();
builder.Services.AddScoped<ISteupDataService, SteupDataService>();
builder.Services.AddSingleton<IBarcodeManager, BarcodeManager>();
}
public void RegisterIntegryServices()
{
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
builder.Services.AddScoped<IIntegrySteupService, IntegrySteupService>();
}
public void RegisterSystemService()
{
builder.Services.AddSingleton<INetworkService, NetworkService>();
builder.Services.AddSingleton<IAttachedService, AttachedService>();
builder.Services.AddSingleton<IFileManager, FileManager>();
builder.Services.AddSingleton<IBarcodeReaderService, HoneywellScannerService>();
}
public void AddAuthorizationCore()
{
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AppAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
provider.GetRequiredService<AppAuthenticationStateProvider>());
}
public void RegisterMessageServices()
{
builder.Services.AddSingleton<IMessenger, WeakReferenceMessenger>();
builder.Services.AddSingleton<NewSchedaService>();
builder.Services.AddSingleton<OnScannerService>();
builder.Services.AddSingleton<CompleteInspectionService>();
builder.Services.AddSingleton<BackButtonService>();
}
public void RegisterDbServices()
{
builder.Services.AddSingleton<IDbPathProvider, DbPathProvider>();
builder.Services.AddDbContext<AppDbContext>((sp, options) =>
{
var dbPath = sp.GetRequiredService<IDbPathProvider>().GetDbPath();
options.UseSqlite($"Filename={dbPath}");
});
builder.Services.AddSingleton<IDbInitializer, DbInitializer>();
builder.Services.AddSingleton<IIspezioniService, IspezioniService>();
}
public void RegisterLoggerServices()
{
var logPath = Path.Combine(FileSystem.AppDataDirectory, "logs");
const string logFilePrefix = "SteUp-log";
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddProvider(new FileLoggerProvider(logPath, logFilePrefix));
loggingBuilder.SetMinimumLevel(LogLevel.Information);
});
}
}
}